Skip to content

Commit

Permalink
Use tornado.testing classes for tests, which use unittest
Browse files Browse the repository at this point in the history
Rename test directories so the CI is not triggered by changes there
  • Loading branch information
meffmadd committed Jul 9, 2024
1 parent 01a119c commit a3f0fd3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 32 deletions.
1 change: 0 additions & 1 deletion testing.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ pytest
pytest-asyncio
pytest-cov
pytest-mock
pytest-tornado
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions tests/server_tests/test_key_handler.py
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()
31 changes: 0 additions & 31 deletions tests/srv/test_key_handler.py

This file was deleted.

0 comments on commit a3f0fd3

Please sign in to comment.