File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,14 @@ class NoTokenError(Exception):
2121
2222
2323def get_api_endpoint ():
24- domain = os .environ .get ("PYTHONANYWHERE_DOMAIN" , "pythonanywhere.com" )
25- return "https://www.{domain}/api/v0/user/{{username}}/{{flavor}}/" .format (domain = domain )
24+ hostname = os .environ .get (
25+ "PYTHONANYWHERE_SITE" ,
26+ "www." + os .environ .get (
27+ "PYTHONANYWHERE_DOMAIN" ,
28+ "pythonanywhere.com"
29+ )
30+ )
31+ return "https://{hostname}/api/v0/user/{{username}}/{{flavor}}/" .format (hostname = hostname )
2632
2733
2834def call_api (url , method , ** kwargs ):
Original file line number Diff line number Diff line change 1111
1212
1313class TestGetAPIEndpoint :
14- def test_gets_domain_from_env_if_set (self , monkeypatch ):
14+
15+ def test_defaults_to_pythonanywhere_dot_com_if_no_environment_variables (self ):
1516 assert get_api_endpoint () == "https://www.pythonanywhere.com/api/v0/user/{username}/{flavor}/"
17+
18+ def test_gets_domain_from_pythonanywhere_site_and_ignores_pythonanywhere_domain_if_both_set (self , monkeypatch ):
19+ monkeypatch .setenv ("PYTHONANYWHERE_SITE" , "www.foo.com" )
20+ monkeypatch .setenv ("PYTHONANYWHERE_DOMAIN" , "wibble.com" )
21+ assert get_api_endpoint () == "https://www.foo.com/api/v0/user/{username}/{flavor}/"
22+
23+ def test_gets_domain_from_pythonanywhere_domain_and_adds_on_www_if_set_but_no_pythonanywhere_site (self , monkeypatch ):
1624 monkeypatch .setenv ("PYTHONANYWHERE_DOMAIN" , "foo.com" )
1725 assert get_api_endpoint () == "https://www.foo.com/api/v0/user/{username}/{flavor}/"
1826
You can’t perform that action at this time.
0 commit comments