Exemple #1
0
def test_get_expected_document_by_guid(test_client, db_session, auth_headers):
    exp_doc_guid = MineExpectedDocumentFactory().exp_document_guid

    get_resp = test_client.get('/documents/expected/' + str(exp_doc_guid),
                               headers=auth_headers['full_auth_header'])
    get_data = json.loads(get_resp.data.decode())
    assert get_resp.status_code == 200
    assert get_data['expected_document']['exp_document_guid'] == str(
        exp_doc_guid)
Exemple #2
0
def test_remove_file_no_doc(test_client, db_session, auth_headers):
    expected_document = MineExpectedDocumentFactory()

    post_resp = test_client.delete(
        f'/documents/expected/{expected_document.exp_document_guid}/document/{uuid.uuid4()}',
        headers=auth_headers['full_auth_header'])

    post_data = json.loads(post_resp.data.decode())

    assert post_resp.status_code == 404
    assert post_data['error']['message'] is not None
def test_get_mine_documents_by_mine_guid(test_client, db_session,
                                         auth_headers):
    mine_documents_count = 5
    mine = MineFactory(minimal=True)

    exp_doc = MineExpectedDocumentFactory.create_batch(
        size=1, mine=mine, related_documents=mine_documents_count)

    get_resp = test_client.get('/documents/mines/' + str(mine.mine_guid),
                               headers=auth_headers['full_auth_header'])
    get_data = json.loads(get_resp.data.decode())
    assert get_resp.status_code == 200
    assert len(get_data['mine_documents']) == mine_documents_count
Exemple #4
0
def test_expected_documents_find_by_mine_guid_after_insert(db_session):
    mine = MineFactory(mine_expected_documents=BATCH_SIZE)
    mine_guid = mine.mine_guid
    org_expected_documents = MineExpectedDocument.find_by_mine_guid(
        str(mine_guid))

    MineExpectedDocumentFactory(mine=mine)
    new_expected_documents = MineExpectedDocument.find_by_mine_guid(
        str(mine_guid))

    assert len(new_expected_documents) == BATCH_SIZE + 1
    assert all(mine_guid == ned.mine_guid for ned in new_expected_documents)
    assert all(mine_guid == oed.mine_guid for oed in org_expected_documents)
Exemple #5
0
def test_put_expected_document_by_guid(test_client, db_session, auth_headers):
    exp_doc_guid = MineExpectedDocumentFactory().exp_document_guid

    put_resp = test_client.put(
        '/documents/expected/' + str(exp_doc_guid),
        data={'exp_document_name': 'updatedocumentname'},
        headers=auth_headers['full_auth_header'])
    put_data = json.loads(put_resp.data.decode())
    assert put_resp.status_code == 200
    assert put_data['expected_document'][
        'exp_document_name'] == 'updatedocumentname'
    assert put_data['expected_document']['exp_document_guid'] == str(
        exp_doc_guid)
Exemple #6
0
def test_happy_path_file_removal(test_client, db_session, auth_headers):
    expected_document = MineExpectedDocumentFactory()
    mine_document = expected_document.related_documents[0]
    assert mine_document is not None

    post_resp = test_client.delete(
        f'/documents/expected/{expected_document.exp_document_guid}/document/{mine_document.mine_document_guid}',
        headers=auth_headers['full_auth_header'])

    post_data = json.loads(post_resp.data.decode())

    assert post_resp.status_code == 200
    assert post_data['message'] is not None
    assert mine_document not in expected_document.related_documents
Exemple #7
0
def test_put_existing_file(test_client, db_session, auth_headers):
    expected_doc = MineExpectedDocumentFactory()
    existing_mine_doc = MineDocumentFactory(mine=expected_doc.mine)
    document_count = len(expected_doc.related_documents)

    data = {'mine_document_guid': existing_mine_doc.mine_document_guid}
    post_resp = test_client.put(
        f'/documents/expected/{expected_doc.exp_document_guid}/document',
        headers=auth_headers['full_auth_header'],
        json=data)
    post_data = json.loads(post_resp.data.decode())
    assert post_resp.status_code == 200
    assert len(post_data['related_documents']) == document_count + 1
    assert any(
        str(existing_mine_doc.mine_document_guid) == rel_doc['mine_document_guid']
        for rel_doc in post_data['related_documents'])
Exemple #8
0
def test_put_new_file(test_client, db_session, auth_headers):
    expected_doc = MineExpectedDocumentFactory()
    new_doc = DocumentManagerFactory()
    document_count = len(expected_doc.related_documents)

    data = {
        'document_manager_guid': str(new_doc.document_guid),
        'filename': new_doc.file_display_name
    }
    post_resp = test_client.put(
        f'/documents/expected/{expected_doc.exp_document_guid}/document',
        headers=auth_headers['full_auth_header'],
        json=data)
    post_data = json.loads(post_resp.data.decode())
    assert post_resp.status_code == 200
    assert len(post_data['related_documents']) == document_count + 1
    assert any(
        str(new_doc.document_guid) == rel_doc['document_manager_guid']
        for rel_doc in post_data['related_documents'])
Exemple #9
0
def test_expected_documents_find_by_exp_document_guid(db_session):
    exp_doc = MineExpectedDocumentFactory.create_batch(size=BATCH_SIZE)[0]

    expected_document = MineExpectedDocument.find_by_exp_document_guid(
        str(exp_doc.exp_document_guid))
    assert expected_document.exp_document_guid == exp_doc.exp_document_guid