Skip to content

Commit

Permalink
upd testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chacoon3 committed Nov 8, 2023
1 parent a6768e3 commit 1ef47d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
1 change: 1 addition & 0 deletions bmgt435_elp/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def middleware(request: HttpRequest):
2. user utility api's are allowed if there is a user id cookie
3. manage api's are allowed if there is a user id cookie, and if the user is an admin (validated by a database query)
"""

# no authentication required
if request.path.startswith("/bmgt435-service/api/auth/") or request.path.startswith("/bmgt435-service/admin") or request.path.startswith("/bmgt435-service/static"):
return get_response(request)
Expand Down
39 changes: 12 additions & 27 deletions bmgt435_elp/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import json


def _clientSetCookies(client:Client, cookies:dict):
for k, v in cookies.items():
client.cookies[k] = v


def _clientSignUp(client:Client, did:str, password:str):
return client.post(
'bmgt435-service/api/auth/sign-up',
Expand Down Expand Up @@ -86,14 +81,9 @@ def testRepeatedSignUp(self):

def testSignInPositive(self):
c = Client()
_clientSignUp(c, 'did', 'pa3232.ssword')

resp = c.post(
'bmgt435-service/api/auth/sign-in',
json.dumps({'did': 'did', 'password': 'pa3232.ssword'}),
'application/json'
)

pwd = 'pa3232.ssword'
_clientSignUp(c, 'did', pwd)
resp = _clientSignIn(c, 'did', pwd)
self.assertEqual(resp.status_code, 200)


Expand All @@ -120,13 +110,6 @@ def setUp(self):
BMGTUser(first_name='f', last_name='l', did='did323', role='admin', activated=0, password='Grave11.').save()
BMGTUser(first_name='first321', last_name='last232', did='did232', role='user', activated=1, password='Grave11.').save()


def testUserMePositive(self):
resp = Client().get(
'bmgt435-service/api/user/me',
)
self.assertNotEqual(resp.status_code, 200)


def testUserMeAfterSignIn(self):
c = Client()
Expand All @@ -147,27 +130,29 @@ def testUserMeNegative(self):


def testUserMeNotActivated(self):
resp = Client().get(
c = Client()
c.cookies['id'] = 2
resp = c.get(
'bmgt435-service/api/users/me',
)
self.assertNotEqual(resp.status_code, 200)


class GroupApiTest(TestCase):


def setUp(self) -> None:
BMGTUser(first_name='f', last_name='l', did='did', role='admin', activated=1, password='Grave11.').save()
BMGTUser(first_name='f', last_name='l', did='did323', role='admin', activated=0, password='Grave11.').save()
BMGTUser(first_name='first321', last_name='last232', did='did232', role='user', activated=1, password='Grave11.').save()
BMGTSemester(year=2022, season='fall').save()
BMGTGroup(number = 1, semester = BMGTSemester.objects.get(year=2022, season='fall')).save()
BMGTUser.objects.create(first_name='f', last_name='l', did='did', role='admin', activated=1, password='Grave11.')
BMGTUser.objects.create(first_name='f', last_name='l', did='did323', role='admin', activated=0, password='Grave11.')
BMGTUser.objects.create(first_name='first321', last_name='last232', did='did232', role='user', activated=1, password='Grave11.')
BMGTSemester.objects.create(year=2022, season='fall')
BMGTGroup.objects.create(number = 1, semester = BMGTSemester.objects.get(year=2022, season='fall'))


def testGetGroupPositive(self):
c = Client()
_clientSignUp(c, 'did', 'Grave11.')
_clientSignIn(c, 'did', 'Grave11.')
_clientSetCookies(c, {'id': 1})
resp = c.get(
'bmgt435-service/api/groups?id=1',
)
Expand Down

0 comments on commit 1ef47d4

Please sign in to comment.