This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.py
56 lines (42 loc) · 1.8 KB
/
main_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from unittest import mock
import flask
import pytest
from google.cloud import firestore
import main
# Create a fake "app" for generating test request contexts.
@pytest.fixture(scope="module")
def app():
return flask.Flask(__name__)
@pytest.fixture(scope="function")
def firestore_client():
mock_firestore_client = mock.MagicMock(firestore.Client)
build_firestore_client_patcher = mock.patch(
"functions.smokerino.build_firestore_client",
return_value=mock_firestore_client)
build_firestore_client_patcher.start()
yield build_firestore_client_patcher
build_firestore_client_patcher.stop()
@pytest.mark.parametrize("method", ["POST", "PUT", "DELETE"])
def test_get_cigarette_returns_not_allowed_if_not_get_request(app, method):
request_mock = mock.Mock(method=method)
with app.test_request_context():
response = main.get_cigarette_request(request_mock)
assert response.status_code == 405
def test_get_cigarette_returns_bad_request_when_no_user_id(
app, firestore_client):
request_mock = mock.Mock(method="GET", args={})
with app.test_request_context():
response = main.get_cigarette_request(request_mock)
assert response.status_code == 400
@pytest.mark.parametrize("method", ["GET", "PUT", "DELETE"])
def test_add_cigarette_returns_not_allowed_if_not_post_request(app, method):
request_mock = mock.Mock(method=method)
with app.test_request_context():
response = main.add_cigarette_request(request_mock)
assert response.status_code == 405
def test_add_cigarette_returns_bad_request_when_no_user_id(
app, firestore_client):
request_mock = mock.Mock(method="POST", args={})
with app.test_request_context():
response = main.add_cigarette_request(request_mock)
assert response.status_code == 400