Skip to content

Commit

Permalink
Fix broken tests and refactor tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyMay committed Aug 28, 2024
1 parent 3961e97 commit 05abe1d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 45 deletions.
4 changes: 2 additions & 2 deletions autograder/core/models/group/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def clean(self) -> None:
'Hard extended due date must be a valid date')})
except core_ut.HardDeadlineBeforeSoftDeadlineError:
raise ValidationError(
{'soft_extended_due_date': (
'Soft extended due date must not be after hard extended due date')})
{'hard_extended_due_date': (
'Hard extended due date must not be before soft extended due date')})

self.soft_extended_due_date = clean_soft
self.hard_extended_due_date = clean_hard
Expand Down
4 changes: 2 additions & 2 deletions autograder/core/models/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ def clean(self) -> None:
'Closing time must be a valid date')})
except core_ut.HardDeadlineBeforeSoftDeadlineError:
raise exceptions.ValidationError(
{'soft_closing_time': (
'Soft closing time must not be after hard closing time')})
{'closing_time': (
'Closing time must not be before soft closing time')})

self.soft_closing_time = clean_soft
self.closing_time = clean_hard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def test_error_soft_closing_time_after_closing_time(self):
name='stove', course=self.course,
closing_time=closing_time,
soft_closing_time=soft_closing_time)

self.assertIn('soft_closing_time', cm.exception.message_dict)
self.assertIn('closing_time', cm.exception.message_dict)

def test_error_soft_closing_time_not_a_date(self):
soft_closing_time = "foobar"
Expand Down
7 changes: 1 addition & 6 deletions autograder/rest_api/tests/test_views/ag_view_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def do_patch_object_test(self, ag_model_obj, client, user, url,
ignore_fields = list(ignore_fields)
ignore_fields.append('last_modified')

expected_data = ag_model_obj.to_dict()
for field in ignore_fields:
expected_data.pop(field, None)
expected_data = utils.exclude_dict(ag_model_obj.to_dict(), ignore_fields)
for key, value in request_data.items():
if isinstance(value, dict):
expected_data[key].update(value)
Expand Down Expand Up @@ -171,9 +169,6 @@ def _do_bad_update_test(self, ag_model_obj, client, user, url, request_data,
self.assertEqual(expected_status, response.status_code)

ag_model_obj = ag_model_obj._meta.model.objects.get(pk=ag_model_obj.pk)

print(f"{expected_data=}")
print(f"{ag_model_obj.to_dict()=}")
self.assert_dict_contents_equal(expected_data, ag_model_obj.to_dict())

return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ def test_admin_update_guest_group_members(self):
def test_admin_update_group_deprecated_extended_due_date(self):
group = obj_build.make_group(project=self.project)

invalid_extended_due_date = "not a date"
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'extended_due_date': invalid_extended_due_date})
self.assertIn('soft_extended_due_date', response.data)

self.do_patch_object_test(
group, self.client, self.admin, self.group_url(group),
{'extended_due_date': self.new_due_date},
Expand All @@ -498,34 +504,50 @@ def test_admin_update_group_deprecated_extended_due_date(self):
def test_admin_update_soft_extended_due_date(self):
group = obj_build.make_group(
project=self.project, hard_extended_due_date=self.new_due_date)

invalid_soft_extended_due_date = "not a date"
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'soft_extended_due_date': invalid_soft_extended_due_date})
self.assertIn('soft_extended_due_date', response.data)

# soft_extended_due_date can't be later than hard_extended_due_date
invalid_soft_extended_due_date = self.new_due_date + datetime.timedelta(days=1)
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'soft_extended_due_date': invalid_soft_extended_due_date})
self.assertIn('hard_extended_due_date', response.data)

valid_soft_extended_due_date = self.new_due_date - datetime.timedelta(days=1)
self.do_patch_object_test(
group, self.client, self.admin, self.group_url(group),
{'soft_extended_due_date': valid_soft_extended_due_date},
expected_response_overrides={
'soft_extended_due_date': valid_soft_extended_due_date.replace(
second=0, microsecond=0),
# extended_due_date is deprecated, should reflect changes to soft_extended_deadline
# setting soft_extended_due_date will also set extended_due_date
# for backwards compatibility
'extended_due_date': valid_soft_extended_due_date.replace(
second=0, microsecond=0)
})

group.refresh_from_db()
def test_admin_update_hard_extended_due_date(self):
group = obj_build.make_group(
project=self.project, soft_extended_due_date=self.new_due_date)

invalid_soft_extended_due_date = "not a date"
self.do_patch_object_invalid_args_test(
invalid_hard_extended_due_date = "not a date"
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'soft_extended_due_date': invalid_soft_extended_due_date})
{'hard_extended_due_date': invalid_hard_extended_due_date})
self.assertIn('hard_extended_due_date', response.data)

# soft_extended_due_date can't be later than hard_extended_due_date
invalid_soft_extended_due_date = self.new_due_date + datetime.timedelta(days=1)
self.do_patch_object_invalid_args_test(
# hard_extended_due_date can't be before soft_extended_due_date
invalid_hard_extended_due_date = self.new_due_date - datetime.timedelta(days=1)
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'soft_extended_due_date': invalid_soft_extended_due_date})
{'hard_extended_due_date': invalid_hard_extended_due_date})
self.assertIn('hard_extended_due_date', response.data)

def test_admin_update_hard_extended_due_date(self):
group = obj_build.make_group(
project=self.project, soft_extended_due_date=self.new_due_date)
valid_hard_extended_due_date = self.new_due_date + datetime.timedelta(days=1)
self.do_patch_object_test(
group, self.client, self.admin, self.group_url(group),
Expand All @@ -538,19 +560,6 @@ def test_admin_update_hard_extended_due_date(self):
second=0, microsecond=0)
})

group.refresh_from_db()

invalid_hard_extended_due_date = "not a date"
self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'hard_extended_due_date': invalid_hard_extended_due_date})

# hard_extended_due_date can't be before soft_extended_due_date
invalid_hard_extended_due_date = self.new_due_date - datetime.timedelta(days=1)
self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'hard_extended_due_date': invalid_hard_extended_due_date})

def test_admin_update_group_invalid_members(self):
group = obj_build.make_group(project=self.project)
new_members = self.get_names(list(group.members.all())[:-1]) + ['stove']
Expand All @@ -575,13 +584,6 @@ def test_admin_update_group_error_non_allowed_domain_guest(self):
{'member_names': [allowed_guest.username, non_allowed_guest.username]})
self.assertIn('members', response.data)

def test_admin_update_group_bad_date(self):
group = obj_build.make_group(project=self.project)
response = self.do_patch_object_invalid_args_test(
group, self.client, self.admin, self.group_url(group),
{'extended_due_date': 'not a date'})
self.assertIn('extended_due_date', response.data)

def test_non_admin_update_group_permission_denied(self):
group = obj_build.make_group(project=self.project)
staff = obj_build.make_staff_user(self.course)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ def test_edit_project_invalid_closing_time(self):
}

admin = obj_build.make_admin_user(self.course)
self.do_patch_object_invalid_args_test(
response = self.do_patch_object_invalid_args_test(
self.project, self.client, admin, self.url, request_data)
self.assertIn('closing_time', response.data)

def test_non_admin_edit_project_permission_denied(self):
staff = obj_build.make_staff_user(self.course)
Expand Down

0 comments on commit 05abe1d

Please sign in to comment.