-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
99 lines (85 loc) · 2.83 KB
/
test_api.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Unit Tests.
https://pythonhosted.org/Flask-Testing/
"""
import os
from unittest.mock import patch
import werkzeug.test
from flask import Flask
from flask.testing import FlaskClient
from flask_testing import TestCase
import app
from app import db
from tests.mocks.cache import RedisMock
class ApiClientTest(TestCase):
"""
Testing API Client.
"""
@patch.object(app, "cache", RedisMock())
def create_app(self) -> Flask:
"""
Flask application factory.
"""
os.environ["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
os.environ["SECRET_KEY"] = "mock"
os.environ["REDIS_HOST"] = "0.0.0.0"
os.environ["REDIS_PORT"] = "6379"
os.environ["REDIS_DB"] = "0"
os.environ["TESTING"] = "true"
os.environ["DEBUG"] = "true"
return app.create_app()
def setUp(self) -> None:
"""
Running before tests.
"""
db.create_all()
def test_index(self) -> None:
"""
Testing GET /
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.get("/")
self.assertEquals(response.status_code, 404)
def test_companies(self) -> None:
"""
Testing GET /company/gb
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.get("/company/gb")
self.assertEquals(response.status_code, 308)
response = client.get("/company/gb/")
self.assertEquals(response.status_code, 200)
def test_companies_reports_get(self) -> None:
"""
Testing GET /company/gb/<id>
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.get("/company/gb/123")
self.assertEquals(response.status_code, 200)
def test_companies_reports_delete(self) -> None:
"""
Testing DELETE /company/gb/<id>
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.delete("/company/gb/123")
self.assertEquals(response.status_code, 200)
def test_companies_reports_put(self) -> None:
"""
Testing PUT /company/gb/<id>
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.put("/company/gb/123")
self.assertEquals(response.status_code, 200)
def test_companies_reports_post(self) -> None:
"""
Testing POST /company/gb/<id>
"""
client: FlaskClient = self.app.test_client()
response: werkzeug.test.TestResponse = client.post("/company/gb/123")
self.assertEquals(response.status_code, 405)
def tearDown(self) -> None:
"""
Running after tests.
"""
db.session.remove()
db.drop_all()