def test_get_not_ok(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='[{"error": "deu merda"}]', content_type="application/json", status=500) response = ApiClient().get('/service1/') assert not response.ok
def test_get_not_ok_not_json(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='error: "deu merda"', content_type="text/html", status=500) response = ApiClient().get('/service1/') assert not response.ok
def test_delete_not_ok(self): httpretty.register_uri(httpretty.DELETE, "http://localhost:8000/service1/", body='[{"error": "name required"}]', content_type="application/json", status=500) response = ApiClient().delete('/service1/') assert not response.ok
def test_delete_ok(self): httpretty.register_uri(httpretty.DELETE, "http://localhost:8000/service1/", body='{"success": true}', content_type='text/json', status=200) response = ApiClient().delete('/service1/') assert response.ok
def test_get_all_not_ok(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='{"error": "deu merda"}', content_type="application/json", status=500) with pytest.raises(HTTPException): response = ApiClient().get_all('/service1/', limit=2)
def test_get_ok(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='[{"id": "1"}]', content_type="application/json", status=200) response = ApiClient().get('/service1/') assert response.ok assert response.data is not None
def test_full_url_path(self): httpretty.register_uri(httpretty.GET, "http://localhost:9999/service_full/", body='[{"id": "1"}]', content_type="application/json", status=200) response = ApiClient().get('http://localhost:9999/service_full/') assert response.ok assert response.data is not None
def test_put_not_ok(self): httpretty.register_uri(httpretty.PUT, "http://localhost:8000/service1/", body='[{"error": "name required"}]', content_type="application/json", status=500) response = ApiClient().put('/service1/', { "id": "1", "url": "www.americanas.com.br" }) assert not response.ok
def test_post_ok(self): httpretty.register_uri(httpretty.POST, "http://localhost:8000/service1/", body='{"success": true}', content_type='text/json', status=201) response = ApiClient().post('/service1/', { "name": "americanas", "url": "www.americanas.com.br" }) assert response.ok
def test_post_not_ok(self): httpretty.register_uri(httpretty.POST, "http://localhost:8000/service1/", body='[{"error": "name required"}]', content_type='text/json', status=500) response = ApiClient().post('/service1/', { "name": "americanas", "url": "www.americanas.com.br" }) assert not response.ok
def test_get_all_not_ok_second_page(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='{"error": "deu merda"}', content_type="application/json", status=500) httpretty.register_uri( httpretty.GET, "http://localhost:8000/service1/", body='{"objects": [{"id": "1"}, {"id": "2"}], "total": 3}', content_type="application/json", status=200) response = ApiClient().get_all('/service1/', limit=2) assert len(response) == 3 with pytest.raises(HTTPException): response_list = list(response)
def test_get_all_ok(self): httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/", body='{"objects": [{"id": "3"}], "total": 3}', content_type="application/json", status=200) httpretty.register_uri( httpretty.GET, "http://localhost:8000/service1/", body='{"objects": [{"id": "1"}, {"id": "2"}], "total": 3}', content_type="application/json", status=200) response = ApiClient().get_all('/service1/', limit=2) response_list = list(response) assert len(response) == 3 assert len(response_list) == 3 assert response_list[0]['id'] == '1' assert response_list[1]['id'] == '2' assert response_list[2]['id'] == '3'