44from unittest .mock import patch
55from urllib .parse import urlencode
66
7+ from dateutil .tz import tzutc
78import pytest
89import responses
910from pythonanywhere .api import PYTHON_VERSIONS , AuthenticationError , Webapp , call_api , get_api_endpoint
@@ -277,7 +278,9 @@ def test_raises_if_post_does_not_20x(self, api_responses, api_token):
277278
278279
279280class TestGetWebappSSLInfo :
280- def test_returns_json_from_server_having_parsed_expiry (self , api_responses , api_token ):
281+ def test_returns_json_from_server_having_parsed_expiry_with_z_for_utc_and_no_separators (
282+ self , api_responses , api_token
283+ ):
281284 expected_url = get_api_endpoint ().format (username = getpass .getuser (), flavor = "webapps" ) + "mydomain.com/ssl/"
282285 api_responses .add (
283286 responses .GET ,
@@ -294,7 +297,37 @@ def test_returns_json_from_server_having_parsed_expiry(self, api_responses, api_
294297 )
295298
296299 assert Webapp ("mydomain.com" ).get_ssl_info () == {
297- "not_after" : datetime (2018 , 8 , 24 , 17 , 16 , 23 ),
300+ "not_after" : datetime (2018 , 8 , 24 , 17 , 16 , 23 , tzinfo = tzutc ()),
301+ "issuer_name" : "PythonAnywhere test CA" ,
302+ "subject_name" : "www.mycoolsite.com" ,
303+ "subject_alternate_names" : ["www.mycoolsite.com" , "mycoolsite.com" ],
304+ }
305+
306+ get = api_responses .calls [0 ]
307+ assert get .request .method == "GET"
308+ assert get .request .url == expected_url
309+ assert get .request .headers ["Authorization" ] == "Token {api_token}" .format (api_token = api_token )
310+
311+ def test_returns_json_from_server_having_parsed_expiry_with_timezone_offset_and_separators (
312+ self , api_responses , api_token
313+ ):
314+ expected_url = get_api_endpoint ().format (username = getpass .getuser (), flavor = "webapps" ) + "mydomain.com/ssl/"
315+ api_responses .add (
316+ responses .GET ,
317+ expected_url ,
318+ status = 200 ,
319+ body = json .dumps (
320+ {
321+ "not_after" : "2018-08-24T17:16:23+00:00" ,
322+ "issuer_name" : "PythonAnywhere test CA" ,
323+ "subject_name" : "www.mycoolsite.com" ,
324+ "subject_alternate_names" : ["www.mycoolsite.com" , "mycoolsite.com" ],
325+ }
326+ ),
327+ )
328+
329+ assert Webapp ("mydomain.com" ).get_ssl_info () == {
330+ "not_after" : datetime (2018 , 8 , 24 , 17 , 16 , 23 , tzinfo = tzutc ()),
298331 "issuer_name" : "PythonAnywhere test CA" ,
299332 "subject_name" : "www.mycoolsite.com" ,
300333 "subject_alternate_names" : ["www.mycoolsite.com" , "mycoolsite.com" ],
0 commit comments