Beispiel #1
0
def test_import_project_good_url(mock_http_adapter: HttpInceptionAdapter,
                                 mock_io: IO, mock_http_response: Mock,
                                 serialized_project: dict):
    mock_http_response.json.return_value = {'body': serialized_project}
    mock_http_adapter.client.post.return_value = mock_http_response
    mock_http_adapter.import_project(mock_io)
    assert mock_http_adapter.client.post.call_args[0][0] == '/projects/import'
Beispiel #2
0
def test_import_project_returns_project(
        mock_http_adapter: HttpInceptionAdapter, mock_io: IO,
        mock_http_response: Mock, serialized_project: dict):
    mock_http_response.json.return_value = {'body': serialized_project}
    mock_http_adapter.client.post.return_value = mock_http_response
    project = mock_http_adapter.import_project(mock_io)
    assert isinstance(project, Project)
Beispiel #3
0
def test_get_project_returns_good_instance(
        mock_http_adapter: HttpInceptionAdapter, mock_http_response: Mock,
        serialized_project: dict):
    mock_http_response.json.return_value = {'body': serialized_project}
    mock_http_adapter.client.get.return_value = mock_http_response
    response = mock_http_adapter.project(1)
    assert isinstance(response, Project)
Beispiel #4
0
def test_document_has_project_id_injected_document_list(
        mock_http_adapter: HttpInceptionAdapter, mock_http_response: Mock,
        serialized_document: dict):
    test_project_id = 1
    mock_http_response.json.return_value = {'body': [serialized_document]}
    mock_http_adapter.client.get.return_value = mock_http_response
    response = mock_http_adapter.documents(test_project_id)
    assert response[0].project_id == test_project_id
Beispiel #5
0
def test_annotation_has_document_id_injected_annotation_list(
        mock_http_adapter: HttpInceptionAdapter, mock_http_response: Mock,
        serialized_annotation: dict):
    test_project_id = 1
    test_document_id = 2
    mock_http_response.json.return_value = {'body': [serialized_annotation]}
    mock_http_adapter.client.get.return_value = mock_http_response
    response = mock_http_adapter.annotations(test_project_id, test_document_id)
    assert response[0].document_id == test_document_id
Beispiel #6
0
def test_document_has_project_id_injected_creation(
        mock_http_adapter: HttpInceptionAdapter, mock_http_response: Mock,
        serialized_document: dict):
    test_project_id = 1
    mock_http_response.json.return_value = {'body': serialized_document}
    mock_http_adapter.client.post.return_value = mock_http_response
    response = mock_http_adapter.create_document(test_project_id, "test-name",
                                                 None)
    assert response.project_id == test_project_id
Beispiel #7
0
def test_curation_has_document_id_injected_creation(
        mock_http_adapter: HttpInceptionAdapter, mock_http_response: Mock,
        serialized_curation: dict):
    test_project_id = 1
    test_document_id = 2
    mock_http_response.json.return_value = {'body': serialized_curation}
    mock_http_adapter.client.post.return_value = mock_http_response
    response = mock_http_adapter.create_curation(test_project_id,
                                                 test_document_id,
                                                 "test-state", "test-format")
    assert response.document_id == test_document_id
Beispiel #8
0
    def __init__(self,
                 inception_host: Optional[str] = None,
                 authentication: Optional[authentication_type] = None):
        inception_host = inception_host or os.getenv('INCEPTION_HOST')
        authentication = authentication or (os.getenv('INCEPTION_USERNAME'),
                                            os.getenv('INCEPTION_PASSWORD'))
        if not inception_host:
            raise ConfigurationNotProvided(
                "Host was not provided. You can set it via environment variable as 'INCEPTION_HOST'"
            )
        if not all(authentication):
            raise ConfigurationNotProvided(
                "Authentication was not provided. "
                "You can set it via environment variables as 'INCEPTION_USERNAME' and 'INCEPTION_PASSWORD'"
            )

        self.api = HttpInceptionAdapter(inception_host, authentication)
Beispiel #9
0
def mock_http_adapter(mock_http_client):
    adapter = HttpInceptionAdapter('test-host', (None, None))
    adapter.client = mock_http_client
    return adapter