def setUp(test, permission_names): user = ModelFactory.create_user() password = "******" user.set_password(password) user.save() content_type = ContentType.objects.get_for_model(Rsvp) for permission_name in permission_names: permission = Permission.objects.get(content_type=content_type, codename=permission_name) user.user_permissions.add(permission) test.client.login(username=user.username, password=password) event_type = ModelFactory.create_event_type() event = ModelFactory.create_event( name="custom event name", event_type=event_type, created_by=user, access_level=2, ) test.user = user test.password = password test.event = event
def setUp(self): user = ModelFactory.create_user() event_type = ModelFactory.create_event_type() event_name = "custom event name" event = ModelFactory.create_event( name=event_name, event_type=event_type, created_by=user, ) self.user = user self.event_type = event_type self.event_name = event_name self.event = event
def test_events_with_event_type_without_access(self): user = ModelFactory.create_user() event_type = ModelFactory.create_event_type() event = ModelFactory.create_event( name="custom event name", event_type=event_type, created_by=user, access_level=1, ) response = self.client.get(reverse("events:index")) self.assertEqual(response.status_code, 200) self.assertQuerysetEqual(response.context["event_types"], [repr(event_type)]) self.assertQuerysetEqual(response.context["events"], [])
def test_reviewsessions_details(self): user = ModelFactory.create_user() event_type = EventType.objects.create(type="Review Session") rs = ModelFactory.create_event( name="custom event name", event_type=event_type, created_by=user, access_level=2, ) kwargs = {"id": rs.id} response = self.client.get( reverse("studentservices:show_reviewsession_details", kwargs=kwargs) ) self.assertEqual(response.status_code, 200)
def test_no_events_with_event_type(self): event_type = ModelFactory.create_event_type() response = self.client.get(reverse("events:index")) self.assertEqual(response.status_code, 200) self.assertQuerysetEqual(response.context["event_types"], [repr(event_type)]) self.assertQuerysetEqual(response.context["events"], [])
def test_returns_200(self): user = ModelFactory.create_user() password = "******" user.set_password(password) user.save() content_type = ContentType.objects.get_for_model(Rsvp) permission = Permission.objects.get(content_type=content_type, codename="add_rsvp") user.user_permissions.add(permission) self.client.login(username=user.username, password=password) ModelFactory.create_event_type() response = self.client.get(reverse("events:rsvps")) self.assertEqual(response.status_code, 200)
def test_events_ordered_by_start_time_descending(self): user = ModelFactory.create_user() event_type = ModelFactory.create_event_type() num_events = 3 events = [ ModelFactory.create_event( name="custom event {}".format(i), event_type=event_type, created_by=user, access_level=2, ) for i in range(1, 1 + num_events) ] response = self.client.get(reverse("events:index")) self.assertEqual(response.status_code, 200) expected = [repr(event) for event in reversed(events)] actual = response.context["events"] self.assertQuerysetEqual(actual, expected)
def setUp(self): password = "******" user = ModelFactory.create_user( username="******", email="*****@*****.**", ) user.set_password(password) user.save() self.user = user self.password = password
def setUp(self): password = "******" candidate = ModelFactory.create_user( username="******", email="*****@*****.**", first_name="test", last_name="candidate", ) candidate.set_password(password) candidate.save() officer = ModelFactory.create_user( username="******", email="*****@*****.**", first_name="test", last_name="officer1", ) officer.set_password(password) officer.save() officer2 = ModelFactory.create_user( username="******", email="*****@*****.**", first_name="test", last_name="officer2", ) officer2.set_password(password) officer2.save() provision() candidate_group = Group.objects.get(name="candidate") candidate_group.user_set.add(candidate) candidate_group.save() officer_group = Group.objects.get(name="officer") officer_group.user_set.add(officer) officer_group.user_set.add(officer2) officer_group.save() self.password = password self.candidate = candidate self.officer = officer self.officer2 = officer2
def test_event_types_ordered_by_type_ascending(self): num_event_types = 3 event_types = [ ModelFactory.create_event_type( type="custom event type {}".format(i)) for i in range(1, 1 + num_event_types) ] response = self.client.get(reverse("events:index")) self.assertEqual(response.status_code, 200) expected = [repr(event_type) for event_type in event_types] actual = response.context["event_types"] self.assertQuerysetEqual(actual, expected)
def test_checkoff_event_returns_302(self): event_type = ModelFactory.create_event_type(type="test_event_type") event = ModelFactory.create_event( "test_event_name", event_type, created_by=self.officer ) self.client.login(username=self.officer.username, password=self.password) csv_file = SimpleUploadedFile( "csv_file.csv", str.encode( "Email,First Name,Last Name\n{},{},{}\n".format( self.officer.email, self.officer.first_name, self.officer.last_name, ) ), ) data = {"csv_file": csv_file, "checkoff_type": "event", "event_id": event.id} response = self.client.post(reverse("candidate:checkoff_csv"), data=data) self.client.logout() self.assertEqual(response.status_code, 302)
def setUp(self): ( event_create_user, rsvp_users, event_type, event_name, event, rsvps, ) = ModelFactory.create_event_with_rsvps() self.event_create_user = event_create_user self.rsvp_users = rsvp_users self.event_type = event_type self.event_name = event_name self.event = event self.rsvps = rsvps
def setUp(self): event_type = ModelFactory.create_event_type() self.event_type = event_type