Skip to content

Commit

Permalink
cleanup advanced title logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Oct 9, 2023
1 parent 6353023 commit 09d6bf6
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions evap/staff/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,32 +538,25 @@ class TestUserExportView(WebTestStaffMode):
@classmethod
def setUpTestData(cls) -> None:
cls.manager = make_manager()
baker.make(UserProfile, _quantity=5, _fill_optional=["first_name_given", "last_name", "email", "title"])
# titles are not filled by baker because it has a default, see https://github.com/model-bakers/model_bakery/discussions/346
baker.make(
UserProfile,
_quantity=5,
_fill_optional=["first_name_given", "last_name", "email", "title"],
is_active=False,
_fill_optional=["first_name_given", "last_name", "email"],
title=cycle(("", "Some", "Custom", "Titles")),
)
# the titles are not filled by baker
titles = cycle(("", "Some", "Custom", "Titles"))
for user in UserProfile.objects.iterator():
user.title = next(titles)
user.save()

def assertUsersExported(self, response, user_objects):
reader = csv.reader(response.text.strip().split("\n"))
# skip header
next(reader)
self.assertSetEqual({tuple(row) for row in reader}, user_objects)

def test_export_all(self):
user_objects = {
(user.title or "", user.last_name or "", user.first_name or "", user.email or "")
for user in UserProfile.objects.iterator()
}
response = self.app.get(self.url, user=self.manager)
self.assertUsersExported(response, user_objects)

reader = csv.reader(response.text.strip().split("\n"))
# skip header
next(reader)
self.assertSetEqual({tuple(row) for row in reader}, user_objects)


class TestUserImportView(WebTestStaffMode):
Expand Down

0 comments on commit 09d6bf6

Please sign in to comment.