-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin_test.py
More file actions
54 lines (35 loc) · 1.17 KB
/
plugin_test.py
File metadata and controls
54 lines (35 loc) · 1.17 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 json
import pytest
from main import AuthorizeServicer
from proto import auth_pb2
class MockContext:
def __init__(self):
self.code = None
self.details = None
def set_code(self, code):
self.code = code
def set_details(self, details):
self.details = details
@pytest.fixture(scope="module")
def service():
return AuthorizeServicer()
@pytest.fixture
def context():
return MockContext()
@pytest.fixture
def host():
return "http://localhost:8080"
def test_authorized_user(service, context, host):
req = auth_pb2.GetRequest(user="example", host=host)
res = service.Get(req, context)
assert context.code is None, f"gRPC error: {context.details}"
actual = json.loads(res.value)
assert actual["code"] == 200
assert actual["config"]["AmazonS3"]["Key"] == "key1"
assert actual["config"]["AmazonS3"]["Secret"] == "secret1"
def test_unauthorized_user(service, context, host):
req = auth_pb2.GetRequest(user="error", host=host)
res = service.Get(req, context)
assert context.code is None or context.code.value == 0 # OK
actual = json.loads(res.value)
assert actual["code"] == 401