def test_client_post(self): endpoint = 'http://dummy/' client = Client(endpoint) with patch_requests('http://dummy/', Results()): resp = client.analyse('hello') assert isinstance(resp, Results) with patch_requests('http://dummy/', Error('Nothing'), method='POST'): try: client.analyse(input='hello', method='POST', algorithm='NONEXISTENT') raise Exception('Exceptions should be raised. This is not golang') except Error: pass
def test_client(self): endpoint = 'http://dummy/' client = Client(endpoint) with patch_requests('http://dummy/', Results()): resp = client.analyse('hello') assert isinstance(resp, Results) with patch_requests('http://dummy/', Error('Nothing')): try: client.analyse(input='hello', algorithm='NONEXISTENT') raise Exception( 'Exceptions should be raised. This is not golang') except Error: pass
def test_client(self): endpoint = 'http://dummy/' client = Client(endpoint) with patch_requests(Results()) as (request, response): resp = client.analyse('hello') assert isinstance(resp, Results) request.assert_called_with( url=endpoint + '/', method='GET', params={'input': 'hello'}) with patch_requests(Error('Nothing')) as (request, response): try: client.analyse(input='hello', algorithm='NONEXISTENT') raise Exception('Exceptions should be raised. This is not golang') except Error: pass request.assert_called_with( url=endpoint + '/', method='GET', params={'input': 'hello', 'algorithm': 'NONEXISTENT'})
def test_client(self): endpoint = 'http://dummy/' client = Client(endpoint) success = Call(Results()) with patch('requests.request', return_value=success) as patched: resp = client.analyse('hello') assert isinstance(resp, Results) patched.assert_called_with( url=endpoint + '/', method='GET', params={'input': 'hello'}) error = Call(Error('Nothing')) with patch('requests.request', return_value=error) as patched: try: client.analyse(input='hello', algorithm='NONEXISTENT') raise Exception('Exceptions should be raised. This is not golang') except Error: pass patched.assert_called_with( url=endpoint + '/', method='GET', params={'input': 'hello', 'algorithm': 'NONEXISTENT'})