Example #1
0
    def test_negative_create_bear_ages(self, api_bear, bear_age: int or float) -> None:
        json = copy.copy(Bears.SIMPLE_BEAR_JSON)
        json.update({'bear_age': bear_age})

        resp_post = api_bear.post_add(json=json)
        validate_response_code(resp_post, HTTPCodes.OK, should_be_equal=False)
        validate_response_code(resp_post, HTTPCodes.BAD_REQUEST)
Example #2
0
    def test_negative_use_incorrect_header(self, api_bear, header: str) -> None:
        api_bear.delete_all()
        resp_post = api_bear.post_add(headers={"Content-type": header}, json=Bears.SIMPLE_BEAR_JSON)

        assert resp_post.text != 1, "record unexpectedly created"
        validate_response_code(resp_post, HTTPCodes.OK, should_be_equal=False)
        validate_response_code(resp_post, HTTPCodes.BAD_REQUEST)
Example #3
0
    def test_negative_update_specific_bear_age(self, api_bear, create_simple_bear, bear_age) -> None:
        bear_id, json_expected = create_simple_bear

        resp_put = api_bear.put_one(bear_id=bear_id, json={'bear_age': bear_age})

        assert json_expected == api_bear.get_one(bear_id=bear_id).json(), \
            "Result dictionary doesn't match with expected"
        validate_response_code(resp_put, HTTPCodes.OK, should_be_equal=False)
        validate_response_code(resp_put, HTTPCodes.BAD_REQUEST)
Example #4
0
    def test_positive_delete_one_bear(self, api_bear) -> None:
        # create bear
        json_expected = copy.copy(Bears.SIMPLE_BEAR_JSON)
        bear_id = api_bear.post_add(json=json_expected).json()

        # delete bear
        resp_delete = api_bear.delete_one(bear_id=bear_id)
        validate_response_code(resp_delete, HTTPCodes.OK)
        resp_get = api_bear.get_one(bear_id=bear_id)
        assert resp_get.text == Bears.GET_ALL_EMPTY_RESPONSE, 'TEXT: {}'.format(resp_get.text)
Example #5
0
    def test_negative_create_bear_user_ids(self, api_bear) -> None:
        bear_id = bear_id_negative
        json = copy.copy(Bears.SIMPLE_BEAR_JSON)
        json.update({'bear_id': bear_id})

        resp_post = api_bear.post_add(json=json)
        validate_response_code(resp_post, HTTPCodes.OK, should_be_equal=False)
        validate_response_code(resp_post, HTTPCodes.BAD_REQUEST)
        resp_get = api_bear.get_one(bear_id=bear_id)
        assert resp_get.text == Bears.GET_ALL_EMPTY_RESPONSE, 'TEXT: {}'.format(resp_get.text)
Example #6
0
    def test_positive_update_specific_bear_all(self, api_bear, create_simple_bear, bear_type: str, bear_name: str,
                                               bear_age: int or float) -> None:
        bear_id, json_expected = create_simple_bear

        json_expected.update({'bear_type': bear_type, 'bear_name': bear_name.upper(), 'bear_age': float(bear_age)})
        update = {'bear_type': bear_type, 'bear_name': bear_name, 'bear_age': bear_age}
        resp_put = api_bear.put_one(bear_id=bear_id, json=update)

        validate_response_code(resp_put, HTTPCodes.OK)
        json_result = api_bear.get_one(bear_id=bear_id).json()
        assert json_result == json_expected, "Result dictionary doesn't match with expected"
Example #7
0
    def test_positive_create_get_bear(self, api_bear, bear_type: str, bear_name: str, bear_age: int or float) -> None:
        json_expected = {'bear_type': bear_type, 'bear_name': bear_name, 'bear_age': bear_age}
        resp_post = api_bear.post_add(json=json_expected)

        validate_response_code(resp_post, HTTPCodes.OK)
        json_expected.update({'bear_name': bear_name.upper(), 'bear_age': float(bear_age), 'bear_id': resp_post.json()})

        resp_get = api_bear.get_one(bear_id=resp_post.json())
        json_result = resp_get.json()
        assert json_result == json_expected, "Result dictionary doesn't match with expected"
        assert isinstance(json_result['bear_name'], str), 'Incorrect bear_name type: {}'\
            .format(type(json_result['bear_name']))
        assert isinstance(json_result['bear_age'], float), 'Incorrect bear_age type: {}'\
            .format(type(json_result['bear_age']))
        assert isinstance(json_result['bear_id'], int), 'Incorrect bear_id type: {}'\
            .format(type(json_result['bear_id']))
        assert isinstance(json_result['bear_type'], str), 'Incorrect bear_type type: {}'\
            .format(type(json_result['bear_type']))
Example #8
0
    def test_positive_get_all_delete_all_bears(self, api_bear) -> None:
        # create bears
        json_expected = copy.copy(Bears.SIMPLE_BEAR_JSON)
        for num in range(database_size):
            api_bear.post_add(json=json_expected).json()

        # check get all bears
        resp_get = api_bear.get_all()
        validate_response_code(resp_get, HTTPCodes.OK)
        assert len(resp_get.json()) == database_size, "Result Database size doesn't match with expected"

        # check delete all bears
        resp_delete = api_bear.delete_all()
        validate_response_code(resp_delete, HTTPCodes.OK)
        resp_get = api_bear.get_all()
        validate_response_code(resp_get, HTTPCodes.OK)
        assert len(resp_get.json()) == 0, "Database isn't empty"
Example #9
0
def smoke_check(api_bear):
    """quick smoke check that checks basic functionality without which there is no sense to check test suit"""
    json_expected = copy.copy(Bears.SIMPLE_BEAR_JSON)

    # bear create check
    resp_post = api_bear.post_add(json=json_expected)
    validate_response_code(resp_post, HTTPCodes.OK)
    json_expected.update({'bear_id': resp_post.json()})

    # bear get check
    resp_get = api_bear.get_one(bear_id=resp_post.json())
    validate_response_code(resp_get, HTTPCodes.OK)
    json_result = resp_get.json()
    assert json_result == json_expected, "Result dictionary doesn't match with expected"

    # all bears delete check
    resp_delete = api_bear.delete_all()
    validate_response_code(resp_delete, HTTPCodes.OK)
    assert not api_bear.get_all().json(), "Database is not empty"
Example #10
0
def clear(api_bear):
    """clear data base before every test"""
    resp_delete = api_bear.delete_all()
    validate_response_code(resp_delete, HTTPCodes.OK)
Example #11
0
 def test_negative_delete_one_bear(self, api_bear) -> None:
     resp_delete = api_bear.delete_one(bear_id=bear_id_negative)
     validate_response_code(resp_delete, HTTPCodes.NOT_FOUND)
Example #12
0
 def test_negative_get_bear(self, api_bear, bear_id) -> None:
     resp_post = api_bear.get_one(bear_id=bear_id)
     if isinstance(bear_id, int):
         validate_response_code(resp_post, HTTPCodes.NOT_FOUND)
     else:
         validate_response_code(resp_post, HTTPCodes.BAD_REQUEST)