def test_get_documents_bundle_success(self): session_db = Session() session_db.documents_bundles.add( inserting.ManifestDomainAdapter(SAMPLE_ISSUES_KERNEL[0]) ) session_db.documents_bundles.add( inserting.ManifestDomainAdapter(SAMPLE_AOPS_KERNEL[0]) ) result = inserting.get_documents_bundle(session_db, self.data) self.assertIsInstance(result, DocumentsBundle) self.assertEqual(result.id(), "0001-3714-1998-v29-n3")
def test_register_documents_in_documents_bundle( self, mk_link_documents_bundle_with_documents, mk_read_json_file): documents = { "JwqGdMDrdcV3Z7MFHgtKvVk": { "acron": "aiss", "eissn": None, "issn": "0036-3634", "number": "04", "order": "00349", "pid": "S0021-25712009000400001", "pissn": "0036-3634", "supplement": None, "volume": "45", "year": "2009", } } journals = [SAMPLES_JOURNAL] mk_read_json_file.side_effect = [journals, documents] err_filename = os.path.join(config.get("ERRORS_PATH"), "insert_documents_in_bundle.err") session_db = Session() manifest = inserting.ManifestDomainAdapter(SAMPLE_ISSUES_KERNEL[0]) session_db.documents_bundles.add(manifest) inserting.register_documents_in_documents_bundle( session_db, "/tmp/documents.json", "/tmp/journals.json") self.assertEqual(os.path.isfile(err_filename), True) with open(err_filename) as fp: content = fp.read() self.assertEqual(content, "0036-3634-2009-v45-n4\n")
def test_create_aop_bundle_registers_aop_bundle(self, MockManifestDomainAdapter, mk_utcnow): mk_utcnow.return_value = "2019-01-02T05:00:00.000000Z" expected = { "_id": "0001-3714-aop", "created": "2019-01-02T05:00:00.000000Z", "updated": "2019-01-02T05:00:00.000000Z", "items": [], "metadata": {}, "id": "0001-3714-aop", } mk_bundle_manifest = Mock() MockManifestDomainAdapter.return_value = mk_bundle_manifest session_db = MagicMock() session_db.journals.fetch.return_value = inserting.ManifestDomainAdapter( manifest=SAMPLE_KERNEL_JOURNAL) inserting.create_aop_bundle(session_db, SAMPLE_KERNEL_JOURNAL["id"]) MockManifestDomainAdapter.assert_any_call(manifest=expected) session_db.documents_bundles.add.assert_called_once_with( data=mk_bundle_manifest) session_db.changes.add.assert_any_call({ "timestamp": "2019-01-02T05:00:00.000000Z", "entity": "DocumentsBundle", "id": "0001-3714-aop", })
def test_create_aop_bundle_uses_scielo_ids_generator_aops_bundle_id( self, mk_aops_bundle_id): session_db = MagicMock() session_db.journals.fetch.return_value = inserting.ManifestDomainAdapter( manifest=SAMPLE_KERNEL_JOURNAL) inserting.create_aop_bundle(session_db, "0001-3714") mk_aops_bundle_id.assert_called_once_with("0001-3714")
def test_create_aop_bundle_returns_bundle(self): session_db = Session() mocked_journal_data = inserting.ManifestDomainAdapter( manifest=SAMPLE_KERNEL_JOURNAL) session_db.journals.add(mocked_journal_data) result = inserting.create_aop_bundle(session_db, SAMPLE_KERNEL_JOURNAL["id"]) self.assertIsInstance(result, DocumentsBundle) self.assertEqual(result.id(), "0001-3714-aop")
def test_create_aop_bundle_links_aop_bundle_to_journal(self, mk_utcnow): mk_utcnow.return_value = "2019-01-02T05:00:00.000000Z" mocked_journal_data = inserting.ManifestDomainAdapter( manifest=SAMPLE_KERNEL_JOURNAL) mk_bundle_manifest = Mock() session_db = MagicMock() session_db.journals.fetch.return_value = mocked_journal_data inserting.create_aop_bundle(session_db, SAMPLE_KERNEL_JOURNAL["id"]) session_db.journals.update.assert_called() session_db.changes.add.assert_any_call({ "timestamp": "2019-01-02T05:00:00.000000Z", "entity": "Journal", "id": SAMPLE_KERNEL_JOURNAL["id"], }) self.assertEqual(mocked_journal_data.ahead_of_print_bundle, "0001-3714-aop")
def test_register_documents_in_documents_bundle( self, mk_link_documents_bundle_with_documents ): data1 = self.data data2 = dict( [ ("eissn", "0003-3714"), ("issn", "0003-3714"), ("year", "1998"), ("volume", "29"), ("number", "3"), ("supplement", None), ] ) documents_sorted_in_bundles = { "0001-3714-1998-29-03": { "items": ["0001-3714-1998-v29-n3-01", "0001-3714-1998-v29-n3-02"], "data": data1, }, "0003-3714-1998-29-03": { "items": ["0003-3714-1998-v29-n3-01", "0003-3714-1998-v29-n3-02"], "data": data2, }, } err_filename = os.path.join( config.get("ERRORS_PATH"), "insert_documents_in_bundle.err" ) session_db = Session() manifest = inserting.ManifestDomainAdapter(SAMPLE_ISSUES_KERNEL[0]) session_db.documents_bundles.add(manifest) inserting.register_documents_in_documents_bundle( session_db, documents_sorted_in_bundles ) self.assertEqual(os.path.isfile(err_filename), True) with open(err_filename) as fp: content = fp.read() self.assertEqual(content, "0003-3714-1998-29-03\n")
def setUp(self): self.session = Session() manifest = inserting.ManifestDomainAdapter(SAMPLE_ISSUES_KERNEL[0]) self.session.documents_bundles.add(manifest) self.documents_bundle = self.session.documents_bundles.fetch( manifest.id())