def test_can_see_default_cohort(self): # Only students in cohort1 (or with no cohort, i.e. the default cohort) # can see exhibitions for the default cohort1 exhibition_cohort1 = Exhibition(title='New Exhibition', description='description goes here', cohort=self.cohort1) self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertFalse(exhibition_cohort1.can_see(self.cohort2_user)) # Staff can see all exhibitions self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort2_user)) # Super users can see all exhibitions self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort2_user))
def test_can_see_non_default_cohort(self): # Only users in cohort2 can see exhibitions for cohort2 exhibition_cohort2 = Exhibition(title='New Exhibition', description='description goes here', cohort=self.cohort2) self.assertFalse(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertFalse(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user)) # Staff can see all exhibitions self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user)) # Super users can see all exhibitions self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user))
def test_can_see_non_default_cohort(self): # Only users in cohort2 can see exhibitions for cohort2 exhibition_cohort2 = Exhibition( title='New Exhibition', description='description goes here', cohort=self.cohort2) self.assertFalse(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertFalse(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user)) # Staff can see all exhibitions self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user)) # Super users can see all exhibitions self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_cohort2.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort2.can_see(self.cohort2_user))
def test_can_see_default_cohort(self): # Only students in cohort1 (or with no cohort, i.e. the default cohort) # can see exhibitions for the default cohort1 exhibition_cohort1 = Exhibition( title='New Exhibition', description='description goes here', cohort=self.cohort1) self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertFalse(exhibition_cohort1.can_see(self.cohort2_user)) # Staff can see all exhibitions self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort2_user)) # Super users can see all exhibitions self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_cohort1.can_see(self.no_cohort_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort1_user)) self.assertTrue(exhibition_cohort1.can_see(self.cohort2_user))
def test_can_see(self): now = timezone.now() # Released yesterday yesterday = Exhibition(title='New Exhibition', description='description goes here', released_at=now + timedelta(hours=-24)) self.assertTrue(yesterday.can_see(self.user)) self.assertTrue(yesterday.can_see(self.staff_user)) self.assertTrue(yesterday.can_see(self.super_user)) # Released today today = Exhibition(title='New Exhibition', description='description goes here', released_at=now) self.assertTrue(today.can_see(self.user)) self.assertTrue(today.can_see(self.staff_user)) self.assertTrue(today.can_see(self.super_user)) # Released today tomorrow = Exhibition(title='New Exhibition', description='description goes here', released_at=now + timedelta(hours=24)) self.assertFalse(tomorrow.can_see(self.user)) self.assertTrue(tomorrow.can_see(self.staff_user)) self.assertTrue(tomorrow.can_see(self.super_user))
def test_can_see_null_cohorts(self): # All users can see exhibitions with null cohorts exhibition_all = Exhibition( title='New Exhibition', description='description goes here', ) self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user)) self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user)) self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user))
def test_can_see(self): now = timezone.now() # Released yesterday yesterday = Exhibition( title='New Exhibition', description='description goes here', released_at=now + timedelta(hours=-24)) self.assertTrue(yesterday.can_see(self.user)) self.assertTrue(yesterday.can_see(self.staff_user)) self.assertTrue(yesterday.can_see(self.super_user)) # Released today today = Exhibition( title='New Exhibition', description='description goes here', released_at=now) self.assertTrue(today.can_see(self.user)) self.assertTrue(today.can_see(self.staff_user)) self.assertTrue(today.can_see(self.super_user)) # Released today tomorrow = Exhibition( title='New Exhibition', description='description goes here', released_at=now + timedelta(hours=24)) self.assertFalse(tomorrow.can_see(self.user)) self.assertTrue(tomorrow.can_see(self.staff_user)) self.assertTrue(tomorrow.can_see(self.super_user))
def test_can_see_null_cohorts(self): # All users can see exhibitions with null cohorts exhibition_all = Exhibition( title='New Exhibition', description='description goes here', ) self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user)) self.no_cohort_user.is_staff = True self.cohort1_user.is_staff = True self.cohort2_user.is_staff = True self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user)) self.no_cohort_user.is_staff = False self.cohort1_user.is_staff = False self.cohort2_user.is_staff = False self.no_cohort_user.is_superuser = True self.cohort1_user.is_superuser = True self.cohort2_user.is_superuser = True self.assertTrue(exhibition_all.can_see(self.no_cohort_user)) self.assertTrue(exhibition_all.can_see(self.cohort1_user)) self.assertTrue(exhibition_all.can_see(self.cohort2_user))