-
Notifications
You must be signed in to change notification settings - Fork 1
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
Amazia Gur
authored and
Amazia Gur
committed
Oct 29, 2024
1 parent
29686e9
commit dbf372f
Showing
5 changed files
with
80 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
import threading | ||
|
||
from mockingbird.mockingbird import mockingbird | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def mockingbird_server(): | ||
server = mockingbird(port=8080) | ||
|
||
yield server | ||
|
||
server.shutdown() |
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 |
---|---|---|
@@ -1,17 +1,30 @@ | ||
import requests | ||
from hamcrest import assert_that, is_ | ||
from hamcrest import assert_that, is_, has_entry, equal_to | ||
|
||
from mockingbird.mockingbird import mockingbird, get | ||
from mockingbird.mockingbird import get | ||
|
||
|
||
def test_should_get_status_code(): | ||
server = mockingbird(8080).routes( | ||
get("/hello") | ||
.body({"hello": "mockingbird"}) | ||
.status(201) | ||
def test_get_default_200_status_code(mockingbird_server): | ||
mockingbird_server.routes( | ||
get("/hello").body({"message": "Hello, World!"}) | ||
) | ||
server.start() | ||
response = requests.get('http://localhost:8080/hello') | ||
assert_that(response.status_code, is_(200)) | ||
|
||
assert_that(response.status_code, is_(201)) | ||
server.shutdown() | ||
|
||
def test_get_default_application_json_header(mockingbird_server): | ||
mockingbird_server.routes( | ||
get("/hello").body({"message": "Hello, World!"}).status(200) | ||
) | ||
response = requests.get('http://localhost:8080/hello') | ||
assert_that(response.headers, has_entry("Content-Type", "application/json")) | ||
|
||
|
||
def test_get_json_response(mockingbird_server): | ||
mockingbird_server.routes( | ||
get("/hello").body({"message": "Hello, World!"}).status(200) | ||
) | ||
response = requests.get('http://localhost:8080/hello') | ||
assert_that(response.headers, has_entry("Content-Type", "application/json")) | ||
|
||
assert_that(response.json(), equal_to({"message": "Hello, World!"})) |