def setUp(self): self.submitter = create_user() self.user = create_user() self.activity1 = create_activity(submitter=self.submitter) self.activity2 = create_activity(submitter=self.submitter) self.client.login(username=self.user.username, password="******")
def test_list_view_with_employee(self): """ Test that an employee will have two tables: (1) all approved activities (including their clubs') (2) their clubs' approved activities """ self.employee = create_user() self.club2.employee = self.employee self.club2.save() self.another_approved_activity = add_deanship_review(add_presidency_review(create_activity(club=self.club2), True), True) self.client.login(username=self.employee.username, password="******") response = self.client.get(reverse('activities:list')) self.assertEqual(response.status_code, 200) self.assertNotIn(self.activity_nn, response.context['pending']) self.assertNotIn(self.activity_pn, response.context['pending']) self.assertNotIn(self.activity_rn, response.context['rejected']) self.assertNotIn(self.activity_an, response.context['pending']) self.assertNotIn(self.activity_ap, response.context['pending']) self.assertNotIn(self.activity_ar, response.context['rejected']) self.assertIn(self.activity_aa, response.context['approved']) self.assertIn(self.another_approved_activity, response.context['approved']) self.assertNotIn(self.activity_aa, response.context['club_approved']) self.assertIn(self.another_approved_activity, response.context['club_approved'])
def test_show_view_with_a_normal_user(self): """ Test the show activity view with a user with no permissions. """ # Setup the database normal_user = create_user('normal_user') club = create_club() activity = create_activity(submitter=normal_user, club=club) add_presidency_review(activity, True) add_deanship_review(activity, True) # Login logged_in = self.client.login(username=normal_user.username, password='******') self.assertEqual(logged_in, True) # Go to the view response = self.client.get(reverse('activities:show', args=(activity.pk, ))) self.assertEqual(response.status_code, 200) self.assertContains(response, activity.name) self.assertContains(response, activity.primary_club.name) # self.assertContains(response, activity.description) # Normal user should not see activity status self.assertNotContains(response, 'tooltip-primary') # Normal user should not see edit button self.assertNotContains(response, 'href="' + reverse('activities:edit', args=(activity.pk, )) + '"' ) # Normal user should not see review buttons self.assertNotContains(response, u'مراجعة رئاسة نادي الطلاب') self.assertNotContains(response, u'مراجعة عمادة شؤون الطلاب')
def test_list_view_with_employee(self): """ Test that an employee will have two tables: (1) all approved activities (including their clubs') (2) their clubs' approved activities """ self.employee = create_user() self.club2.employee = self.employee self.club2.save() self.another_approved_activity = add_deanship_review( add_presidency_review(create_activity(club=self.club2), True), True) self.client.login(username=self.employee.username, password="******") response = self.client.get(reverse('activities:list')) self.assertEqual(response.status_code, 200) self.assertNotIn(self.activity_nn, response.context['pending']) self.assertNotIn(self.activity_pn, response.context['pending']) self.assertNotIn(self.activity_rn, response.context['rejected']) self.assertNotIn(self.activity_an, response.context['pending']) self.assertNotIn(self.activity_ap, response.context['pending']) self.assertNotIn(self.activity_ar, response.context['rejected']) self.assertIn(self.activity_aa, response.context['approved']) self.assertIn(self.another_approved_activity, response.context['approved']) self.assertNotIn(self.activity_aa, response.context['club_approved']) self.assertIn(self.another_approved_activity, response.context['club_approved'])
def test_show_view_with_a_normal_user(self): """ Test the show activity view with a user with no permissions. """ # Setup the database normal_user = create_user('normal_user') club = create_club() activity = create_activity(submitter=normal_user, club=club) add_presidency_review(activity, True) add_deanship_review(activity, True) # Login logged_in = self.client.login(username=normal_user.username, password='******') self.assertEqual(logged_in, True) # Go to the view response = self.client.get( reverse('activities:show', args=(activity.pk, ))) self.assertEqual(response.status_code, 200) self.assertContains(response, activity.name) self.assertContains(response, activity.primary_club.name) # self.assertContains(response, activity.description) # Normal user should not see activity status self.assertNotContains(response, 'tooltip-primary') # Normal user should not see edit button self.assertNotContains( response, 'href="' + reverse('activities:edit', args=(activity.pk, )) + '"') # Normal user should not see review buttons self.assertNotContains(response, u'مراجعة رئاسة نادي الطلاب') self.assertNotContains(response, u'مراجعة عمادة شؤون الطلاب')
def setUp(self): self.user = create_user() self.activity = create_activity() create_codes(5, activity=self.activity, category=Category.objects.get(points=1)) create_codes(5, activity=self.activity, category=Category.objects.get(points=2)) create_codes(5, activity=self.activity, category=Category.objects.get(points=3)) self.client.login(username=self.user.username, password='******')
def setUp(self): self.presidency = create_club(english_name="Presidency") self.media_center = create_club(english_name="Media Center") self.club = create_club() self.club2 = create_club() self.user = create_user(username="******") self.client.login(username=self.user.username, password="******") # The following activities represent the 7 common patterns for activities in terms of their approval status. # The naming of the following activities follows this pattern: activity_[P][D], # where [P] represents the status of the activity's presidency review # and [D] represents the status of the activity's DSA review. # The possible statuses are n (nonexistent), p (pending), r (rejected), and a (approved). self.activity_nn = create_activity(club=self.club) # no review self.activity_pn = add_presidency_review( create_activity(club=self.club2), None) # and add reviews # p: pending, n: none self.activity_rn = add_presidency_review( create_activity(club=self.club2), False) self.activity_an = add_presidency_review( create_activity(club=self.club), True) self.activity_ap = add_deanship_review( add_presidency_review(create_activity(club=self.club), True), None) self.activity_ar = add_deanship_review( add_presidency_review(create_activity(club=self.club), True), False) self.activity_aa = add_deanship_review( add_presidency_review(create_activity(club=self.club), True), True)
def create_codes(count, activity=create_activity(), category=Category.objects.get(pk=1)): order = Code_Order.objects.create(activity=activity) collec = Code_Collection.objects.create(parent_order=order, code_category=category, code_count=count, delivery_type='0', ) for i in range(count): create_code(activity=activity, category=category, collection=collec, )
def test_show_view_with_a_privileged_user(self): privileged_user = create_user('user2') view_activity = Permission.objects.get(codename='view_activity') change_activity = Permission.objects.get(codename='change_activity') view_deanship_review = Permission.objects.get( codename='view_deanship_review') view_presidency_review = Permission.objects.get( codename='view_presidency_review') privileged_user.user_permissions.add(view_activity, change_activity, view_deanship_review, view_presidency_review) club = create_club() activity = create_activity(submitter=privileged_user) # Login logged_in = self.client.login(username=privileged_user.username, password='******') self.assertEqual(logged_in, True) # Go to the view response = self.client.get( reverse('activities:show', args=(activity.pk, ))) # Housekeeping tests self.assertEqual(response.status_code, 200) self.assertContains(response, activity.name) self.assertContains(response, activity.primary_club.name) self.assertContains(response, activity.description) # Privileged user should see activity status self.assertContains(response, 'tooltip-primary') # Privileged user should see edit button self.assertContains( response, 'href="' + reverse('activities:edit', args=(activity.pk, )) + '"') # Privileged user should see review buttons self.assertContains(response, u'مراجعة رئاسة نادي الطلاب') self.assertContains(response, u'مراجعة عمادة شؤون الطلاب')
def setUp(self): self.presidency = create_club(english_name="Presidency") self.media_center = create_club(english_name="Media Center") self.club = create_club() self.club2 = create_club() self.user = create_user(username="******") self.client.login(username=self.user.username, password="******") # The following activities represent the 7 common patterns for activities in terms of their approval status. # The naming of the following activities follows this pattern: activity_[P][D], # where [P] represents the status of the activity's presidency review # and [D] represents the status of the activity's DSA review. # The possible statuses are n (nonexistent), p (pending), r (rejected), and a (approved). self.activity_nn = create_activity(club=self.club) # no review self.activity_pn = add_presidency_review(create_activity(club=self.club2), None) # and add reviews # p: pending, n: none self.activity_rn = add_presidency_review(create_activity(club=self.club2), False) self.activity_an = add_presidency_review(create_activity(club=self.club), True) self.activity_ap = add_deanship_review(add_presidency_review(create_activity(club=self.club), True), None) self.activity_ar = add_deanship_review(add_presidency_review(create_activity(club=self.club), True), False) self.activity_aa = add_deanship_review(add_presidency_review(create_activity(club=self.club), True), True)
def test_show_view_with_a_privileged_user(self): privileged_user = create_user('user2') view_activity = Permission.objects.get(codename='view_activity') change_activity = Permission.objects.get(codename='change_activity') view_deanship_review = Permission.objects.get(codename='view_deanship_review') view_presidency_review = Permission.objects.get(codename='view_presidency_review') privileged_user.user_permissions.add(view_activity, change_activity, view_deanship_review, view_presidency_review) club = create_club() activity = create_activity(submitter=privileged_user) # Login logged_in = self.client.login(username=privileged_user.username, password='******') self.assertEqual(logged_in, True) # Go to the view response = self.client.get(reverse('activities:show', args=(activity.pk, ))) # Housekeeping tests self.assertEqual(response.status_code, 200) self.assertContains(response, activity.name) self.assertContains(response, activity.primary_club.name) self.assertContains(response, activity.description) # Privileged user should see activity status self.assertContains(response, 'tooltip-primary') # Privileged user should see edit button self.assertContains(response, 'href="' + reverse('activities:edit', args=(activity.pk, )) + '"' ) # Privileged user should see review buttons self.assertContains(response, u'مراجعة رئاسة نادي الطلاب') self.assertContains(response, u'مراجعة عمادة شؤون الطلاب')
def setUp(self): self.user = create_user() self.activity = create_activity()
def setUp(self): self.user = create_user(username="******") self.activity = create_activity(club=Club.objects.get(pk=3)) self.client.login(username=self.user.username, password='******')