50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from datetime import timedelta
|
|
|
|
from django.test import TestCase
|
|
from django.utils import timezone
|
|
|
|
from core.factories import UserFactory
|
|
from core.utils import is_private_api_call_allowed
|
|
|
|
|
|
class MiddlewareTestCase(TestCase):
|
|
def test_user_with_license_can_see_private_api(self):
|
|
|
|
tomorrow = timezone.now() + timedelta(1)
|
|
user = UserFactory(username='aschiman@ch.ch')
|
|
user.license_expiry_date = tomorrow
|
|
|
|
body = b'"{mutation {\\n addRoom}"'
|
|
|
|
self.assertTrue(is_private_api_call_allowed(user, body))
|
|
|
|
def test_user_without_valid_license_cannot_see_private_api(self):
|
|
|
|
yesterday = timezone.now() - timedelta(1)
|
|
user = UserFactory(username='aschiman@ch.ch', hep_id=23)
|
|
user.license_expiry_date = yesterday.date()
|
|
|
|
body = b'"{mutation {\\n addRoom}"'
|
|
|
|
self.assertFalse(is_private_api_call_allowed(user, body))
|
|
|
|
def test_logout_is_allowed_without_valid_license(self):
|
|
|
|
yesterday = timezone.now() - timedelta(1)
|
|
user = UserFactory(username='aschiman@ch.ch')
|
|
user.license_expiry_date = yesterday.date()
|
|
|
|
body = b'"{mutation { logout {"'
|
|
|
|
self.assertTrue(is_private_api_call_allowed(user, body))
|
|
|
|
def test_me_query_is_allowed_without_valid_license(self):
|
|
|
|
yesterday = timezone.now() - timedelta(1)
|
|
user = UserFactory(username='aschiman@ch.ch')
|
|
user.license_expiry_date = yesterday
|
|
|
|
body = b'"{query { me {"'
|
|
|
|
self.assertTrue(is_private_api_call_allowed(user, body))
|