Commit d684d27c authored by Håvard Farestveit's avatar Håvard Farestveit
Browse files

Merge branch 'havfar/fix/users-test-script' into havfar/fix/users

parents 2bcdf356 9bd3c8db
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
from users.tests.offers import *
from users.tests.user_registration import UserRegistration2WayTestCase
from users.tests.user_serializer import UserSerializerTestCase
from django.test import TestCase
from django.contrib.auth import get_user_model
from rest_framework.test import APIClient
from users.models import Offer
class OfferTestCase(TestCase):
def setUp(self):
self.client = APIClient()
self.user_model = get_user_model()
self.password = "password"
self.user1 = self.user_model(
username="testOffer1",
email="test@test.com",
phone_number="12345678",
country="Norway",
city="Oslo",
street_address="address 10"
)
self.user1.set_password(self.password)
self.user1.save()
self.user2 = self.user_model(
username="testOffer2",
email="test@test.com",
phone_number="12345678",
country="Norway",
city="Oslo",
street_address="address 10"
)
self.user2.set_password(self.password)
self.user2.save()
def _send_offer(self, user_id, status):
request = {}
request["status"] = status
request["recipient"] = "http://127.0.0.1:8000/api/users/{0}/".format(user_id)
response = self.client.post('/api/offers/', request)
return response.status_code
def _login(self, user):
request = {}
request["username"] = user.username
request["password"] = self.password
response = self.client.post('/api/token/', request)
access_token = response.data['access']
self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token)
def test_create_offer(self):
recipient = self.user2.id
self._login(self.user1)
status_code = self._send_offer(recipient, Offer.PENDING)
self.assertEqual(status_code, 201)
def test_get_offers(self):
self._login(self.user1)
self._send_offer(self.user2.id, Offer.PENDING)
self._login(self.user2)
response = self.client.get('/api/offers/')
number_of_offers = response.data["count"]
self.assertEqual(1, number_of_offers)
def test_get_offer_detail(self):
self._login(self.user1)
self._send_offer(self.user2.id, Offer.PENDING)
self._login(self.user2)
response = self.client.get('/api/offers/1/')
self.assertEqual(200, response.status_code)
def test_decline_offer(self):
self._login(self.user1)
self._send_offer(self.user2.id, Offer.PENDING)
self._login(self.user2)
response = self.client.patch('/api/offers/1/', {"status": Offer.DECLINED})
self.assertEqual(200, response.status_code)
def test_accept_offer(self):
self._login(self.user1)
self._send_offer(self.user2.id, Offer.PENDING)
self._login(self.user2)
offer_response = self.client.patch('/api/offers/1/', {"status": Offer.ACCEPTED})
self.assertEqual(200, offer_response.status_code)
coach_response = self.client.patch(
'/api/users/{0}/'.format(self.user2.id),
{"coach": "http://127.0.0.1:8000/api/users/{0}/".format(self.user1.id)}
)
self.assertEqual(200, coach_response.status_code)
athlete = self.user_model.objects.get(username=self.user2.username)
self.assertEqual(athlete.coach.id, self.user1.id)
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"airbnb-base",
"@cordova/eslint-config/node",
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 12
},
"overrides": [
{
"files": [
"spec/**/*.js"
],
"extends": [
"@cordova/eslint-config/node-tests"
]
},
{
"files": [
"cordova-js-src/**/*.js"
],
"extends": [
"@cordova/eslint-config/browser"
]
}
],
"rules": {
// enable additional rules
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
// override configuration set by extending "eslint:recommended"
"no-empty": "warn",
"no-cond-assign": [
"error",
"always"
],
// disable rules from base configurations
"for-direction": "off"
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -14,5 +14,11 @@
},
"scripts": {
"cypress:open": "cypress open"
},
"devDependencies": {
"@cordova/eslint-config": "^3.0.0",
"eslint": "^7.23.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1"
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment