Exemplo n.º 1
0
 def test_retrieve_requests_with_param(self, mocked):
     mocked.return_value = self._mock_response()
     request = Request('/hello', 'POST')
     requests = self.client.retrieve_requests(request)
     mocked.assert_called_with('{}/retrieve'.format(self.base_url),
                               params={'type': 'requests'},
                               data=request.json())
     self.assertEqual([], requests)
Exemplo n.º 2
0
 def test_verify_ok_with_times(self, mocked):
     mocked.return_value.status_code = 202
     request = Request('/hello', 'POST')
     times = VerificationTimes(2, False)
     verified = self.client.verify(request, times)
     data = {
         'httpRequest': request.dict(),
         'times': {
             'count': 2,
             'exact': False
         }
     }
     mocked.assert_called_with('{}/verify'.format(self.base_url),
                               headers=self.header,
                               data=json.dumps(data))
Exemplo n.º 3
0
 def test_verify_error(self, mocked):
     mocked.return_value.status_code = 400
     mocked.return_value.content = b'hello'
     request = Request('/hello', 'POST')
     verified = self.client.verify(request)
     self.assertEqual('ERROR', verified['status'])
     self.assertEqual('hello', verified['reason'])
Exemplo n.º 4
0
 def test_verify_ok(self, mocked):
     mocked.return_value.status_code = 202
     request = Request('/hello', 'POST')
     verified = self.client.verify(request)
     data = {
         'httpRequest': request.dict(),
         'times': {
             'count': 1,
             'exact': True
         }
     }
     mocked.assert_called_with('{}/verify'.format(self.base_url),
                               headers=self.header,
                               data=json.dumps(data))
     self.assertTrue(verified['found'])
     self.assertEqual('OK', verified['status'])
Exemplo n.º 5
0
 def test_verify_not_found(self, mocked):
     mocked.return_value.status_code = 406
     mocked.return_value.content = b'hello'
     request = Request('/hello', 'POST')
     verified = self.client.verify(request)
     self.assertFalse(verified['found'])
     self.assertEqual('OK', verified['status'])
     self.assertEqual('hello', verified['reason'])
Exemplo n.º 6
0
 def test_reset(self):
     self.client.expectation(self.request, self.response)
     new_req = Request('/world', 'GET')
     self.client.expectation(new_req, self.response)
     resp_hello = requests.get('{}/hello'.format(self.mock_url))
     resp_world = requests.get('{}/world'.format(self.mock_url))
     self.assertEqual(200, resp_hello.status_code)
     self.assertEqual(200, resp_world.status_code)
     # delete all  endpoint
     self.client.reset()
     verified = self.client.verify(self.request)
     self.assertFalse(verified['found'])
     verified = self.client.verify(new_req)
     self.assertFalse(verified['found'])
Exemplo n.º 7
0
    def test_expectation_no_times(self, mocked_put):
        request = Request('/hello', 'POST')
        response = Response(200, 'world')
        self.client.expectation(request, response)

        data = {
            'httpRequest': {
                'path': '/hello',
                'method': 'POST'
            },
            'httpResponse': {
                'statusCode': 200,
                'body': 'world'
            },
            'times': {
                'remainingTimes': 1,
                'unlimited': True
            }
        }
        mocked_put.assert_called_with('{}/expectation'.format(self.base_url),
                                      json.dumps(data))
Exemplo n.º 8
0
    def test_forward_no_times(self, mocked_put):
        request = Request('/hello', 'POST')
        response = Forward('1.2.3.4', 8080)
        self.client.forward(request, response)

        data = {
            'httpRequest': {
                'path': '/hello',
                'method': 'POST'
            },
            'httpForward': {
                'host': '1.2.3.4',
                'port': 8080,
                'scheme': 'HTTP'
            },
            'times': {
                'remainingTimes': 1,
                'unlimited': True
            }
        }
        mocked_put.assert_called_with('{}/expectation'.format(self.base_url),
                                      json.dumps(data))
Exemplo n.º 9
0
 def setUpClass(cls):
     cls.client = Client('localhost', 1080)
     cls.request = Request(path='/hello', method='GET')
     cls.response = Response(status_code=200, body='world')
     cls.mock_url = 'http://localhost:1080'
Exemplo n.º 10
0
 def test_clear(self, mocked):
     request = Request('/hello', 'POST')
     self.client.clear(request)
     mocked.assert_called_with('{}/clear'.format(self.base_url),
                               data=request.json())