1919
2020class TestItemDefinition (unittest .TestCase ):
2121
22- def test_item_definition (self ):
22+ def test_invalid_pricing (self ):
2323 with self .assertRaises (InvalidItemDefinition ):
2424 ItemDefinition (1 , '' , '' , 'title' )
25+
26+ def test_invalid_expiry (self ):
2527 with self .assertRaises (InvalidItemDefinition ):
2628 ItemDefinition (1 , 'EUR20' , 'http://foo.invalid' , 'title' , expiry = "illegal123" )
2729
28- it = ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , expiry = '+100' )
30+ def test_invalid_sub_id (self ):
31+ with self .assertRaisesRegexp (InvalidItemDefinition , r'^Invalid sub_id value ' ):
32+ ItemDefinition (1 , 'EUR20' , 'http://example.com' , 'title' , sub_id = '' , period = 3600 )
33+ with self .assertRaisesRegexp (InvalidItemDefinition , r'^Invalid sub_id value ' ):
34+ ItemDefinition (1 , 'EUR20' , 'http://example.com' , 'title' , sub_id = 'a' * 129 , period = 3600 )
35+ with self .assertRaisesRegexp (InvalidItemDefinition , r'^Invalid sub_id value ' ):
36+ ItemDefinition (1 , 'EUR20' , 'http://example.com' , 'title' , sub_id = 'ä' , period = 3600 )
37+
38+ def test_invalid_period (self ):
39+ with self .assertRaisesRegexp (InvalidItemDefinition , r'Period not set or invalid value' ):
40+ ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'a' , period = 3599 )
41+ with self .assertRaisesRegexp (InvalidItemDefinition , r'Period not set or invalid value' ):
42+ ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'a' , period = 31536001 )
43+ with self .assertRaisesRegexp (InvalidItemDefinition , r'Period not set or invalid value' ):
44+ ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'a' , period = '12345' )
2945
46+ def test_item_definition (self ):
47+ it = ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , expiry = '+100' )
3048 self .assertEqual (it .data , {
3149 'article_id' : 1 ,
3250 'expiry' : '+100' ,
@@ -35,6 +53,22 @@ def test_item_definition(self):
3553 'url' : 'http://example.com/t' ,
3654 })
3755
56+ def test_sub_id (self ):
57+ # Test sub_id_bounds
58+ ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'a' , period = 3600 )
59+ ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'a' * 128 , period = 31536000 )
60+
61+ it = ItemDefinition (1 , 'EUR20' , 'http://example.com/t' , 'title' , sub_id = 'abc' , period = 12345 )
62+ self .assertEqual (it .data , {
63+ 'article_id' : 1 ,
64+ 'expiry' : None ,
65+ 'period' : 12345 ,
66+ 'pricing' : 'EUR20' ,
67+ 'sub_id' : 'abc' ,
68+ 'title' : 'title' ,
69+ 'url' : 'http://example.com/t' ,
70+ })
71+
3872
3973class TestLaterPayClient (unittest .TestCase ):
4074
@@ -206,6 +240,31 @@ def test_get_buy_url(self):
206240 self .assertQueryString (url , 'something' , value = 'else' )
207241 self .assertQueryString (url , 'BLUB' , value = [b'b1' , 'b2' , u'u1' , 'u2' ])
208242
243+ def test_get_subscribe_url (self ):
244+ item = ItemDefinition (1 , 'EUR20' , 'http://example.net/t' , 'title' , sub_id = 'a0_-9Z' , period = 12345 )
245+ url = self .lp .get_subscribe_url (
246+ item ,
247+ product_key = 'some-product-key' ,
248+ dialog = False ,
249+ return_url = 'http://return.url/foo?bar=buz&lorem=ipsum' ,
250+ failure_url = 'http://failure.url/FOO?BAR=BUZ&LOREM=IPSUM' ,
251+ something = 'else' ,
252+ period = 12345 ,
253+ BLUB = [u'u2' , b'b1' , b'b2' , u'u1' ],
254+ )
255+ self .assertFalse (
256+ self .assertQueryString (url , 'expiry' ),
257+ 'expiry url param is "None". Should be omitted.'
258+ )
259+ self .assertQueryString (url , 'sub_id' , value = 'a0_-9Z' )
260+ self .assertQueryString (url , 'product_key' , value = 'some-product-key' )
261+ self .assertTrue (url .startswith ('https://web.laterpay.net/subscribe?' ))
262+ self .assertQueryString (url , 'return_url' , value = 'http://return.url/foo?bar=buz&lorem=ipsum' )
263+ self .assertQueryString (url , 'failure_url' , value = 'http://failure.url/FOO?BAR=BUZ&LOREM=IPSUM' )
264+ self .assertQueryString (url , 'something' , value = 'else' )
265+ self .assertQueryString (url , 'period' , value = '12345' )
266+ self .assertQueryString (url , 'BLUB' , value = [b'b1' , 'b2' , u'u1' , 'u2' ])
267+
209268 def test_get_login_dialog_url_with_use_dialog_api_false (self ):
210269 url = self .lp .get_login_dialog_url ('http://example.org' )
211270 self .assertEqual (str (furl (url ).path ), '/account/dialog/login' )
0 commit comments