def test_draft_indexing(app, db, es, example_draft, indexer): """Test indexing of a draft.""" # Index document in ES assert indexer.index(example_draft)['result'] == 'created' # Retrieve document from ES data = current_search_client.get('draftsresources-drafts-draft-v1.0.0', id=example_draft.id, doc_type='_doc') # Loads the ES data and compare draft = Draft.loads(data['_source']) assert draft == example_draft assert draft.id == example_draft.id assert draft.revision_id == example_draft.revision_id assert draft.created == example_draft.created assert draft.updated == example_draft.updated assert draft.expires_at == example_draft.expires_at assert draft.parent == example_draft.parent assert draft.versions.is_latest_draft == \ example_draft.versions.is_latest_draft assert draft.versions.index == \ example_draft.versions.index # Check system fields assert draft.metadata == example_draft['metadata']
def test_draft_dump_load_idempotence(app, db, example_draft): """Test idempotence of dumps/loads.""" loaded_draft = Draft.loads(example_draft.dumps()) assert example_draft == loaded_draft # Parent was dumped and loaded assert example_draft.parent == loaded_draft.parent assert example_draft.versions.is_latest_draft \ == loaded_draft.versions.is_latest_draft # Test that SQLAlchemy model was loaded from the JSON and not DB. assert not inspect(loaded_draft.parent.model).persistent assert not inspect(loaded_draft.versions._state).persistent
def test_record_indexing(app, db, es, example_record, indexer): """Test indexing of a record.""" # Index document in ES assert indexer.index(example_record)['result'] == 'created' # Retrieve document from ES data = current_search_client.get('draftsresources-drafts-draft-v1.0.0', id=example_record.id, doc_type='_doc') # Loads the ES data and compare record = Draft.loads(data['_source']) assert record == example_record assert record.id == example_record.id assert record.revision_id == example_record.revision_id assert record.created == example_record.created assert record.updated == example_record.updated assert record.expires_at == example_record.expires_at # Check system fields record.metadata == example_record['metadata']