Cleanup some code
NOT FINISHED!
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
|
||||
from ActiveCollabAPI.AcTokenAuthenticator import AcTokenAuthenticator
|
||||
|
||||
|
||||
class TestAcTokenAuthenticator(TestCase):
|
||||
|
||||
def mock_token_success(self):
|
||||
return {
|
||||
"is_ok": 1,
|
||||
"token": "abcdef"
|
||||
}
|
||||
|
||||
def test_issue_token_intent_success(self):
|
||||
with patch("ActiveCollabAPI.AcTokenAuthenticator.requests.post") as mock_post:
|
||||
mock_post.return_value.status_code = 200
|
||||
mock_post.return_value.json.return_value = self.mock_token_success()
|
||||
|
||||
auth = AcTokenAuthenticator("http://mock")
|
||||
res = auth.issue_token_intent("this-is-the-token-intent-string")
|
||||
|
||||
self.assertEqual(200, res.status_code)
|
||||
res_data = res.json()
|
||||
self.assertEqual(1, res_data["is_ok"])
|
||||
|
||||
def mock_token_not_ok(self):
|
||||
return {
|
||||
"is_ok": 0,
|
||||
"token": "abcdef"
|
||||
}
|
||||
|
||||
def test_issue_token_intent_not_ok(self):
|
||||
with patch("ActiveCollabAPI.AcTokenAuthenticator.requests.post") as mock_post:
|
||||
mock_post.return_value.status_code = 200
|
||||
mock_post.return_value.json.return_value = self.mock_token_not_ok()
|
||||
|
||||
auth = AcTokenAuthenticator("http://mock")
|
||||
res = auth.issue_token_intent("this-is-the-token-intent-string")
|
||||
|
||||
self.assertEqual(200, res.status_code)
|
||||
res_data = res.json()
|
||||
self.assertNotEqual(1, res_data["is_ok"])
|
||||
|
||||
def mock_token_forbidden(self):
|
||||
return {
|
||||
}
|
||||
|
||||
def test_issue_token_intent_forbidden(self):
|
||||
with patch("ActiveCollabAPI.AcTokenAuthenticator.requests.post") as mock_post:
|
||||
mock_post.return_value.status_code = 401
|
||||
mock_post.return_value.json.return_value = self.mock_token_forbidden()
|
||||
|
||||
auth = AcTokenAuthenticator("http://mock")
|
||||
res = auth.issue_token_intent("this-is-the-token-intent-string")
|
||||
|
||||
self.assertEqual(401, res.status_code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user