Add unit test

This commit is contained in:
Ramon Wenger 2023-08-16 15:52:19 +02:00
parent 1a3e7c9169
commit d37197bd3d
1 changed files with 33 additions and 0 deletions

View File

@ -218,3 +218,36 @@ class LoginTests(TestCase):
self.fail('LoginTests.test_teacher_can_login_with_valid_license: Userdata should not exist') self.fail('LoginTests.test_teacher_can_login_with_valid_license: Userdata should not exist')
except: except:
pass pass
@patch.object(HepClient, "fetch_eorders", return_value=VALID_TEACHERS_ORDERS)
@patch.object(DjangoOAuth2App, "authorize_access_token", return_value=TOKEN)
@patch.object(HepClient, "user_details", return_value=ME_DATA)
def test_update_of_duration_in_code_MS768(
self, user_mock, authorize_mock, orders_mock
):
"""
https://iterativ.atlassian.net/browse/MS-768
"""
response = self._login("/api/oauth/authorize?code=1234")
user = User.objects.get(email=ME_DATA["email"])
# user_role_key = user.user_roles.get(user=user).role.key
# Create a license that expires in 70 days later than duration...
# (which is special since the expiration date is set to now+ duration)
# This simulates that the duration was changed in the code after the license was created
current_license: License = (
License.objects.filter(licensee=user).order_by("-expire_date").first()
)
current_license.expire_date = current_license.expire_date + timedelta(days=700)
current_license.save()
for _ in range(5):
response = self._login("/api/oauth/authorize?code=1234")
# Check that only one new licesnse was created and not one for each login
self.assertEqual(License.objects.all().count(), 2)
self.assertEqual(response.url, f"/{OAUTH_REDIRECT}?state=success")
self.assertTrue(self.user.is_authenticated)