-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_auth.py
More file actions
54 lines (43 loc) · 2.42 KB
/
test_auth.py
File metadata and controls
54 lines (43 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
from agrirouter.api.enums import ResponseTypes
from agrirouter.api.environments import BaseEnvironment
from agrirouter.auth.auth import Authorization
from agrirouter.auth.parameters import AuthUrlParameter
class MockEnvironment(BaseEnvironment):
def get_secured_onboarding_authorization_url(self, **kwargs):
return 'https://secured.url'
def get_env_public_key(self):
return 'public_key_env'
class TestAuthorization(unittest.TestCase):
def test_authorization_initialization(self):
authorization = Authorization(MockEnvironment(), 'public_key', 'private_key')
assert authorization._public_key == 'public_key'
assert authorization._private_key == 'private_key'
def test_get_auth_request_url(self):
authorization = Authorization(MockEnvironment(), 'public_key', 'private_key')
parameters = AuthUrlParameter(application_id='app_id', response_type=ResponseTypes.ONBOARD.value,
state='state',
redirect_uri='redirect_uri')
auth_url = authorization.get_auth_request_url(parameters=parameters)
assert auth_url == 'https://secured.url'
def test_extract_auth_response(self):
authorization = Authorization(MockEnvironment(), 'public_key', 'private_key')
auth_response = authorization.extract_auth_response(
'https://example.com/?state=state&token=token&signature=signature')
assert auth_response.state == 'state'
assert auth_response.token == 'token'
assert auth_response.signature == 'signature'
assert auth_response.error is None
def test_extract_auth_response_and_error(self):
authorization = Authorization(MockEnvironment(), 'public_key', 'private_key')
auth_response = authorization.extract_auth_response(
'https://example.com/?state=state&token=token&signature=signature&error=error')
assert auth_response.state == 'state'
assert auth_response.token == 'token'
assert auth_response.signature == 'signature'
assert auth_response.error == 'error'
def test_extract_query_params(self):
query_str = "param1=value1¶m2=value2¶m3=value3"
extracted_params = Authorization._extract_query_params(query_str)
expected_params = {'param1': 'value1', 'param2': 'value2', 'param3': 'value3'}
assert extracted_params == expected_params