-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35875e3
commit a3f9d4c
Showing
2 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
from api import app, configure_api_app | ||
from gazettes import GazetteAccessInterface, GazetteRequest | ||
from suggestions import SuggestionServiceInterface | ||
from suggestions import Suggestion, SuggestionServiceInterface | ||
|
||
|
||
@GazetteAccessInterface.register | ||
|
@@ -569,3 +569,94 @@ def test_city_endpoint_should_return_city_info_returned_by_gazettes_interface(se | |
} | ||
}, | ||
) | ||
|
||
|
||
class ApiSuggestionsEndpointTests(TestCase): | ||
def setUp(self): | ||
self.suggestion_service = MockSuggestionService() | ||
configure_api_app(MockGazetteAccessInterface(), self.suggestion_service) | ||
self.client = TestClient(app) | ||
|
||
def test_suggestion_endpoint_should_send_email(self): | ||
self.suggestion_service.add_suggestion = MagicMock(return_value=True) | ||
|
||
response = self.client.post( | ||
"/suggestions", | ||
json={ | ||
"email_address": "[email protected]", | ||
"name": "My Name", | ||
"content": "Suggestion content", | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == {"status": "sent"} | ||
|
||
def test_api_should_fail_when_try_to_set_any_object_as_suggestions_service_interface( | ||
self, | ||
): | ||
with self.assertRaises(Exception): | ||
configure_api_app(MockGazetteAccessInterface(), MagicMock()) | ||
|
||
def test_suggestion_endpoint_should_fail_send_email(self): | ||
self.suggestion_service.add_suggestion = MagicMock(return_value=False) | ||
|
||
response = self.client.post( | ||
"/suggestions", | ||
json={ | ||
"email_address": "[email protected]", | ||
"name": "My Name", | ||
"content": "Suggestion content", | ||
}, | ||
) | ||
assert response.status_code == 400 | ||
assert response.json() == {"status": "Problem on sent message"} | ||
|
||
def test_suggestion_endpoint_should_reject_when_email_address_is_not_present(self): | ||
response = self.client.post( | ||
"/suggestions", json={"name": "My Name", "content": "Suggestion content",}, | ||
) | ||
assert response.status_code == 422 | ||
assert response.json() == { | ||
"detail": [ | ||
{ | ||
"loc": ["body", "email_address"], | ||
"msg": "field required", | ||
"type": "value_error.missing", | ||
} | ||
] | ||
} | ||
|
||
def test_suggestion_endpoint_should_reject_when_name_is_not_present(self): | ||
response = self.client.post( | ||
"/suggestions", | ||
json={ | ||
"email_address": "[email protected]", | ||
"content": "Suggestion content", | ||
}, | ||
) | ||
assert response.status_code == 422 | ||
assert response.json() == { | ||
"detail": [ | ||
{ | ||
"loc": ["body", "name"], | ||
"msg": "field required", | ||
"type": "value_error.missing", | ||
} | ||
] | ||
} | ||
|
||
def test_suggestion_endpoint_should_reject_when_content_is_not_present(self): | ||
response = self.client.post( | ||
"/suggestions", | ||
json={"email_address": "[email protected]", "name": "My Name",}, | ||
) | ||
assert response.status_code == 422 | ||
assert response.json() == { | ||
"detail": [ | ||
{ | ||
"loc": ["body", "content"], | ||
"msg": "field required", | ||
"type": "value_error.missing", | ||
} | ||
] | ||
} |