def checking_new_user_removing_X_param(self, param_name): originalBody = UserPayloads.new_user('withoutParam', 'Female') originalBody.pop(param_name) body = self.user.create_user(originalBody).json() Poc_Asserts.check_status_code( 422, body['code']) #checking the supposed real code Poc_Asserts.check_list_contains_dict( { 'field': param_name, 'message': "can't be blank" }, body['data']) print('✓ user not created without {} [Unprocessable Entity]'.format( param_name))
def test_delete_user_without_authorization(self): """Checking authorization deleting users""" body = UserPayloads.new_user('delNotAuth', 'Male') resp_body = self.user.create_user(body).json() Poc_Asserts.check_status_code(201, resp_body['code']) self.usr_id = resp_body['data']['id'] print('✓ user created -> {}'.format(self.usr_id)) resp_body = self.user.delete_user_without_auth(self.usr_id).json() Poc_Asserts.check_status_code( 401, resp_body['code']) #checking the supposed real code Poc_Asserts.check_response_contains_values_from_dict( {'message': 'Authentication failed'}, resp_body['data']) print('✓ user {} not deleted [Unauthorized]'.format(self.usr_id))
def test_search_user_with_filters(self): """Checking filters getting users""" body = UserPayloads.new_user('MyFilteredUser', 'Male') resp = self.user.create_user(body).json() Poc_Asserts.check_status_code(201, resp['code']) self.usr_id = resp['data']['id'] body = resp['data'] print('✓ user created -> {}'.format(self.usr_id)) for filter_field in ['name', 'email']: filters = {filter_field: body[filter_field]} resp_body = self.user.get_users_with_filters(filters).json() Poc_Asserts.check_list_contains_dict(body, resp_body['data']) print('✓ got user {} filtering by {} -> {}'.format( self.usr_id, filter_field, body[filter_field]))
def test_create_user_successfully(self): """Check to verify if the creation of users is correct -> happy path""" body = UserPayloads.new_user('MyBestUser', 'Male') resp = self.user.create_user(body) Poc_Asserts.check_status_code(200, resp.status_code) resp_body = resp.json() Poc_Asserts.check_response_contains_values_from_dict( body, resp_body['data']) self.usr_id = resp_body['data']['id'] print('✓ user created -> {}'.format(self.usr_id)) resp = self.user.get_user_by_id(self.usr_id) Poc_Asserts.check_status_code(200, resp.status_code) resp_body = resp.json() Poc_Asserts.check_response_contains_values_from_dict( body, resp_body['data']) print('✓ got user -> {}'.format(self.usr_id))
def test_create_user_without_required_params(self): """Checking the required parameters are actually needed""" params = UserPayloads.attrs() # one by one for elem in params: self.checking_new_user_removing_X_param(elem) # all in one shoot empty_payload = {} body = self.user.create_user(empty_payload).json() Poc_Asserts.check_status_code( 422, body['code']) #checking the supposed real code for elem in params: Poc_Asserts.check_list_contains_dict( { 'field': elem, 'message': "can't be blank" }, body['data']) print('✓ all params checked [Unprocessable Entity]')
def test_create_user_with_existing_email(self): """checking email uniqueless""" body = UserPayloads.new_user('MyRepeatedUser', 'Male') resp = self.user.create_user(body).json() Poc_Asserts.check_status_code(201, resp['code']) self.usr_id = resp['data']['id'] print('✓ user created once -> {}'.format(self.usr_id)) # repeating the request resp = self.user.create_user(body).json() Poc_Asserts.check_status_code( 422, resp['code']) #checking the supposed real code Poc_Asserts.check_list_contains_dict( { 'field': 'email', 'message': "has already been taken" }, resp['data']) print('✓ user not created with same email `{}` [Unprocessable Entity]'. format(body['email']))
def test_create_user_without_required_enum(self): """Checking the restricted parameters are actually being respected""" dic = { 'status': 'can be Active or Inactive', 'gender': 'can be Male or Female' } for field, err_msg in dic.items(): payload = UserPayloads.new_user('Invalid', 'Male') payload[field] = 'invalidValue' body = self.user.create_user(payload).json() Poc_Asserts.check_status_code( 422, body['code']) #checking the supposed real code Poc_Asserts.check_list_contains_dict( { 'field': field, 'message': err_msg }, body['data']) print('✓ user not created with invalid {} [Unprocessable Entity]'. format(field))