This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_acls.py
149 lines (117 loc) · 4.24 KB
/
test_acls.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""Tests for the objectrocket.acls module."""
import responses
from objectrocket.acls import Acl
####################################
# Tests for Acls public interface. #
####################################
# Tests for all. #
@responses.activate
def test_all_makes_expected_api_request(client):
instance_name = 'test_instance'
expected_url = 'http://localhost:5050/v2/instances/{}/acls/'.format(instance_name)
responses.add(
responses.GET,
expected_url,
status=200,
json={'data': []},
content_type="application/json",
)
output = client.acls.all(instance_name)
assert output == []
@responses.activate
def test_all_concretizes_returned_acl_doc(client, acl_doc):
instance_name = 'test_instance'
expected_acl_object = Acl(acl_doc, client.acls)
expected_url = 'http://localhost:5050/v2/instances/{}/acls/'.format(instance_name)
responses.add(
responses.GET,
expected_url,
status=200,
json={'data': [acl_doc]},
content_type="application/json",
)
output = client.acls.all(instance_name)
assert len(output) == 1
assert output[0].id == expected_acl_object.id
assert isinstance(output[0], Acl)
# Tests for create. #
@responses.activate
def test_create_makes_expected_api_request(client, acl_doc):
cidr_mask = '0.0.0.0/1'
description = 'testing'
instance_name = 'test_instance'
expected_acl_object = Acl(acl_doc, client.acls)
expected_url = 'http://localhost:5050/v2/instances/{}/acls/'.format(instance_name)
responses.add(
responses.POST,
expected_url,
status=200,
json={'data': acl_doc},
content_type="application/json",
)
output = client.acls.create(instance_name, cidr_mask, description)
assert output.id == expected_acl_object.id
assert isinstance(output, Acl)
# Tests for get. #
@responses.activate
def test_get_makes_expected_api_request(client, acl_doc):
instance_name = 'test_instance'
expected_acl_object = Acl(acl_doc, client.acls)
expected_url = 'http://localhost:5050/v2/instances/{}/acls/{}/'.format(
instance_name,
expected_acl_object.id
)
responses.add(
responses.GET,
expected_url,
status=200,
json={'data': acl_doc},
content_type="application/json",
)
output = client.acls.get(instance_name, expected_acl_object.id)
assert output.id == expected_acl_object.id
assert isinstance(output, Acl)
# Tests for delete. #
@responses.activate
def test_delete_makes_expected_api_request(client, acl):
instance_name = 'test_instance'
expected_url = 'http://localhost:5050/v2/instances/{}/acls/{}/'.format(
instance_name,
acl.id
)
responses.add(
responses.DELETE,
expected_url,
status=200,
json={'data': {}},
content_type="application/json",
)
client.acls.delete(instance_name, acl.id)
#####################################
# Tests for Acls private interface. #
#####################################
# Tests for _concrete_acl. #
def test_concrete_acl_returns_none_if_dict_not_given(client):
output = client.acls._concrete_acl([])
assert output is None
def test_concrete_acl_returns_none_if_doc_is_missing_needed_field(acl_doc, client):
acl_doc.pop('cidr_mask') # Will cause a constructor error.
output = client.acls._concrete_acl(acl_doc)
assert output is None
def test_concrete_acl_returns_expected_acl_object(acl_doc, client):
output = client.acls._concrete_acl(acl_doc)
assert isinstance(output, Acl)
assert output._document is acl_doc
# Tests for _concrete_acl_list. #
def test_concrete_acl_list_returns_empty_list_if_empty_list_provided(client):
output = client.acls._concrete_acl_list([])
assert output == []
def test_concrete_acl_list_returns_empty_list_if_constructor_error_for_doc(acl_doc, client):
acl_doc.pop('cidr_mask') # Will cause a constructor error.
output = client.acls._concrete_acl_list([acl_doc])
assert output == []
def test_concrete_acl_list_returns_expected_list(acl_doc, client):
output = client.acls._concrete_acl_list([acl_doc])
assert isinstance(output, list)
assert len(output) == 1
assert output[0]._document is acl_doc