@@ -48,29 +48,53 @@ def setUp(self):
48
48
}
49
49
)
50
50
51
+ self .site_domain2 = 'testsite2.com'
52
+ self .site2 = self .set_up_site (
53
+ self .site_domain2 ,
54
+ {
55
+ 'COURSE_CATALOG_API_URL' : self .catalog_integration .get_internal_api_url ().rstrip ('/' )
56
+ }
57
+ )
58
+
51
59
self .list_url = self .catalog_integration .get_internal_api_url ().rstrip ('/' ) + '/programs/'
52
60
self .detail_tpl = self .list_url .rstrip ('/' ) + '/{uuid}/'
53
61
self .pathway_url = self .catalog_integration .get_internal_api_url ().rstrip ('/' ) + '/pathways/'
54
62
55
63
self .programs = ProgramFactory .create_batch (3 )
64
+ self .programs2 = ProgramFactory .create_batch (3 )
56
65
self .pathways = PathwayFactory .create_batch (3 )
66
+ self .pathways2 = PathwayFactory .create_batch (3 )
57
67
self .child_program = ProgramFactory .create ()
68
+ self .child_program2 = ProgramFactory .create ()
58
69
59
70
self .programs [0 ]['curricula' ][0 ]['programs' ].append (self .child_program )
60
71
self .programs .append (self .child_program )
61
-
62
72
self .programs [0 ]['authoring_organizations' ] = OrganizationFactory .create_batch (2 )
63
73
74
+ self .programs2 [0 ]['curricula' ][0 ]['programs' ].append (self .child_program2 )
75
+ self .programs2 .append (self .child_program2 )
76
+ self .programs2 [0 ]['authoring_organizations' ] = OrganizationFactory .create_batch (2 )
77
+
64
78
for pathway in self .pathways :
65
79
self .programs += pathway ['programs' ]
66
80
67
- self .uuids = [program ['uuid' ] for program in self .programs ]
81
+ for pathway in self .pathways2 :
82
+ self .programs2 += pathway ['programs' ]
83
+
84
+ self .uuids = {
85
+ f"{ self .site_domain } " : [program ["uuid" ] for program in self .programs ],
86
+ f"{ self .site_domain2 } " : [program ["uuid" ] for program in self .programs2 ],
87
+ }
68
88
69
89
# add some of the previously created programs to some pathways
70
90
self .pathways [0 ]['programs' ].extend ([self .programs [0 ], self .programs [1 ]])
71
91
self .pathways [1 ]['programs' ].append (self .programs [0 ])
72
92
73
- def mock_list (self ):
93
+ # add some of the previously created programs to some pathways
94
+ self .pathways2 [0 ]['programs' ].extend ([self .programs2 [0 ], self .programs2 [1 ]])
95
+ self .pathways2 [1 ]['programs' ].append (self .programs2 [0 ])
96
+
97
+ def mock_list (self , site = "" ):
74
98
""" Mock the data returned by the program listing API endpoint. """
75
99
# pylint: disable=unused-argument
76
100
def list_callback (request , uri , headers ):
@@ -81,8 +105,8 @@ def list_callback(request, uri, headers):
81
105
'uuids_only' : ['1' ]
82
106
}
83
107
assert request .querystring == expected
84
-
85
- return (200 , headers , json .dumps (self . uuids ))
108
+ uuids = self . uuids [ self . site_domain2 ] if site else self . uuids [ self . site_domain ]
109
+ return (200 , headers , json .dumps (uuids ))
86
110
87
111
httpretty .register_uri (
88
112
httpretty .GET ,
@@ -130,17 +154,36 @@ def pathways_callback(request, uri, headers): # pylint: disable=unused-argument
130
154
131
155
return (200 , headers , json .dumps (body ))
132
156
133
- # NOTE: httpretty does not properly match against query strings here (using match_querystring arg)
134
- # as such, it does not actually look at the query parameters (for page num), but returns items in a LIFO order.
135
- # this means that for multiple pages, you must call this function starting from the last page.
136
- # we do assert the page number query param above, however
137
157
httpretty .register_uri (
138
158
httpretty .GET ,
139
- self .pathway_url ,
159
+ self .pathway_url + f'?exclude_utm=1&page= { page_number } ' ,
140
160
body = pathways_callback ,
141
161
content_type = 'application/json' ,
162
+ match_querystring = True ,
142
163
)
143
164
165
+ def test_handle_domain (self ):
166
+ """
167
+ Verify that the command argument is working correct or not.
168
+ """
169
+ UserFactory (username = self .catalog_integration .service_username )
170
+
171
+ programs = {
172
+ PROGRAM_CACHE_KEY_TPL .format (uuid = program ['uuid' ]): program for program in self .programs2
173
+ }
174
+
175
+ self .mock_list (self .site2 )
176
+ self .mock_pathways (self .pathways2 )
177
+
178
+ for uuid in self .uuids [self .site_domain2 ]:
179
+ program = programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
180
+ self .mock_detail (uuid , program )
181
+
182
+ call_command ('cache_programs' , f'--domain={ self .site_domain2 } ' )
183
+
184
+ cached_uuids = cache .get (SITE_PROGRAM_UUIDS_CACHE_KEY_TPL .format (domain = self .site_domain2 ))
185
+ assert set (cached_uuids ) == set (self .uuids [self .site_domain2 ])
186
+
144
187
def test_handle_programs (self ):
145
188
"""
146
189
Verify that the command requests and caches program UUIDs and details.
@@ -158,14 +201,14 @@ def test_handle_programs(self):
158
201
self .mock_list ()
159
202
self .mock_pathways (self .pathways )
160
203
161
- for uuid in self .uuids :
204
+ for uuid in self .uuids [ self . site_domain ] :
162
205
program = programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
163
206
self .mock_detail (uuid , program )
164
207
165
208
call_command ('cache_programs' )
166
209
167
210
cached_uuids = cache .get (SITE_PROGRAM_UUIDS_CACHE_KEY_TPL .format (domain = self .site_domain ))
168
- assert set (cached_uuids ) == set (self .uuids )
211
+ assert set (cached_uuids ) == set (self .uuids [ self . site_domain ] )
169
212
170
213
program_keys = list (programs .keys ())
171
214
cached_programs = cache .get_many (program_keys )
@@ -228,7 +271,7 @@ def test_handle_pathways(self):
228
271
self .mock_list ()
229
272
self .mock_pathways (self .pathways )
230
273
231
- for uuid in self .uuids :
274
+ for uuid in self .uuids [ self . site_domain ] :
232
275
program = programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
233
276
self .mock_detail (uuid , program )
234
277
@@ -267,7 +310,7 @@ def test_pathways_multiple_pages(self):
267
310
}
268
311
269
312
self .mock_list ()
270
- for uuid in self .uuids :
313
+ for uuid in self .uuids [ self . site_domain ] :
271
314
program = programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
272
315
self .mock_detail (uuid , program )
273
316
@@ -337,7 +380,7 @@ def test_handle_missing_pathways(self):
337
380
338
381
self .mock_list ()
339
382
340
- for uuid in self .uuids :
383
+ for uuid in self .uuids [ self . site_domain ] :
341
384
program = programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
342
385
self .mock_detail (uuid , program )
343
386
@@ -365,7 +408,7 @@ def test_handle_missing_programs(self):
365
408
366
409
self .mock_list ()
367
410
368
- for uuid in self .uuids [:2 ]:
411
+ for uuid in self .uuids [self . site_domain ][ :2 ]:
369
412
program = partial_programs [PROGRAM_CACHE_KEY_TPL .format (uuid = uuid )]
370
413
self .mock_detail (uuid , program )
371
414
@@ -375,7 +418,7 @@ def test_handle_missing_programs(self):
375
418
assert context .value .code == 1
376
419
377
420
cached_uuids = cache .get (SITE_PROGRAM_UUIDS_CACHE_KEY_TPL .format (domain = self .site_domain ))
378
- assert set (cached_uuids ) == set (self .uuids )
421
+ assert set (cached_uuids ) == set (self .uuids [ self . site_domain ] )
379
422
380
423
program_keys = list (all_programs .keys ())
381
424
cached_programs = cache .get_many (program_keys )
0 commit comments