def test_generate_hcard_raises_on_unknown_attribute(self): with pytest.raises(ValueError): generate_hcard("diaspora", hostname="hostname", fullname="fullname", firstname="firstname", unknown="unknown")
def test_generate_hcard_raises_on_missing_attribute(self): with pytest.raises(AssertionError): generate_hcard( "diaspora", hostname="hostname", fullname="fullname", firstname="firstname" )
def test_generate_hcard_raises_on_unknown_attribute(self): with pytest.raises(ValueError): generate_hcard( "diaspora", hostname="hostname", fullname="fullname", firstname="firstname", username="******" )
def test_profile_is_parsed(self): hcard = generate_hcard( "diaspora", hostname="https://example.com", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="true", guid="guidguidguidguid", public_key="public_key", username="******", ) profile = parse_profile_from_hcard(hcard, "*****@*****.**") assert profile.name == "fullname" assert profile.image_urls == { "small": "photo50", "medium": "photo100", "large": "photo300" } assert profile.public == True assert profile.handle == "*****@*****.**" assert profile.guid == "guidguidguidguid" assert profile.public_key == "public_key\n" profile.validate()
def hcard(guid): if guid != app.config.get("RELAY_GUID"): return abort(404) hcard = generate_hcard("diaspora", hostname=app.config.get("SERVER_HOST"), fullname=app.config.get("RELAY_NAME"), firstname=app.config.get("RELAY_NAME"), lastname="", photo300="", photo100="", photo50="", searchable="false") return Response(hcard, status=200)
def test_generate_valid_hcard(self): with open("federation/hostmeta/templates/hcard_diaspora.html") as f: template = f.read().replace("$", "") hcard = generate_hcard( "diaspora", hostname="hostname", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="searchable" ) assert hcard == template
def hcard(guid): if guid != app.config.get("RELAY_GUID"): return abort(404) hcard = generate_hcard( "diaspora", hostname=app.config.get("SERVER_HOST"), fullname=app.config.get("RELAY_NAME"), firstname=app.config.get("RELAY_NAME"), lastname="", photo300="", photo100="", photo50="", searchable="false" ) return Response(hcard, status=200)
def test_parse_profile_from_hcard_called(self, mock_retrieve, mock_parse): hcard = generate_hcard( "diaspora", hostname="https://hostname", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="true", guid="guid", public_key="public_key", username="******", ) mock_retrieve.return_value = hcard retrieve_and_parse_profile("foo@bar") mock_parse.assert_called_with(hcard, "foo@bar")
def test_generate_valid_hcard(self): with open("federation/hostmeta/templates/hcard_diaspora.html") as f: template = f.read().replace("$", "") hcard = generate_hcard( "diaspora", hostname="hostname", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="searchable", guid="guid", public_key="public_key", username="******", ) assert hcard == template
def test_profile_that_doesnt_validate_returns_none(self, mock_retrieve, mock_parse): hcard = generate_hcard( "diaspora", hostname="https://hostname", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="true", guid="guid", public_key="public_key", username="******", ) mock_retrieve.return_value = hcard mock_parse.return_value = Profile(guid="123") profile = retrieve_and_parse_profile("foo@bar") assert profile == None
def test_profile_validate_is_called(self, mock_retrieve, mock_parse): hcard = generate_hcard( "diaspora", hostname="https://hostname", fullname="fullname", firstname="firstname", lastname="lastname", photo300="photo300", photo100="photo100", photo50="photo50", searchable="true", guid="guid", public_key="public_key", username="******", ) mock_retrieve.return_value = hcard mock_profile = Mock() mock_parse.return_value = mock_profile retrieve_and_parse_profile("foo@bar") assert mock_profile.validate.called
def hcard_view(request, guid): """Generate a hcard document. For local users only. """ try: profile = get_object_or_404(Profile, guid=guid, user__isnull=False) except ValueError: raise Http404() hcard = generate_hcard( "diaspora", hostname=settings.SOCIALHOME_URL, fullname=profile.name, firstname=profile.get_first_name(), lastname=profile.get_last_name(), photo300=profile.safer_image_url_large, photo100=profile.safer_image_url_medium, photo50=profile.safer_image_url_small, searchable="true" if profile.public else "false", guid=profile.guid, username=profile.user.username, public_key=profile.rsa_public_key, ) return HttpResponse(hcard)
def test_generate_hcard_raises_on_missing_attribute(self): with pytest.raises(AssertionError): generate_hcard("diaspora", hostname="hostname", fullname="fullname", firstname="firstname")