-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 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 |
---|---|---|
@@ -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.
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,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() |