-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_utils.py
More file actions
31 lines (20 loc) · 971 Bytes
/
test_utils.py
File metadata and controls
31 lines (20 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import getpass
from unittest.mock import patch
from pythonanywhere.utils import ensure_domain
class TestEnsureDomain:
def test_domain_defaults_to_using_current_username_and_domain_from_env(
self, monkeypatch
):
username = getpass.getuser()
monkeypatch.setenv("PYTHONANYWHERE_DOMAIN", "pythonanywhere.domain")
result = ensure_domain("your-username.pythonanywhere.com")
assert result == "{}.pythonanywhere.domain".format(username)
def test_lowercases_username(self, monkeypatch):
with patch('pythonanywhere.utils.getpass') as mock_getpass:
mock_getpass.getuser.return_value = 'UserName1'
result = ensure_domain("your-username.pythonanywhere.com")
assert result == 'username1.pythonanywhere.com'
def test_custom_domain_remains_unchanged(self):
custom_domain = "foo.bar.baz"
result = ensure_domain(custom_domain)
assert result == custom_domain