Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-richards committed Oct 25, 2024
1 parent f1f6f69 commit dd110a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
44 changes: 23 additions & 21 deletions ietf/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,28 +945,30 @@ def test_api_version(self):


def test_api_appauth(self):
url = urlreverse('ietf.api.views.app_auth')
person = PersonFactory()
apikey = PersonalApiKeyFactory(endpoint=url, person=person)

self.client.login(username=person.user.username,password=f'{person.user.username}+password')
self.client.logout()

# error cases
# missing apikey
r = self.client.post(url, {})
self.assertContains(r, 'Missing apikey parameter', status_code=400)

# invalid apikey
r = self.client.post(url, {'apikey': 'foobar'})
self.assertContains(r, 'Invalid apikey', status_code=403)

# working case
r = self.client.post(url, {'apikey': apikey.hash()})
self.assertEqual(r.status_code, 200)
jsondata = r.json()
self.assertEqual(jsondata['success'], True)
for app in ["authortools", "bibxml"]:
url = urlreverse('ietf.api.views.app_auth', kwargs={"app": app})
person = PersonFactory()
apikey = PersonalApiKeyFactory(endpoint=url, person=person)

self.client.login(username=person.user.username,password=f'{person.user.username}+password')
self.client.logout()

# error cases
# missing apikey
r = self.client.post(url, {})
self.assertContains(r, 'Missing apikey parameter', status_code=400)

# invalid apikey
r = self.client.post(url, {'apikey': 'foobar'})
self.assertContains(r, 'Invalid apikey', status_code=403)

# working case
r = self.client.post(url, {'apikey': apikey.hash()})
self.assertEqual(r.status_code, 200)
jsondata = r.json()
self.assertEqual(jsondata['success'], True)
self.client.logout()

def test_api_get_session_matherials_no_agenda_meeting_url(self):
meeting = MeetingFactory(type_id='ietf')
session = SessionFactory(meeting=meeting)
Expand Down
2 changes: 1 addition & 1 deletion ietf/ietfauth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def test_apikey_errors(self):
self.assertContains(r, 'Invalid apikey', status_code=403)

# invalid apikey (invalidated api key)
unauthorized_url = urlreverse('ietf.api.views.app_auth')
unauthorized_url = urlreverse('ietf.api.views.app_auth', kwargs={'app': 'authortools'})
invalidated_apikey = PersonalApiKey.objects.create(
endpoint=unauthorized_url, person=person, valid=False)
r = self.client.post(unauthorized_url, {'apikey': invalidated_apikey.hash()})
Expand Down
2 changes: 1 addition & 1 deletion ietf/person/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Meta:

class PersonalApiKeyFactory(factory.django.DjangoModelFactory):
person = factory.SubFactory(PersonFactory)
endpoint = FuzzyChoice(PERSON_API_KEY_ENDPOINTS)
endpoint = FuzzyChoice(v for v, n in PERSON_API_KEY_ENDPOINTS)

class Meta:
model = PersonalApiKey
Expand Down

0 comments on commit dd110a8

Please sign in to comment.