-
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.
Use tornado.testing classes for tests, which use unittest
Rename test directories so the CI is not triggered by changes there
- Loading branch information
Showing
5 changed files
with
48 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ pytest | |
pytest-asyncio | ||
pytest-cov | ||
pytest-mock | ||
pytest-tornado |
File renamed without changes.
File renamed without changes.
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,48 @@ | ||
import json | ||
import pathlib | ||
|
||
import pytest | ||
from tornado.testing import AsyncHTTPTestCase | ||
|
||
from srv.server import make_app | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def tmp_path_cls(request, tmp_path): | ||
request.cls.config_values = tmp_path | ||
|
||
|
||
@pytest.mark.usefixtures("tmp_path_cls") | ||
class TestKeyHandler(AsyncHTTPTestCase): | ||
config_values: pathlib.Path | ||
|
||
def get_app(self): | ||
return make_app(self.config_values) | ||
|
||
def test_root(self): | ||
response = self.fetch('/') | ||
self.assertEqual(response.code, 404) | ||
|
||
def test_not_found(self): | ||
response = self.fetch('/key/not-found') | ||
self.assertEqual(response.code, 404) | ||
# self.assertEqual(response.body, 'Hello, world') | ||
|
||
def test_key(self): | ||
test_file = self.config_values / "test" | ||
test_file.write_text(json.dumps({"foo": "bar"})) | ||
|
||
response = self.fetch('/key/test') | ||
self.assertEqual(response.code, 200) | ||
self.assertEqual(response.body.decode(), json.dumps({"foo": "bar"})) | ||
|
||
test_file.unlink() | ||
|
||
def test_key_not_json(self): | ||
test_file = self.config_values / "test" | ||
test_file.write_text("something: not json") | ||
|
||
response = self.fetch('/key/test') | ||
self.assertEqual(response.code, 400) | ||
|
||
test_file.unlink() |
This file was deleted.
Oops, something went wrong.