示例#1
0
 def request(self, method, path, **options):
     try:
         return super().request(method, path, **options)
     except asana.error.AsanaError:
         raise exceptions.InvalidRequest()
     except Exception as e:
         raise exceptions.FailedRequest()
示例#2
0
def test_import_asana_list_users_with_problem_on_request(client):
    user = f.UserFactory.create()
    client.login(user)

    url = reverse("importers-asana-list-users")

    with mock.patch('taiga.importers.asana.importer.AsanaClient') as AsanaClientMock:
        instance = mock.Mock()
        instance.workspaces.find_all.side_effect = exceptions.InvalidRequest()
        AsanaClientMock.oauth.return_value = instance
        response = client.post(url, content_type="application/json", data=json.dumps({"token": "token", "project": 1}))

    assert response.status_code == 400
示例#3
0
def test_authorize_with_bad_verify(client, settings):
    user = f.UserFactory.create()
    client.login(user)

    authorize_url = reverse("importers-asana-authorize")

    with mock.patch('taiga.importers.asana.api.AsanaImporter') as AsanaImporterMock:
        AsanaImporterMock.get_access_token.side_effect = exceptions.InvalidRequest()
        response = client.post(authorize_url, content_type="application/json", data=json.dumps({"code": "bad"}))
        assert AsanaImporterMock.get_access_token.calledWith(
            settings.IMPORTERS['asana']['app_id'],
            settings.IMPORTERS['asana']['app_secret'],
            "bad"
        )

    assert response.status_code == 400
    assert 'token' not in response.data
    assert '_error_message' in response.data
    assert response.data['_error_message'] == "Invalid Asana API request"