Exemple #1
0
    def test_update_user_without_authorization(self):
        """Checking authorization updating users (PUT)"""

        body = UserPayloads.new_user('futureNotUpdated', 'Male')
        resp = self.user.create_user(body)
        Poc_Asserts.check_status_code(200, resp.status_code)
        self.usr_id = resp.json()['data']['id']
        print('✓ user created -> {}'.format(self.usr_id))
        new_body = UserPayloads.new_user('Updated', 'Female')
        resp = self.user.update_user_without_auth(new_body, self.usr_id)
        Poc_Asserts.check_status_code(
            200, resp.status_code)  #bad design of the fake api
        resp_body = resp.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 updated properly [Unauthorized]'.format(
            self.usr_id))
Exemple #2
0
    def test_update_user_successfully(self):
        """checking updates (PUT) of a user"""

        body = UserPayloads.new_user('futureUpdated', 'Female')
        resp = self.user.create_user(body)
        Poc_Asserts.check_status_code(200, resp.status_code)
        self.usr_id = resp.json()['data']['id']
        print('✓ user created -> {}'.format(self.usr_id))
        new_body = UserPayloads.new_user('Updated', 'Male')
        resp = self.user.update_user(new_body, self.usr_id)
        Poc_Asserts.check_status_code(200, resp.status_code)
        resp_body = resp.json()
        Poc_Asserts.check_response_contains_values_from_dict(
            new_body, resp_body['data'])
        print('✓ user updated -> {}'.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(
            new_body, resp_body['data'])
        print('✓ got updated user -> {}'.format(self.usr_id))
Exemple #3
0
    def test_create_user_without_authorization(self):
        """Check authorization for the creation of users"""

        body = UserPayloads.new_user('MyWorstUser', 'Male')
        resp = self.user.create_user_without_auth(body)
        Poc_Asserts.check_status_code(200,
                                      resp.status_code)  #bad design of the api
        resp_body = resp.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 created properly [Unauthorized]')
Exemple #4
0
 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))
Exemple #5
0
    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))
Exemple #6
0
    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]))
Exemple #7
0
    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))
Exemple #8
0
    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']))
Exemple #9
0
    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))