Skip to content
Snippets Groups Projects
Select Git revision
  • fix-index.html-encoding
  • develop default protected
  • document-loglevel
  • master
  • 1.0.1
  • 1121-download
  • plugins-v3
  • 876-http-signature
  • plugins-v2
  • plugins
  • 1.0.1
  • 1.0
  • 1.0-rc1
  • 0.21.2
  • 0.21.1
  • 0.21
  • 0.21-rc2
  • 0.21-rc1
  • 0.20.1
  • 0.20.0
  • 0.20.0-rc1
  • 0.19.1
  • 0.19.0
  • 0.19.0-rc2
  • 0.19.0-rc1
  • 0.18.3
  • 0.18.2
  • 0.18.1
  • 0.18
  • 0.17
30 results

test_webfinger.py

Blame
  • Forked from funkwhale / funkwhale
    7432 commits behind the upstream repository.
    test_webfinger.py 1.27 KiB
    import pytest
    
    from django import forms
    from django.urls import reverse
    
    from funkwhale_api.federation import webfinger
    
    
    def test_webfinger_clean_resource():
        t, r = webfinger.clean_resource('acct:service@test.federation')
        assert t == 'acct'
        assert r == 'service@test.federation'
    
    
    @pytest.mark.parametrize('resource,message', [
        ('', 'Invalid resource string'),
        ('service@test.com', 'Missing webfinger resource type'),
        ('noop:service@test.com', 'Invalid webfinger resource type'),
    ])
    def test_webfinger_clean_resource_errors(resource, message):
        with pytest.raises(forms.ValidationError) as excinfo:
            webfinger.clean_resource(resource)
    
            assert message == str(excinfo)
    
    
    def test_webfinger_clean_acct(settings):
        username, hostname = webfinger.clean_acct('library@test.federation')
        assert username == 'library'
        assert hostname == 'test.federation'
    
    
    @pytest.mark.parametrize('resource,message', [
        ('service', 'Invalid format'),
        ('service@test.com', 'Invalid hostname test.com'),
        ('noop@test.federation', 'Invalid account'),
    ])
    def test_webfinger_clean_acct_errors(resource, message, settings):
        with pytest.raises(forms.ValidationError) as excinfo:
            webfinger.clean_resource(resource)
    
            assert message == str(excinfo)