-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial set up + test for login (#72)
Co-authored-by: Rob Beal <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5812940
commit c7a5eeb
Showing
6 changed files
with
77 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,3 +1,5 @@ | ||
.env | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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 @@ | ||
3.12 |
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
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,3 +1,5 @@ | ||
pytz | ||
requests | ||
paho-mqtt | ||
pytest | ||
python-dotenv |
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,45 @@ | ||
import unittest | ||
from dotenv import load_dotenv | ||
import os | ||
import pytz | ||
from yoto_api.YotoAPI import YotoAPI | ||
from datetime import datetime | ||
|
||
|
||
class ValidLogin(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
load_dotenv() | ||
username = os.getenv("USERNAME") | ||
password = os.getenv("PASSWORD") | ||
api = YotoAPI() | ||
cls.token = api.login(username, password) | ||
|
||
def test_access_token(self): | ||
self.assertIsNotNone(self.token.access_token) | ||
|
||
def test_refresh_token(self): | ||
self.assertIsNotNone(self.token.refresh_token) | ||
|
||
def test_token_type(self): | ||
self.assertIsNotNone(self.token.token_type) | ||
|
||
def test_scope(self): | ||
self.assertIsNotNone(self.token.scope) | ||
|
||
def test_valid_until_is_greater_than_now(self): | ||
self.assertGreater(self.token.valid_until, datetime.now(pytz.utc)) | ||
|
||
|
||
class InvalidLogin(unittest.TestCase): | ||
def test_it_throws_an_error(self): | ||
api = YotoAPI() | ||
|
||
with self.assertRaises(Exception) as error: | ||
api.login("invalid", "invalid") | ||
|
||
self.assertEqual(str(error.exception), "Wrong email or password.") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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