-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
391 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
from logging.handlers import SysLogHandler | ||
import os | ||
|
||
|
||
def initialize_papertrail(): | ||
"""Initialize papertrail logging.""" | ||
logger = logging.getLogger("first_logger") | ||
logger.setLevel(logging.DEBUG) | ||
syslog = SysLogHandler( | ||
address=(os.getenv("PAPERTRAIL_HOST"), int(os.getenv("PAPERTRAIL_PORT"))) | ||
) | ||
logger.addHandler(syslog) | ||
|
||
logger.debug("Logger setup complete.") |
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,56 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_add_4_get(auth_client): | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-4") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert b"<fieldset multiple>" in response.data | ||
|
||
|
||
def test_add_4_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-4", | ||
data={ | ||
"basics": ["Paid parking", "Free parking", "Kitchen"], | ||
"safety": ["Smoke alarm", "CO detector", "First aid kit"], | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/add-5" | ||
|
||
|
||
def test_add_4_edit_get(auth_client, mocked_posts): | ||
with patch("firebase_admin.firestore.client") as firestore: | ||
firestore.return_value.collection.return_value.document.return_value.get.return_value = MagicMock( | ||
to_dict=lambda: mocked_posts[0] | ||
) | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-4/1") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
print(response.data.decode("utf-8")) | ||
assert b'<input type="checkbox"' in response.data | ||
|
||
|
||
def test_add_4_edit_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-4/1", | ||
data={ | ||
"basics": ["Paid parking", "Free parking", "Kitchen"], | ||
"safety": ["Smoke alarm", "CO detector", "First aid kit"], | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/1" |
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,53 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_add_5_get(auth_client): | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-5") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert b"<textarea" in response.data | ||
|
||
|
||
def test_add_5_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-5", | ||
data={"desc": "This is a test description22"}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/add-6" | ||
|
||
|
||
def test_add_5_edit_get(auth_client, mocked_posts): | ||
with patch("firebase_admin.firestore.client") as firestore: | ||
firestore.return_value.collection.return_value.document.return_value.get.return_value = MagicMock( | ||
to_dict=lambda: mocked_posts[0] | ||
) | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-5/1") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
print(response.data.decode("utf-8")) | ||
assert ( | ||
b'<textarea name="desc" style="max-width: 1000px;min-width: 400px;" rows="20">This is a test description' | ||
in response.data | ||
) | ||
|
||
|
||
def test_add_5_edit_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-5/1", | ||
data={"desc": "This is a test description22"}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/1" |
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,51 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_add_6_get(auth_client): | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-6") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert b'<i class="fa fa-upload d-block p-4"' in response.data | ||
|
||
|
||
def test_add_6_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-6", | ||
data={"images": ["https://via.placeholder.com/550"]}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/add-7" | ||
|
||
|
||
def test_add_6_edit_get(auth_client, mocked_posts): | ||
with patch("firebase_admin.firestore.client") as firestore: | ||
firestore.return_value.collection.return_value.document.return_value.get.return_value = MagicMock( | ||
to_dict=lambda: mocked_posts[0] | ||
) | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-6/1") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert b'<img src="https://via.placeholder.com/150"' in response.data | ||
assert b'<img src="https://via.placeholder.com/300"' in response.data | ||
assert b'<img src="https://via.placeholder.com/450"' in response.data | ||
|
||
|
||
def test_add_6_edit_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-6/1", | ||
data={"images": ["https://via.placeholder.com/550"]}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/1" |
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,66 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_add_7_get(auth_client): | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-7") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert ( | ||
b'<input class="form-control-sm form-control w-50" name="bedrooms"' | ||
in response.data | ||
) | ||
|
||
|
||
def test_add_7_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-7", | ||
data={ | ||
"bedrooms": "1", | ||
"baths": "1", | ||
"guests": "1", | ||
"beds": "1", | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/add-8" | ||
|
||
|
||
def test_add_7_edit_get(auth_client, mocked_posts): | ||
with patch("firebase_admin.firestore.client") as firestore: | ||
firestore.return_value.collection.return_value.document.return_value.get.return_value = MagicMock( | ||
to_dict=lambda: mocked_posts[0] | ||
) | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-7/1") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
print(response.data.decode("utf-8")) | ||
assert ( | ||
b'<input class="form-control-sm form-control w-50" name="bedrooms" type="number" value="1"' | ||
in response.data | ||
) | ||
|
||
|
||
def test_add_7_edit_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-7/1", | ||
data={ | ||
"bedrooms": "1", | ||
"baths": "1", | ||
"guests": "1", | ||
"beds": "1", | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/1" |
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,69 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_add_8_get(auth_client): | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-8") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
assert b'name="price" type="number"' in response.data | ||
|
||
|
||
def test_add_8_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-8", | ||
data={ | ||
"price": "100", | ||
"month-disc": "15", | ||
"year-disc": "20", | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/9999" | ||
|
||
|
||
def test_add_8_edit_get(auth_client, mocked_posts): | ||
with patch("firebase_admin.firestore.client") as firestore: | ||
firestore.return_value.collection.return_value.document.return_value.get.return_value = MagicMock( | ||
to_dict=lambda: mocked_posts[0] | ||
) | ||
# Make a GET request to the route with parameters | ||
response = auth_client.get("/add-8/1") | ||
|
||
# Assert the response status code | ||
assert response.status_code == 200 | ||
print(response.data.decode("utf-8")) | ||
assert ( | ||
b'<input class="form-control-sm form-control w-75" value="15" name="month-disc"' | ||
in response.data | ||
) | ||
assert ( | ||
b'<input class="form-control-sm form-control w-75" value="20" name="year-disc"' | ||
in response.data | ||
) | ||
assert ( | ||
b'<input class="form-control-sm form-control w-75" value="10" name="price"' | ||
in response.data | ||
) | ||
|
||
|
||
def test_add_8_edit_post(auth_client): | ||
# Make a GET request to the route with parameters | ||
with patch("firebase_admin.firestore.client"): | ||
response = auth_client.post( | ||
"/add-8/1", | ||
data={ | ||
"price": "100", | ||
"month-disc": "15", | ||
"year-disc": "20", | ||
}, | ||
) | ||
|
||
# Assert the response status code | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == "/edit/9999" |
Oops, something went wrong.