Skip to content

Commit

Permalink
Fix breaking tests with upgraded django version
Browse files Browse the repository at this point in the history
  • Loading branch information
oleast committed Mar 29, 2020
1 parent a4025dc commit fcd9e28
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 32 deletions.
8 changes: 4 additions & 4 deletions apps/authentication/api/tests/user_data_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_user_cannot_create_an_email_with_an_existing_address(self):
def test_user_can_change_primary_email(self):
self.assertTrue(self.email.primary)

email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)

response = self.client.patch(
self.id_url(email.id), {"primary": True}, **self.headers
Expand All @@ -89,7 +89,7 @@ def test_user_can_change_primary_email(self):
def test_user_cannot_remove_primary_email_without_selecting_a_new_primary(self):
self.assertTrue(self.email.primary)

email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)

response = self.client.patch(
self.id_url(email.id), {"primary": False}, **self.headers
Expand All @@ -108,7 +108,7 @@ def test_user_cannot_remove_primary_email_without_selecting_a_new_primary(self):
self.assertTrue(self.email.primary)

def test_user_cannot_verify_emails_without_token(self):
email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)
response = self.client.patch(
self.id_url(email.id), {"verified": True}, **self.headers
)
Expand All @@ -121,7 +121,7 @@ def test_user_cannot_verify_emails_without_token(self):
def test_user_cannot_change_the_address_of_an_existing_email(self):
address = "[email protected]"
other_address = "[email protected]"
email: Email = G(Email, user=self.user, verfied=False, email=address)
email: Email = G(Email, user=self.user, verified=False, email=address)
self.client.patch(
self.id_url(email.id), {"email": other_address}, **self.headers
)
Expand Down
4 changes: 2 additions & 2 deletions apps/dataporten/study/tests/task_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_fetch_groups_information(self, mocked_request):

