Example #1
0
def test_create_app(mock_post):
    mock_post.return_value = MockResponse({
        'client_id': 'foo',
        'client_secret': 'bar',
    })

    create_app('bigfish.software')

    mock_post.assert_called_once_with('https://bigfish.software/api/v1/apps', {
        'website': CLIENT_WEBSITE,
        'client_name': CLIENT_NAME,
        'scopes': SCOPES,
        'redirect_uris': 'urn:ietf:wg:oauth:2.0:oob',
    })
Example #2
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')
Example #3
0
def create_app_interactive():
    instance = input("Choose an instance [%s]: " % green(DEFAULT_INSTANCE))
    if not instance:
        instance = DEFAULT_INSTANCE

    base_url = 'https://{}'.format(instance)

    print("Registering application with %s" % green(base_url))
    try:
        app = api.create_app(base_url)
    except:
        raise ConsoleError("Failed authenticating application. Did you enter a valid instance?")

    save_app(app)
    print("Application tokens saved to: {}".format(green(CONFIG_APP_FILE)))

    return app
Example #4
0
def register_app(instance):
    print("Registering application with %s" % green(instance))

    try:
        response = api.create_app(instance)
    except:
        raise ConsoleError(
            "Registration failed. Did you enter a valid instance?")

    base_url = 'https://' + instance

    app = App(instance, base_url, response['client_id'],
              response['client_secret'])
    path = config.save_app(app)
    print("Application tokens saved to: {}\n".format(green(path)))

    return app
Example #5
0
def test_create_app(monkeypatch):
    response = {
        'client_id': 'foo',
        'client_secret': 'bar',
    }

    def mock_post(url, data):
        assert url == 'https://bigfish.software/api/v1/apps'
        assert data == {
            'website': CLIENT_WEBSITE,
            'client_name': CLIENT_NAME,
            'scopes': SCOPES,
            'redirect_uris': 'urn:ietf:wg:oauth:2.0:oob'
        }
        return MockResponse(response)

    monkeypatch.setattr(requests, 'post', mock_post)

    assert create_app('bigfish.software') == response
Example #6
0
def register_app(domain, scheme='https'):
    print_out("Looking up instance info...")
    instance = api.get_instance(domain)

    print_out(
        "Found instance <blue>{}</blue> running Mastodon version <yellow>{}</yellow>"
        .format(instance['title'], instance['version']))

    try:
        print_out("Registering application...")
        response = api.create_app(domain, scheme)
    except ApiError:
        raise ConsoleError("Registration failed.")

    base_url = scheme + '://' + domain

    app = App(domain, base_url, response['client_id'],
              response['client_secret'])
    config.save_app(app)

    print_out("Application tokens saved.")

    return app