-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_auth.py
83 lines (67 loc) · 2.39 KB
/
test_auth.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import pytest
import argparse
from shelly_ota.auth import AuthProvider
from shelly_ota.shelly import ShellyDevice
@pytest.fixture
def empty_args():
parser = argparse.ArgumentParser()
parser.add_argument('--auth_env')
parser.add_argument('--auth_file')
args = parser.parse_args()
return args
@pytest.fixture
def simple_args():
parser = argparse.ArgumentParser()
parser.add_argument('--auth_env', default=None)
parser.add_argument('--auth_file', default=None)
os.environ["TEST_AUTH"] = "user:pass"
args = parser.parse_args(args=["--auth_env", "TEST_AUTH"])
return args
@pytest.fixture
def multi_args():
parser = argparse.ArgumentParser()
parser.add_argument('--auth_env', default=None)
parser.add_argument('--auth_file', default=None)
os.environ["TEST_AUTH"] = "user:pass"
args = parser.parse_args(args=["--auth_file", "auth_file.sample"])
return args
@pytest.fixture
def no_auth_provider(empty_args):
return AuthProvider(empty_args)
@pytest.fixture
def simple_auth_provider(simple_args):
return AuthProvider(simple_args)
@pytest.fixture
def multi_auth_provider(multi_args):
return AuthProvider(multi_args)
@pytest.fixture
def dummy_device1():
return ShellyDevice(
'0.0.0.0',
{'type': 'DUMMY', 'mac': '00:00:00:00:00:00'}
)
@pytest.fixture
def dummy_device2():
return ShellyDevice(
'1.1.1.1',
{'type': 'DUMMY', 'mac': '01:01:01:01:01:01'}
)
@pytest.fixture
def dummy_device3():
return ShellyDevice(
'2.2.2.2',
{'type': 'SHPLG-S', 'mac': '02:02:02:02:02:02'}
)
def test_no_auth(no_auth_provider, dummy_device1):
assert no_auth_provider is not None
assert no_auth_provider.get_auth_for(None) is None
assert no_auth_provider.get_auth_for(dummy_device1) is None
def test_simple_auth(simple_auth_provider, dummy_device1):
assert simple_auth_provider.get_auth_for(dummy_device1) == ('user', 'pass')
def test_multi_auth1(multi_auth_provider, dummy_device1):
assert multi_auth_provider.get_auth_for(dummy_device1) == ('test1_user', 'test1_pass')
def test_multi_auth2(multi_auth_provider, dummy_device2):
assert multi_auth_provider.get_auth_for(dummy_device2) == ('test2_user', 'test2_pass')
def test_multi_auth3(multi_auth_provider, dummy_device3):
assert multi_auth_provider.get_auth_for(dummy_device3) == ('test3_user', 'test3_pass')