Пример #1
0
def test_unfollow_not_found(monkeypatch, capsys):
    req = Request('GET', 'https://habunek.com/api/v1/accounts/search',
                  params={'q': 'blixa'}, headers={'Authorization': 'Bearer xxx'})
    res = MockResponse([])

    expectations = Expectations([req], [res])
    expectations.patch(monkeypatch)

    with pytest.raises(ConsoleError) as ex:
        console.run_command(app, user, 'unfollow', ['blixa'])
    assert "Account not found" == str(ex.value)
Пример #2
0
def test_unfollow(monkeypatch, capsys):
    req1 = Request('GET', 'https://habunek.com/api/v1/accounts/search',
                   params={'q': 'blixa'},
                   headers={'Authorization': 'Bearer xxx'})
    res1 = MockResponse([
        {'id': 123, 'acct': '*****@*****.**'},
        {'id': 321, 'acct': 'blixa'},
    ])

    req2 = Request('POST', 'https://habunek.com/api/v1/accounts/321/unfollow',
                   headers={'Authorization': 'Bearer xxx'})
    res2 = MockResponse()

    expectations = Expectations([req1, req2], [res1, res2])
    expectations.patch(monkeypatch)

    console.run_command(app, user, 'unfollow', ['blixa'])

    out, err = capsys.readouterr()
    assert "You are no longer following blixa" in out
Пример #3
0
def test_login(monkeypatch):
    app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar')

    data = {
        'grant_type': 'password',
        'client_id': app.client_id,
        'client_secret': app.client_secret,
        'username': '******',
        'password': '******',
        'scope': SCOPES,
    }

    request = Request('POST',
                      'https://bigfish.software/oauth/token',
                      data=data)

    response = MockResponse({
        'token_type': 'bearer',
        'scope': 'read write follow',
        'access_token': 'xxx',
        'created_at': 1492523699
    })

    e = Expectations()
    e.add(request, response)
    e.patch(monkeypatch)

    login(app, 'user', 'pass')
Пример #4
0
def test_whoami(monkeypatch, capsys):
    req = Request('GET', 'https://habunek.com/api/v1/accounts/verify_credentials',
                  headers={'Authorization': 'Bearer xxx'})

    res = MockResponse({
        'acct': 'ihabunek',
        'avatar': 'https://files.mastodon.social/accounts/avatars/000/046/103/original/6a1304e135cac514.jpg?1491312434',
        'avatar_static': 'https://files.mastodon.social/accounts/avatars/000/046/103/original/6a1304e135cac514.jpg?1491312434',
        'created_at': '2017-04-04T13:23:09.777Z',
        'display_name': 'Ivan Habunek',
        'followers_count': 5,
        'following_count': 9,
        'header': '/headers/original/missing.png',
        'header_static': '/headers/original/missing.png',
        'id': 46103,
        'locked': False,
        'note': 'A developer.',
        'statuses_count': 19,
        'url': 'https://mastodon.social/@ihabunek',
        'username': '******'
    })

    expectations = Expectations([req], [res])
    expectations.patch(monkeypatch)

    console.run_command(app, user, 'whoami', [])

    out, err = capsys.readouterr()
    out = uncolorize(out)

    assert "@ihabunek Ivan Habunek" in out
    assert "A developer." in out
    assert "https://mastodon.social/@ihabunek" in out
    assert "ID: 46103" in out
    assert "Since: 2017-04-04 @ 13:23:09" in out
    assert "Followers: 5" in out
    assert "Following: 9" in out
    assert "Statuses: 19" in out
Пример #5
0
def test_create_app(monkeypatch):
    request = Request('POST',
                      'https://bigfish.software/api/v1/apps',
                      data={
                          'website': CLIENT_WEBSITE,
                          'client_name': CLIENT_NAME,
                          'scopes': SCOPES,
                          'redirect_uris': 'urn:ietf:wg:oauth:2.0:oob'
                      })

    response = MockResponse({'client_id': 'foo', 'client_secret': 'bar'})

    e = Expectations()
    e.add(request, response)
    e.patch(monkeypatch)

    create_app('bigfish.software')
Пример #6
0
def test_login_failed(monkeypatch):
    app = App('bigfish.software', 'https://bigfish.software', 'foo', 'bar')

    data = {
        'grant_type': 'password',
        'client_id': app.client_id,
        'client_secret': app.client_secret,
        'username': '******',
        'password': '******',
        'scope': SCOPES,
    }

    request = Request('POST',
                      'https://bigfish.software/oauth/token',
                      data=data)
    response = MockResponse(is_redirect=True)

    e = Expectations()
    e.add(request, response)
    e.patch(monkeypatch)

    with pytest.raises(AuthenticationError):
        login(app, 'user', 'pass')