def test_register__invalid_email(self, api_client): user_data = generate_user_profile() user_data['email'] = 'invalid_email' response = api_client.post(self.register_url, user_data) response_json = response.json() assert response.status_code == status.HTTP_400_BAD_REQUEST assert 'email' in response_json
def test_register_with_email_confirmation(self, api_client, test_user): allow(UserService).register_new_user.and_return(test_user) user_data = generate_user_profile() response = api_client.post(self.register_url, user_data) response_json = response.json() assert response.status_code == status.HTTP_200_OK assert mail_outbox() == 1 assert response_json.get('code') == AccountsResponses.CONFIRMATION_EMAIL_SENT.get('code')
def test_register(self, api_client, test_user): allow(UserService).register_new_user.and_return(test_user) user_data = generate_user_profile() response = api_client.post(self.register_url, user_data) response_json = response.json() serialized_data = SessionSerializer(test_user).data assert response.status_code == status.HTTP_200_OK assert response_json.keys() == serialized_data.keys()
def test_register__existent_user(self, api_client, test_user): user_data = generate_user_profile() user_data['username'] = test_user.username response = api_client.post(self.register_url, user_data) assert response.status_code == status.HTTP_400_BAD_REQUEST assert_validation_code( response_json=response.json(), attribute='username', code=AccountsErrorCodes.USERNAME_ALREDY_USED.code, )
def test_update_profile__with_photo(self, auth_api_client): profile = generate_user_profile() profile['photo'] = generate_image() response = auth_api_client.put( self.profile_url, data=profile, format='multipart', ) assert response.status_code == status.HTTP_200_OK self.assert_profile(response, profile)
def test_update_profile_alredy_used_username(self, auth_api_client): existent_user = UserFactory() profile = generate_user_profile() profile['username'] = existent_user.username response = auth_api_client.put(self.profile_url, data=profile) response_json = response.json() assert response.status_code == status.HTTP_400_BAD_REQUEST assert 'username' in response_json assert has_same_code(response_json['username'][0], USERNAME_UNAVAILABLE)
def test_update_profile_alredy_used_username(self, auth_api_client): existent_user = UserFactory() profile = generate_user_profile() profile['username'] = existent_user.username response = auth_api_client.put(self.profile_url, data=profile) assert response.status_code == status.HTTP_400_BAD_REQUEST assert_validation_code( response_json=response.json(), attribute='username', code=AccountsErrorCodes.USERNAME_UNAVAILABLE.code, )
def test_register__forbidden_username(self, api_client): forbidden_usernames = settings.USERNAME_BLACKLIST user_data = generate_user_profile() user_data['username'] = forbidden_usernames[0] response = api_client.post(self.register_url, user_data) assert response.status_code == status.HTTP_400_BAD_REQUEST assert_validation_code( response_json=response.json(), attribute='username', code=AccountsErrorCodes.USERNAME_ALREDY_USED.code, )
def test_register__existent_user(self, api_client, test_user): user_data = generate_user_profile() user_data['username'] = test_user.username response = api_client.post(self.register_url, user_data) response_json = response.json() assert response.status_code == status.HTTP_400_BAD_REQUEST assert 'username' in response_json assert has_same_code( response_codes.USERNAME_ALREDY_USED, response_json['username'][0], )
def test_register__forbidden_username(self, api_client): forbidden_usernames = settings.USERNAME_BLACKLIST user_data = generate_user_profile() user_data['username'] = forbidden_usernames[0] response = api_client.post(self.register_url, user_data) response_json = response.json() assert response.status_code == status.HTTP_400_BAD_REQUEST assert 'username' in response_json assert has_same_code( response_codes.USERNAME_ALREDY_USED, response_json['username'][0], )
def test_update_profile_crendentials_required(self, api_client): profile = generate_user_profile() response = api_client.put(self.profile_url, data=profile) assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_update_profile(self, auth_api_client): profile = generate_user_profile() response = auth_api_client.put(self.profile_url, data=profile) assert response.status_code == status.HTTP_200_OK self.assert_profile(response, profile)
def get_profile(): data = generate_user_profile() password = data.pop('password') data['password1'] = password data['password2'] = password return data