Exemplo n.º 1
0
    def test_diff_response_body_equal(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'body': {
                'success': True,
                'count': 10
            }})

        # expected response body is not specified
        expected_resp_json = {}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertFalse(diff_content)

        # response body is the same as expected response body
        expected_resp_json = {'body': {'success': True, 'count': '10'}}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertFalse(diff_content)
Exemplo n.º 2
0
    def test_diff_response_headers_equal(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'headers': {
                'abc': 123,
                'def': 456
            }})

        expected_resp_json = {'headers': {'abc': 123, 'def': '456'}}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertFalse(diff_content)
Exemplo n.º 3
0
    def test_diff_response_status_code_equal(self):
        status_code = random.randint(200, 511)
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={
                'status_code': status_code,
            })

        expected_resp_json = {'status_code': status_code}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertFalse(diff_content)
Exemplo n.º 4
0
    def test_diff_response_body_not_equal_string_unmatch(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'body': "success"})

        # response body content type matched to be string, while value unmatch
        expected_resp_json = {'body': "ok"}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertEqual(diff_content['body'], {
            'value': 'success',
            'expected': 'ok'
        })
Exemplo n.º 5
0
    def run_single_testcase(self, testcase):
        req_kwargs = testcase['request']

        try:
            url = req_kwargs.pop('url')
            method = req_kwargs.pop('method')
        except KeyError:
            raise exception.ParamsError("URL or METHOD missed!")

        resp_obj = self.client.request(url=url, method=method, **req_kwargs)
        diff_content = utils.diff_response(resp_obj, testcase['response'])
        success = False if diff_content else True
        return success, diff_content
Exemplo n.º 6
0
    def test_diff_response_status_code_not_equal(self):
        status_code = random.randint(200, 511)
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={
                'status_code': status_code,
            })

        expected_resp_json = {'status_code': 512}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertIn('value', diff_content['status_code'])
        self.assertIn('expected', diff_content['status_code'])
        self.assertEqual(diff_content['status_code']['value'], status_code)
        self.assertEqual(diff_content['status_code']['expected'], 512)
Exemplo n.º 7
0
    def test_diff_response_body_not_equal_type_unmatch(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'body': {
                'success': True,
                'count': 10
            }})

        # response body content type not match
        expected_resp_json = {'body': "ok"}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertEqual(diff_content['body'], {
            'value': {
                'success': True,
                'count': 10
            },
            'expected': 'ok'
        })
Exemplo n.º 8
0
    def test_diff_response_body_not_equal_json_unmatch(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'body': {
                'success': False
            }})

        # response body is the same as expected response body
        expected_resp_json = {'body': {'success': True, 'count': 10}}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertEqual(
            diff_content['body'], {
                'success': {
                    'value': False,
                    'expected': True
                },
                'count': {
                    'value': None,
                    'expected': 10
                }
            })
Exemplo n.º 9
0
    def test_diff_response_headers_not_equal(self):
        resp_obj = requests.post(
            url="http://127.0.0.1:5000/customize-response",
            json={'headers': {
                'a': 123,
                'b': '456',
                'c': '789'
            }})

        expected_resp_json = {'headers': {'a': '123', 'b': '457', 'd': 890}}
        diff_content = utils.diff_response(resp_obj, expected_resp_json)
        self.assertEqual(
            diff_content['headers'], {
                'b': {
                    'expected': '457',
                    'value': '456'
                },
                'd': {
                    'expected': 890,
                    'value': None
                }
            })