def test_dive_list_shows_dives_of_logged_in_user_only(self): user_1 = UserFactory() user_2 = UserFactory() _ = DiveFactory(created_by=user_1) _ = DiveFactory(created_by=user_1) _ = DiveFactory(created_by=user_2) self.client.force_login(user_1) response = self.client.get(reverse('dive_list')) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context_data['dive_list']), 2)
def setUp(self): self.superuser = get_user_model().objects.create_superuser( username='******', email='*****@*****.**', password='******') self.user_1 = UserFactory() self.user_2 = UserFactory() self.dive_1 = DiveFactory(created_by=self.user_1) self.dive_2 = DiveFactory(created_by=self.user_2) self.dive_3 = DiveFactory(created_by=self.user_2)
def test_dive_list_view_does_not_shows_dives_of_other_user(self): user1 = UserFactory() user2 = UserFactory() _ = DiveFactory(created_by=user1) _ = DiveFactory(created_by=user1) _ = DiveFactory(created_by=user1) self.client.force_login(user2) response = self.client.get(reverse('dive_list')) self.assertContains(response, 'You do not have any dives registered yet!') self.assertEqual(response.status_code, 200)
def setUp(self): self.user = UserFactory() self.dive = DiveFactory(created_by=self.user)