class StudyUpdatingTestCase(TestCase):
def test_find_user_study_and_update_1st_grader(self):
user = G(OnlineUser)
user = G(OnlineUser, ntnu_username="testesen")
groups = [
INFORMATICS_BACHELOR_STUDY_PROGRAMME,
load_course(ITGK_ACTIVE, years_ago=0),
Expand All @@ -57,7 +57,7 @@ def test_find_user_study_and_update_1st_grader(self):
self.assertEqual(len(mail.outbox), 0)

def test_find_user_study_and_update_5th_grader(self):
user = G(OnlineUser)
user = G(OnlineUser, ntnu_username="testesen")
groups = [
INFORMATICS_MASTER_STUDY_PROGRAMME,
load_course(PVS_ACTIVE, active=True),
Expand Down
6 changes: 4 additions & 2 deletions apps/events/tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def test_event_with_group_restriction(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)

restricted_to_group: Group = G(Group)
G(GroupRestriction, event=self.event, group=restricted_to_group)
G(GroupRestriction, event=self.event, groups=[restricted_to_group])

response = self.client.get(self.id_url(self.event.id), **self.headers)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Expand All @@ -502,7 +502,9 @@ def test_event_with_group_restriction(self):
class AttendAPITestCase(OIDCTestCase):
def setUp(self):
self.committee = G(Group, name="Arrkom")
self.user = G(OnlineUser, name="test_user", groups=[self.committee])
self.user = G(
OnlineUser, first_name="Test", last_name="Testesen", groups=[self.committee]
)
self.token = self.generate_access_token(self.user)
self.headers = {
**self.generate_headers(),
Expand Down
4 changes: 3 additions & 1 deletion apps/events/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def add_payment_delay(payment: Payment, user: OnlineUser) -> PaymentDelay:


def generate_user(username: str) -> OnlineUser:
user = G(OnlineUser, username=username, ntnu_username=username)
user = G(
OnlineUser, username=username, ntnu_username=username, phone_number="12345678"
)
G(Email, user=user)
return user

Expand Down
14 changes: 12 additions & 2 deletions apps/gsuite/mail_syncer/tests/apiclient_utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ def test_get_g_suite_users_for_group_no_members(self, mocked_g_suite_client):

@patch("apps.gsuite.mail_syncer.utils.setup_g_suite_client", autospec=True)
def test_get_g_suite_groups_for_user(self, mocked_g_suite_client):
user = G(OnlineUser)
user = G(
OnlineUser,
first_name="Test",
last_name="Testesen",
online_mail="test.testesen",
)

ow4_gsuite_sync = settings.OW4_GSUITE_SYNC
ow4_gsuite_sync["ENABLED"] = True
Expand All @@ -306,7 +311,12 @@ def test_get_g_suite_groups_for_user(self, mocked_g_suite_client):

@patch("apps.gsuite.mail_syncer.utils.setup_g_suite_client", autospec=True)
def test_get_g_suite_groups_for_user_no_members(self, mocked_g_suite_client):
user = G(OnlineUser)
user = G(
OnlineUser,
first_name="Test",
last_name="Testesen",
online_mail="test.testesen",
)

ow4_gsuite_sync = settings.OW4_GSUITE_SYNC
ow4_gsuite_sync["ENABLED"] = True
Expand Down
7 changes: 6 additions & 1 deletion apps/gsuite/mail_syncer/tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def test_get_user_no_params(self):
self.assertRaises(ValueError, lambda: get_user(object))

def test_get_user(self):
user = G(OnlineUser)
user = G(
OnlineUser,
first_name="Test",
last_name="Testesen",
online_mail="test.testesen",
)
self.assertEqual(user, get_user(user, ow4=True))
self.assertEqual(user.online_mail, get_user(user, gsuite=True))

Expand Down
2 changes: 1 addition & 1 deletion apps/payment/tests/view_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
self.attendance_event = G(
AttendanceEvent,
event=self.event,
unnatend_deadline=timezone.now() + timedelta(days=1),
unattend_deadline=timezone.now() + timedelta(days=1),
)
self.user = G(
User,
Expand Down
17 changes: 3 additions & 14 deletions apps/webshop/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,9 @@ class CurrentOrderLineDefault(serializers.CurrentUserDefault):
Gets the currently active order_line for the logged in user
"""

def __init__(self, *args, **kwargs):
self.order_line = None
super().__init__(*args, **kwargs)

def set_context(self, serializer_field):
# Call set_context to set the user in the context of this object
super().set_context(serializer_field)
self.order_line = self.get_or_create_order_line()

def get_or_create_order_line(self) -> OrderLine:
return OrderLine.get_current_order_line_for_user(self.user)

def __call__(self):
return self.order_line
def __call__(self, serializer_field):
user = super().__call__(serializer_field)
return OrderLine.get_current_order_line_for_user(user)


class OrderCreateSerializer(serializers.ModelSerializer):
Expand Down
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ PyMuPDF==1.16.5
# django-filebrowser==3.12.1 # File uploading
git+https://github.com/sehmaschine/django-filebrowser.git@4c1a86d67cd7424df57b0e6880152b309823f009#egg=django-filebrowser==3.12.2
git+https://github.com/dotKom/django-chunks.git@e6bf109d4fd286964024c140ac1b8f3d86713540#egg=django-chunks==0.4
django-crispy-forms==1.8.1 # nice forms
django-crispy-forms==1.9.0 # nice forms
django-extensions==2.2.8 # nice extra commands for debugging, etc
django-dynamic-fixture==3.0.2 # Dynamic fixtures for models
django-dynamic-fixture==3.1.0 # Dynamic fixtures for models
django-recaptcha==2.0.6 # Google ReCaptcha
django-oauth-toolkit==1.2.0 # OAuth2 authentication support
django-watson==1.5.4 # Indexed model search lib
django-reversion==3.0.5 # Model version history with middleware hooks to all post_save signals
django-reversion==3.0.7 # Model version history with middleware hooks to all post_save signals
django-guardian==2.2.0 # Per Object permissions framework
django-taggit==1.2.0 # Generic multi-model tagging library
django-taggit-serializer==0.1.7 # REST Framework serializers for Django-taggit
Expand All @@ -50,8 +50,7 @@ coreapi==2.3.3 # API documentation
requests[security]==2.22.0

# Wiki
# wiki==0.6
git+https://github.com/django-wiki/django-wiki.git@f19f3e5d729e887054513229c727015f1eaed712#egg=wiki==0.5.1
wiki==0.6b1

# Django 1.9 support
sorl-thumbnail==12.6.2
Expand Down

0 comments on commit fcd9e28

Please sign in to comment.