Add fixture to mock domain
parent
a9ce2c0511
commit
c93780ab35
|
@ -1,6 +1,19 @@
|
|||
import unittest.mock
|
||||
|
||||
import django.contrib.sites.models
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_domain():
|
||||
fake_site = django.contrib.sites.models.Site(domain="my.website", name="My Website")
|
||||
with unittest.mock.patch(
|
||||
"django.contrib.sites.models.SiteManager.get_current",
|
||||
return_value=fake_site,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def enable_db_access_for_all_tests(db):
|
||||
pass
|
||||
|
|
|
@ -18,7 +18,20 @@ class TestWebfingerGet:
|
|||
res = client.get("/.well-known/webfinger?resource=acct:wint@my.website")
|
||||
assert res.status_code == 404
|
||||
|
||||
def test_known_user_returns_serializer_data(self):
|
||||
def test_known_user_returns_serializer_data(self, mock_domain):
|
||||
client = rest_framework.test.APIClient()
|
||||
poster = models.Poster()
|
||||
poster.save()
|
||||
user = models.LocalUser(
|
||||
display_name="dril", username="wint", password="hunter2", poster=poster
|
||||
)
|
||||
user.save()
|
||||
res = client.get("/.well-known/webfinger?resource=acct:wint@my.website")
|
||||
assert res.status_code == 200
|
||||
# We could test more properties of this, but we will leave that to the serializer test
|
||||
assert res.data["subject"] == "acct:wint@my.website"
|
||||
|
||||
def test_wrong_domain_in_request_returns_404(self, mock_domain):
|
||||
client = rest_framework.test.APIClient()
|
||||
poster = models.Poster()
|
||||
poster.save()
|
||||
|
@ -27,33 +40,5 @@ class TestWebfingerGet:
|
|||
)
|
||||
user.save()
|
||||
|
||||
fake_site = django.contrib.sites.models.Site(
|
||||
domain="my.website", name="My Website"
|
||||
)
|
||||
with unittest.mock.patch(
|
||||
"django.contrib.sites.models.SiteManager.get_current",
|
||||
return_value=fake_site,
|
||||
):
|
||||
res = client.get("/.well-known/webfinger?resource=acct:wint@my.website")
|
||||
assert res.status_code == 200
|
||||
# We could test more properties of this, but we will leave that to the serializer test
|
||||
assert res.data["subject"] == "acct:wint@my.website"
|
||||
|
||||
def test_wrong_domain_in_request_returns_404(self):
|
||||
client = rest_framework.test.APIClient()
|
||||
poster = models.Poster()
|
||||
poster.save()
|
||||
user = models.LocalUser(
|
||||
display_name="dril", username="wint", password="hunter2", poster=poster
|
||||
)
|
||||
user.save()
|
||||
|
||||
fake_site = django.contrib.sites.models.Site(
|
||||
domain="my.website", name="My Website"
|
||||
)
|
||||
with unittest.mock.patch(
|
||||
"django.contrib.sites.models.SiteManager.get_current",
|
||||
return_value=fake_site,
|
||||
):
|
||||
res = client.get("/.well-known/webfinger?resource=acct:wint@example.com")
|
||||
assert res.status_code == 404
|
||||
res = client.get("/.well-known/webfinger?resource=acct:wint@example.com")
|
||||
assert res.status_code == 404
|
||||
|
|
Loading…
Reference in New Issue