@@ -58,13 +58,16 @@ def test_verify_valid_predicate(self):
58
58
verifier = pretend .stub ()
59
59
caveat = V1Caveat (verifier )
60
60
d = datetime .now () + timedelta (days = 1 )
61
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
61
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
62
62
tz_aware = tz .localize (d )
63
63
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
64
- predicate = {"permissions" : {"scope" : "user" , "expiration" : expiration }, "version" : 1 }
64
+ predicate = {
65
+ "permissions" : {"scope" : "user" , "expiration" : expiration },
66
+ "version" : 1 ,
67
+ }
65
68
66
69
assert caveat (json .dumps (predicate )) is True
67
-
70
+
68
71
def test_verify_user_invalid_predicate (self ):
69
72
verifier = pretend .stub ()
70
73
caveat = V1Caveat (verifier )
@@ -77,8 +80,10 @@ def test_verify_project_invalid_context(self):
77
80
verifier = pretend .stub (context = pretend .stub ())
78
81
caveat = V1Caveat (verifier )
79
82
80
- predicate = {"version" : 1 , "permissions" :
81
- {"projects" : [{"project-name" : "notfoobar" }]}}
83
+ predicate = {
84
+ "version" : 1 ,
85
+ "permissions" : {"projects" : [{"project-name" : "notfoobar" }]},
86
+ }
82
87
with pytest .raises (InvalidMacaroon ):
83
88
caveat (json .dumps (predicate ))
84
89
@@ -87,8 +92,10 @@ def test_verify_project_invalid_project_name(self, db_request):
87
92
verifier = pretend .stub (context = project )
88
93
caveat = V1Caveat (verifier )
89
94
90
- predicate = {"version" : 1 , "permissions" :
91
- {"projects" : [{"project-name" : "notfoobar" }]}}
95
+ predicate = {
96
+ "version" : 1 ,
97
+ "permissions" : {"projects" : [{"project-name" : "notfoobar" }]},
98
+ }
92
99
with pytest .raises (InvalidMacaroon ):
93
100
caveat (json .dumps (predicate ))
94
101
@@ -110,26 +117,36 @@ def test_verify_project(self, db_request):
110
117
verifier = pretend .stub (context = project )
111
118
caveat = V1Caveat (verifier )
112
119
d = datetime .now () + timedelta (days = 1 )
113
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
120
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
114
121
tz_aware = tz .localize (d )
115
122
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
116
123
117
- predicate = {"version" : 1 , "permissions" :
118
- {"expiration" : expiration , "projects" : [{"project-name" : "foobar" , "version" : "1.0" }]}}
124
+ predicate = {
125
+ "version" : 1 ,
126
+ "permissions" : {
127
+ "expiration" : expiration ,
128
+ "projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
129
+ },
130
+ }
119
131
assert caveat (json .dumps (predicate )) is True
120
-
132
+
121
133
def test_verify_releases (self , db_request ):
122
134
project = ProjectFactory .create (name = "foobar" )
123
135
release = ReleaseFactory .create (project = project )
124
136
verifier = pretend .stub (context = project )
125
137
caveat = V1Caveat (verifier )
126
138
d = datetime .now () + timedelta (days = 1 )
127
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
139
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
128
140
tz_aware = tz .localize (d )
129
141
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
130
142
131
- predicate = {"version" : 1 , "permissions" :
132
- {"projects" : [{"project-name" : "foobar" , "version" : "1.0" }], "expiration" : expiration }}
143
+ predicate = {
144
+ "version" : 1 ,
145
+ "permissions" : {
146
+ "projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
147
+ "expiration" : expiration ,
148
+ },
149
+ }
133
150
assert caveat (json .dumps (predicate )) is True
134
151
135
152
def test_verify_release_exists (self , db_request ):
@@ -138,27 +155,38 @@ def test_verify_release_exists(self, db_request):
138
155
verifier = pretend .stub (context = project )
139
156
caveat = V1Caveat (verifier )
140
157
d = datetime .now () + timedelta (days = 1 )
141
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
158
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
142
159
tz_aware = tz .localize (d )
143
160
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
144
161
145
- predicate = {"version" : 1 , "permissions" :
146
- {"projects" : [{"project-name" : "foobar" , "version" : project .latest_version [0 ]}],
147
- "expiration" : expiration }}
162
+ predicate = {
163
+ "version" : 1 ,
164
+ "permissions" : {
165
+ "projects" : [
166
+ {"project-name" : "foobar" , "version" : project .latest_version [0 ]}
167
+ ],
168
+ "expiration" : expiration ,
169
+ },
170
+ }
148
171
with pytest .raises (InvalidMacaroon ):
149
172
caveat (json .dumps (predicate ))
150
-
173
+
151
174
def test_verify_release_missing (self , db_request ):
152
175
project = ProjectFactory .create (name = "foobar" )
153
176
verifier = pretend .stub (context = project )
154
177
caveat = V1Caveat (verifier )
155
178
d = datetime .now () + timedelta (days = 1 )
156
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
179
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
157
180
tz_aware = tz .localize (d )
158
181
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
159
182
160
- predicate = {"version" : 1 , "permissions" :
161
- {"projects" : [{"project-name" : "foobar" }], "expiration" : expiration }}
183
+ predicate = {
184
+ "version" : 1 ,
185
+ "permissions" : {
186
+ "projects" : [{"project-name" : "foobar" }],
187
+ "expiration" : expiration ,
188
+ },
189
+ }
162
190
with pytest .raises (InvalidMacaroon ):
163
191
caveat (json .dumps (predicate ))
164
192
@@ -168,24 +196,32 @@ def test_verify_invalid_expiration(self, db_request):
168
196
verifier = pretend .stub (context = project )
169
197
caveat = V1Caveat (verifier )
170
198
171
- predicate = {"version" : 1 , "permissions" :
172
- {"projects" : [{"project-name" :"foobar" , "version" : "1.0" }],
173
- "expiration" : "notanexpiration" }}
199
+ predicate = {
200
+ "version" : 1 ,
201
+ "permissions" : {
202
+ "projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
203
+ "expiration" : "notanexpiration" ,
204
+ },
205
+ }
174
206
with pytest .raises (InvalidMacaroon ):
175
207
caveat (json .dumps (predicate ))
176
-
208
+
177
209
def test_verify_expiration (self , db_request ):
178
210
project = ProjectFactory .create (name = "foobar" )
179
211
verifier = pretend .stub (context = project )
180
212
caveat = V1Caveat (verifier )
181
213
d = datetime .now () + timedelta (days = 1 )
182
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
214
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
183
215
tz_aware = tz .localize (d )
184
216
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
185
217
186
- predicate = {"version" : 1 , "permissions" :
187
- {"projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
188
- "expiration" : expiration }}
218
+ predicate = {
219
+ "version" : 1 ,
220
+ "permissions" : {
221
+ "projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
222
+ "expiration" : expiration ,
223
+ },
224
+ }
189
225
assert caveat (json .dumps (predicate )) is True
190
226
191
227
def test_verify_expired (self , db_request ):
@@ -194,26 +230,33 @@ def test_verify_expired(self, db_request):
194
230
verifier = pretend .stub (context = project )
195
231
caveat = V1Caveat (verifier )
196
232
d = datetime .now () - timedelta (days = 1 )
197
- tz = pytz .timezone (' GMT' ) # GMT for POC, ideally would be user's local timezone
233
+ tz = pytz .timezone (" GMT" ) # GMT for POC, ideally would be user's local timezone
198
234
tz_aware = tz .localize (d )
199
235
expiration = datetime .strftime (tz_aware , "%Y-%m-%dT%H:%M" )
200
236
201
- predicate = {"version" : 1 , "permissions" :
202
- {"projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
203
- "expiration" : expiration }}
237
+ predicate = {
238
+ "version" : 1 ,
239
+ "permissions" : {
240
+ "projects" : [{"project-name" : "foobar" , "version" : "1.0" }],
241
+ "expiration" : expiration ,
242
+ },
243
+ }
204
244
with pytest .raises (InvalidMacaroon ):
205
245
caveat (json .dumps (predicate ))
206
-
246
+
207
247
def test_verify_expiration_missing (self , db_request ):
208
248
project = ProjectFactory .create (name = "foobar" )
209
249
verifier = pretend .stub (context = project )
210
250
caveat = V1Caveat (verifier )
211
251
212
- predicate = {"version" : 1 , "permissions" :
213
- {"projects" : [{"project-name" : "foobar" , "version" : "1.0" }]}}
252
+ predicate = {
253
+ "version" : 1 ,
254
+ "permissions" : {"projects" : [{"project-name" : "foobar" , "version" : "1.0" }]},
255
+ }
214
256
with pytest .raises (InvalidMacaroon ):
215
257
caveat (json .dumps (predicate ))
216
258
259
+
217
260
class TestVerifier :
218
261
def test_creation (self ):
219
262
macaroon = pretend .stub ()
0 commit comments