Exemplo n.º 1
0
class TestTokenApi(unittest.TestCase):
    @allure.step('Read Config for Data')
    def setUp(self):
        data = read_config_file()
        self.base_url = data['base_url']
        self.valid_credentials = data['valid_credentials']
        self.invalid_credentials = data['invalid_credentials']

    @allure.step('Token API With valid Credentials')
    @pytest.mark.run(order=1)
    def test_get_token_valid(self):
        self.api = ApiInterface(self.base_url)
        response = self.api.get_token(self.valid_credentials)
        assert response['status_code'] == 200
        assert response['response']['token'] is not None

    @allure.step('Token API with Invalid Credentials')
    @pytest.mark.run(order=2)
    def test_get_token_invalid(self):
        self.api = ApiInterface(self.base_url)
        response = self.api.get_token(self.invalid_credentials)
        print(response)
        self.assertEqual(response['status_code'], 401)
        self.assertEqual(response['response']['message'], 'Invalid User')

    @allure.step('Token API with NO Credentials')
    @pytest.mark.run(order=3)
    def test_get_token_no_header(self):
        self.api = ApiInterface(self.base_url)
        response = self.api.get_token()
        print(response)
        self.assertEqual(response['status_code'], 401)
        self.assertEqual(response['response']['message'], 'Invalid User')
Exemplo n.º 2
0
class TestAPIFlow(unittest.TestCase):
    @allure.step('Get User Token')
    def setUp(self):
        data = read_config_file()
        self.base_url = data['base_url']
        self.valid_credentials = data['valid_credentials']
        self.get_token()

    def get_token(self):
        self.api = ApiInterface(self.base_url)
        response = self.api.get_token(self.valid_credentials)
        self.token = response['response']['token']
        print('get_token: ', self.token)

    @allure.step('Fetch User Information')
    @pytest.mark.run(order=1)
    def test_get_user_information(self):
        self.user = self.valid_credentials[0]
        response = self.api.get_user(user=self.user, token=self.token)
        print('test_get_user_information: ', response)
        self.assertEqual(response['response']['message'],
                         'retrieval succesful')

    @allure.step('Get All Users')
    @pytest.mark.run(order=2)
    def test_get_all_users(self):
        response = self.api.get_all_users()
        print('test_get_all_users: ', response['response']['status'])
        self.assertEqual(response['response']['status'], 'SUCCESS')

    @allure.step('Update User Information')
    @pytest.mark.run(order=3)
    def test_update_user_information(self):
        self.user = self.valid_credentials[0]
        json_data = generate_fake_data()
        response = self.api.update_user(user=self.user,
                                        json=json.loads(json.dumps(json_data)),
                                        token=self.token)
        print('test_update_user_information: ', response)
        status_code = response['status_code']
        self.assertEqual(status_code, 201)

    @allure.step('Fetch Updated User Information')
    @pytest.mark.run(order=4)
    def test_get_updated_user_information(self):
        self.user = self.valid_credentials[0]
        response = self.api.get_user(user=self.user, token=self.token)
        print('test_get_updated_user_information: ', response)
        self.assertEqual(response['response']['message'],
                         'retrieval succesful')
class TestAPIFlow(unittest.TestCase):
    @allure.step('Get User Token')
    def setUp(self):
        data = read_config_file()
        self.base_url = data['base_url']
        self.valid_credentials = data['valid_credentials']
        self.get_token()

    def get_token(self):
        self.api = ApiInterface(self.base_url)
        response = self.api.get_token(self.valid_credentials)
        self.token = response['response']['token']
        print('get_token: ', self.token)

    @allure.step('Update User Information - Faker Data')
    @pytest.mark.run(order=1)
    def test_update_user_information_faker(self):
        self.user = self.valid_credentials[0]
        json_data = generate_fake_data()
        response = self.api.update_user(user=self.user,
                                        json=json.loads(json.dumps(json_data)),
                                        token=self.token)
        print('test_update_user_information: ', response)
        status_code = response['status_code']
        self.assertEqual(status_code, 201)

    @allure.step('Update User Information - Not allowed Field')
    @pytest.mark.run(order=2)
    def test_update_user_information_not_allowed_field(self):
        self.user = self.valid_credentials[0]
        json_data = {"field": "value"}
        response = self.api.update_user(user=self.user,
                                        json=json.loads(json.dumps(json_data)),
                                        token=self.token)
        print('test_update_user_information: ', response)
        status_code = response['status_code']
        message = response['message']
        self.assertEqual(status_code, 403)
        self.assertEqual(message, 'Field update not allowed')