def perform_retrieve_with_participant(self): obj = self.factory.create() user = UserFactory.create() Participation.objects.create(visit=obj, user=user) self.client.force_login(user=user) response = self.perform_retrieve(obj=obj) return response
def test_get_absolute_url(self): self.client.force_login(UserFactory.create()) url = self.obj.get_absolute_url() expected = '/api/visits/{}/'.format(self.obj.pk) self.assertEqual(url, expected) response = self.client.get(url) self.assertEqual(200, response.status_code)
def test_if_email_of_existing_user_returns_bad_request(self): user = UserFactory.create() data = self.get_create_data() data['email'] = user.email response = self._create(data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) self.assertIn('email', response.data)
def assertAuthForbidden(self, perform_request): """Assert request is forbidden to anonymous and authenticated users. Parameters ---------- perform_request : function: None -> response Should send the request of interest and return the response object. """ self.assertRequiresAuth(perform_request) self.assertRequestResponse( perform_request, user=UserFactory.create(), expected_status_code=status.HTTP_403_FORBIDDEN)
def assertUserRequestResponse(self, perform_request, expected_status_code): """Perform a request with an authenticated user & check status code. Parameters ---------- perform_request : function: None -> response Should send the request of interest and return the response object. expected_status_code : int HTTP status code. """ self.assertRequestResponse(perform_request, user=UserFactory.create(), expected_status_code=expected_status_code)
def perform_create(self): user = UserFactory.create() edition = EditionFactory.create() form = Form.objects.create(title="What's up?") entry = { 'form': form.pk, 'answers': [], } payload = { 'user': user.pk, 'edition_id': edition.pk, 'entry': entry, } return self.client.post('/api/project-participations/', data=payload, format='json')
def setUp(self): super().setUp() # create a fake user self.fake_password = '******' self.user = UserFactory.create(password=self.fake_password)
def setUp(self): self.user = UserFactory.create() VisitFactory.create() self.obj = ParticipationFactory.create()
def setUpTestData(cls): """Create a bunch of users and visits to choose from.""" UserFactory.create_batch(10) VisitFactory.create_batch(10) cls.factory.create_batch(5)
def test_user_exists_has_not_created_admin(self): UserFactory.create() self.assertEqual(self.count_created(), 0)
def test_two_users_with_same_email_not_allowed(self): same_email = '*****@*****.**' UserFactory.create(email=same_email) _, created = User.objects.get_or_create(email=same_email) self.assertFalse(created)
def test_two_users_with_same_username_allowed(self): UserFactory.create(username='******') UserFactory.create(username='******')
def setUpTestData(self): self.obj = UserFactory.create()
def handle(self, *args, **options): test_user = UserFactory.create() subjects = SubjectFactory.create_batch(options["subject"], owner=test_user) for subject in subjects: NoteFactory.create_batch(options["note"], subject=subject, owner=test_user)
def test_get_absolute_url(self): self.client.force_login(UserFactory.create()) url = self.obj.get_absolute_url() response = self.client.get(url) self.assertEqual(200, response.status_code)
def decorated(self, *args, **kwargs): self.client.force_login(UserFactory.create()) return test_method(self, *args, **kwargs)
def setUp(self): self.user = UserFactory.create() self.visit = VisitFactory.create() self.obj = self.create()