def test_matrix_creation_endpoint(client, session): bib = Bibliography(eid='123', description='lorem') session.add(bib) session.flush() response = client.post('/matrix', json={ 'bibliography': '123', 'fields': ['title', 'description'], }) assert response.status_code == 200 assert response.json().get('bibliography_eid') == '123'
def test_matrix_creation_endpoint_fails(client, session): bib = Bibliography(eid='123', description='lorem') session.add(bib) session.flush() response = client.post('/matrix', json={ 'bibliography': '1234', 'fields': ['title', 'description'], }) assert response.status_code == 404 assert 'message' in response.json()
def test_single_bibliography_existing(client, session): # Given an existing bibliography bib = Bibliography(eid='123', description='lorem') session.add(bib) session.commit() # When I ask for it res = client.get('/bibliography/123') # Then I get a successful response assert res.status_code == 200 # And the response is non empty assert res.json().get('eid') == '123' assert res.json().get('description') == 'lorem'
def test_bibliography_endpoint_when_many_bibliographies(client, session): # Create a bibliography bib = Bibliography(eid='345', description='lorem') session.add(bib) session.commit() # When I request the list bibliography res = client.get('/bibliography') # Then I get a successful response assert res.status_code == 200 # The response is non empty assert len(res.json()) == 1 # And has bibliographies assert any(b.get('eid') == '345' for b in res.json())
def test_document_endpoint_actually_returns_documents(client, session): # Given some records matching records in the database bib = Bibliography(eid='123', description='lorem') session.add(bib) session.flush() doc = Document(eid='345', bibliography_eid='123', title='lorem', keywords='{}', description='lorem', language='english', hash='alksdjksjdf') session.add(doc) session.commit() # When I request the documents with the given bibliography eid res = client.get('/document?bibliography=123') # Then I receive a successful response assert res.status_code == 200 # And the response is non empty assert len(res.json()) > 0
def test_individual_matrix_endpoint_existing(client, session): # Given some records matching records in the database bib = Bibliography(eid='123', description='lorem') session.add(bib) session.flush() mat = TermDocumentMatrix( eid='345', bibliography_eid='123', bibliography_options='', processing_options='', term_list_path='', matrix_path='', ) session.add(mat) session.commit() # When I request the matrix with the eid res = client.get('/matrix/345') # Then I receive a successful response assert res.status_code == 200 # And the response is non empty assert len(res.json()) > 0
def test_matrix_endpoint_when_there_are_matrix(client, session): # Given some records matching records in the database bib = Bibliography(eid='123', description='lorem') session.add(bib) session.flush() mat = TermDocumentMatrix( eid='345', bibliography_eid='123', bibliography_options='', processing_options='', term_list_path='', matrix_path='', ) session.add(mat) session.commit() # When I request the documents with the given bibliography eid res = client.get('/matrix') # Then I receive a successful response assert res.status_code == 200 # The response is non empty assert len(res.json()) == 1 # And has matrix assert any(m.get('eid') == '345' for m in res.json())