Skip to content

Commit

Permalink
test: create a unit test skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
ustuehler committed Jun 22, 2022
1 parent 2b0595c commit 8738445
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .pythonrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python3
try:
# noinspection PyUnresolvedReferences
import amazing_marvin
except ModuleNotFoundError:
import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

# noinspection PyUnresolvedReferences
import amazing_marvin

print(f"Type \"help({amazing_marvin.__name__})\" to learn about this package.")
Empty file added tests/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions tests/test_amazing_marvin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import unittest
from datetime import date

# noinspection PyUnresolvedReferences
from amazing_marvin import AmazingMarvinAPI, API_URL


class MockResponse:
def __init__(self, content: str):
self.content = content

def raise_for_status(self) -> None:
pass


class MockSession:
headers: dict = {}

def __init__(self, path_content: dict[str, str]) -> None:
self.path_content = path_content

def get(self, path: str) -> MockResponse:
return MockResponse(self.path_content[path])


class MockRequestsModule:
def __init__(self, path_content: dict[str, str]) -> None:
self.path_content = path_content
self.Session = lambda: MockSession(self.path_content)


class TestAmazingMarvinAPI(unittest.TestCase):

def setUp(self) -> None:
today = date.today()

self.api = AmazingMarvinAPI(
api_token='ignored_by_mock_requests_module',
requests_module=MockRequestsModule({
f'{API_URL}/me': '{}',
f'{API_URL}/todayItems?date={today.isoformat()}': '[]'
})
)

def test_me(self):
self.assertIsInstance(self.api.me(), dict)

def test_today_items(self):
self.assertIsInstance(self.api.today_items(), list)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8738445

Please sign in to comment.