import unittest.mock import django.contrib.sites.models import rest_framework.response import rest_framework.test from printpub.user import models class TestWebfingerGet: def test_request_with_no_resource_gives_400(self): client = rest_framework.test.APIClient() res = client.get("/.well-known/webfinger") assert res.status_code == 400 def test_request_with_unknown_user_returns_404(self): client = rest_framework.test.APIClient() res = client.get("/.well-known/webfinger?resource=acct:wint@my.website") assert res.status_code == 404 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() user = models.LocalUser( display_name="dril", username="wint", password="hunter2", poster=poster ) user.save() res = client.get("/.well-known/webfinger?resource=acct:wint@example.com") assert res.status_code == 404