black
This commit is contained in:
parent
5a286fa0d2
commit
325455439a
18 changed files with 261 additions and 459 deletions
|
|
@ -30,35 +30,35 @@ def client():
|
|||
|
||||
|
||||
def test_api_ping(client):
|
||||
resp = client.get('/api/ping')
|
||||
resp = client.get("/api/ping")
|
||||
assert resp.data == b"OK"
|
||||
|
||||
|
||||
def test_api_count_global(client):
|
||||
resp = client.get('/api/comments/count')
|
||||
resp = client.get("/api/comments/count")
|
||||
d = json.loads(resp.data)
|
||||
assert d and d['count'] == 2
|
||||
assert d and d["count"] == 2
|
||||
|
||||
|
||||
def test_api_count_url(client):
|
||||
resp = client.get('/api/comments/count?url=/site1')
|
||||
resp = client.get("/api/comments/count?url=/site1")
|
||||
d = json.loads(resp.data)
|
||||
assert d and d['count'] == 1
|
||||
resp = client.get('/api/comments/count?url=/site2')
|
||||
assert d and d["count"] == 1
|
||||
resp = client.get("/api/comments/count?url=/site2")
|
||||
d = json.loads(resp.data)
|
||||
assert d and d['count'] == 0
|
||||
assert d and d["count"] == 0
|
||||
|
||||
|
||||
def test_api_comment(client):
|
||||
resp = client.get('/api/comments?url=/site1')
|
||||
resp = client.get("/api/comments?url=/site1")
|
||||
d = json.loads(resp.data)
|
||||
assert d and len(d['data']) == 1
|
||||
comment = d['data'][0]
|
||||
assert comment['author'] == 'Bob'
|
||||
assert comment['content'] == 'comment 1'
|
||||
assert d and len(d["data"]) == 1
|
||||
comment = d["data"][0]
|
||||
assert comment["author"] == "Bob"
|
||||
assert comment["content"] == "comment 1"
|
||||
|
||||
|
||||
def test_api_comment_not_found(client):
|
||||
resp = client.get('/api/comments?url=/site2')
|
||||
resp = client.get("/api/comments?url=/site2")
|
||||
d = json.loads(resp.data)
|
||||
assert d and d['data'] == []
|
||||
assert d and d["data"] == []
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ EXPECTED_LANG = "fr"
|
|||
|
||||
|
||||
class ConfigTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.conf = Config()
|
||||
self.conf.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
|
||||
|
|
@ -21,7 +20,9 @@ class ConfigTestCase(unittest.TestCase):
|
|||
self.assertTrue(self.conf.exists(ConfigParameter.DB_SQLITE_FILE))
|
||||
|
||||
def test_get(self):
|
||||
self.assertEqual(self.conf.get(ConfigParameter.DB_SQLITE_FILE), EXPECTED_DB_SQLITE_FILE)
|
||||
self.assertEqual(
|
||||
self.conf.get(ConfigParameter.DB_SQLITE_FILE), EXPECTED_DB_SQLITE_FILE
|
||||
)
|
||||
self.assertEqual(self.conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
|
||||
self.assertIsNone(self.conf.get(ConfigParameter.HTTP_HOST))
|
||||
self.assertEqual(self.conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from stacosys.db import database
|
|||
|
||||
|
||||
class DbTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
database.setup(":memory:")
|
||||
|
||||
|
|
@ -50,5 +49,5 @@ class DbTestCase(unittest.TestCase):
|
|||
self.assertEqual(0, len(dao.find_not_notified_comments()))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -20,20 +20,25 @@ def client():
|
|||
|
||||
|
||||
def test_new_comment_honeypot(client):
|
||||
resp = client.post('/newcomment',
|
||||
content_type='multipart/form-data',
|
||||
data={'remarque': 'trapped'})
|
||||
assert resp.status == '400 BAD REQUEST'
|
||||
resp = client.post(
|
||||
"/newcomment", content_type="multipart/form-data", data={"remarque": "trapped"}
|
||||
)
|
||||
assert resp.status == "400 BAD REQUEST"
|
||||
|
||||
|
||||
def test_new_comment_success(client):
|
||||
resp = client.post('/newcomment',
|
||||
content_type='multipart/form-data',
|
||||
data={'author': 'Jack', 'url': '/site3', 'message': 'comment 3'})
|
||||
assert resp.status == '302 FOUND'
|
||||
resp = client.post(
|
||||
"/newcomment",
|
||||
content_type="multipart/form-data",
|
||||
data={"author": "Jack", "url": "/site3", "message": "comment 3"},
|
||||
)
|
||||
assert resp.status == "302 FOUND"
|
||||
|
||||
|
||||
def test_check_form_data():
|
||||
from stacosys.interface.form import check_form_data
|
||||
assert check_form_data({'author': 'Jack', 'url': '/site3', 'message': 'comment 3'})
|
||||
assert not check_form_data({'author': 'Jack', 'url': '/site3', 'message': 'comment 3', 'extra': 'ball'})
|
||||
|
||||
assert check_form_data({"author": "Jack", "url": "/site3", "message": "comment 3"})
|
||||
assert not check_form_data(
|
||||
{"author": "Jack", "url": "/site3", "message": "comment 3", "extra": "ball"}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,5 @@ from stacosys import __version__
|
|||
|
||||
|
||||
class StacosysTestCase(unittest.TestCase):
|
||||
|
||||
def test_version(self):
|
||||
self.assertEqual("2.0", __version__)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue