@@ -326,7 +326,6 @@ def test_get_access_data_success(self, time_time_mock, sign_mock):
326326 data = client .get_access_data (
327327 ['article-1' , 'article-2' ],
328328 lptoken = 'fake-lptoken' ,
329- muid = 'some-user' ,
330329 )
331330
332331 self .assertEqual (data , {
@@ -349,7 +348,7 @@ def test_get_access_data_success(self, time_time_mock, sign_mock):
349348 self .assertEqual (qd ['cp' ], ['fake-cp-key' ])
350349 self .assertEqual (qd ['article_id' ], ['article-1' , 'article-2' ])
351350 self .assertEqual (qd ['hmac' ], ['fake-signature' ])
352- self .assertEqual ( qd [ 'muid' ], [ 'some-user' ] )
351+ self .assertNotIn ( 'muid' , 'qd' )
353352
354353 sign_mock .assert_called_once_with (
355354 secret = 'fake-shared-secret' ,
@@ -358,6 +357,70 @@ def test_get_access_data_success(self, time_time_mock, sign_mock):
358357 'article_id' : ['article-1' , 'article-2' ],
359358 'ts' : '123' ,
360359 'lptoken' : 'fake-lptoken' ,
360+ },
361+ url = 'http://example.net/access' ,
362+ method = 'GET' ,
363+ )
364+
365+ @mock .patch ('laterpay.signing.sign' )
366+ @mock .patch ('time.time' )
367+ @responses .activate
368+ def test_get_access_data_success_muid (self , time_time_mock , sign_mock ):
369+ time_time_mock .return_value = 123
370+ sign_mock .return_value = 'fake-signature'
371+ responses .add (
372+ responses .GET ,
373+ 'http://example.net/access' ,
374+ body = json .dumps ({
375+ "status" : "ok" ,
376+ "articles" : {
377+ "article-1" : {"access" : True },
378+ "article-2" : {"access" : False },
379+ },
380+ }),
381+ status = 200 ,
382+ content_type = 'application/json' ,
383+ )
384+
385+ client = LaterPayClient (
386+ 'fake-cp-key' ,
387+ 'fake-shared-secret' ,
388+ api_root = 'http://example.net' ,
389+ )
390+
391+ data = client .get_access_data (
392+ ['article-1' , 'article-2' ],
393+ muid = 'some-user' ,
394+ )
395+
396+ self .assertEqual (data , {
397+ "status" : "ok" ,
398+ "articles" : {
399+ "article-1" : {"access" : True },
400+ "article-2" : {"access" : False },
401+ },
402+ })
403+ self .assertEqual (len (responses .calls ), 1 )
404+
405+ call = responses .calls [0 ]
406+
407+ self .assertEqual (call .request .headers ['X-LP-APIVersion' ], '2' )
408+
409+ qd = parse_qs (urlparse (call .request .url ).query )
410+
411+ self .assertEqual (qd ['ts' ], ['123' ])
412+ self .assertEqual (qd ['cp' ], ['fake-cp-key' ])
413+ self .assertEqual (qd ['article_id' ], ['article-1' , 'article-2' ])
414+ self .assertEqual (qd ['hmac' ], ['fake-signature' ])
415+ self .assertEqual (qd ['muid' ], ['some-user' ])
416+ self .assertNotIn ('lptoken' , 'qd' )
417+
418+ sign_mock .assert_called_once_with (
419+ secret = 'fake-shared-secret' ,
420+ params = {
421+ 'cp' : 'fake-cp-key' ,
422+ 'article_id' : ['article-1' , 'article-2' ],
423+ 'ts' : '123' ,
361424 'muid' : 'some-user' ,
362425 },
363426 url = 'http://example.net/access' ,
@@ -379,16 +442,31 @@ def test_get_access_params(self, time_time_mock, sign_mock):
379442 'hmac' : 'fake-signature' ,
380443 })
381444
382- params = self .lp .get_access_params ('article-1' , lptoken = 'fake-lptoken' , muid = 'some-user' )
445+ params = self .lp .get_access_params ('article-1' , muid = 'some-user' )
383446 self .assertEqual (params , {
384447 'cp' : '1' ,
385448 'ts' : '123' ,
386- 'lptoken' : 'fake-lptoken' ,
387449 'article_id' : ['article-1' ],
388450 'hmac' : 'fake-signature' ,
389451 'muid' : 'some-user' ,
390452 })
391453
454+ lpclient = LaterPayClient ('1' , 'some-secret' , lptoken = 'instance-lptoken' )
455+ params = lpclient .get_access_params ('article-1' )
456+ self .assertEqual (params , {
457+ 'cp' : '1' ,
458+ 'ts' : '123' ,
459+ 'lptoken' : 'instance-lptoken' ,
460+ 'article_id' : ['article-1' ],
461+ 'hmac' : 'fake-signature' ,
462+ })
463+
464+ with self .assertRaises (AssertionError ):
465+ self .lp .get_access_params ('article-1' , lptoken = 'fake-lptoken' , muid = 'some-user' )
466+
467+ with self .assertRaises (AssertionError ):
468+ self .lp .get_access_params ('article-1' )
469+
392470 @mock .patch ('time.time' )
393471 def test_get_gettoken_redirect (self , time_mock ):
394472 time_mock .return_value = 12345678
0 commit comments