Ejemplo n.º 1
0
    def test_18_enhancement(self):
        # Check we can create and work with Enhancement model objects

        # first make a blank one
        req = Enhancement()

        # now make one around the fixture
        source = EnhancementFixtureFactory.example()
        req = Enhancement(source)
        pub = req.make_public_apc()
        assert isinstance(pub, PublicAPC)
        assert pub.record == req.record

        # make one with a broken source
        broken = {"whatever" : "broken"}
        with self.assertRaises(dataobj.DataStructureException):
            req = Enhancement(broken)

        # now make one bit by bit
        req = Enhancement()
        req.record = source.get("record")

        # now make it broken
        req = Enhancement()
        with self.assertRaises(dataobj.DataStructureException):
            req.record = {"random" : "stuff"}
Ejemplo n.º 2
0
    def test_12_publish_enhancement(self):
        # Publish an Enhancement where no public record exists

        source = EnhancementFixtureFactory.example()
        en = Enhancement(source)
        pub = PublicApi.publish(en)

        # check that no public record was saved
        assert pub.id is None
        dao = PublicAPC()
        pubs = [p for p in dao.iterall()]
        assert len(pubs) == 0
Ejemplo n.º 3
0
    def test_13_process_ehnancements_cycle(self):
        # Run through the process of processing an enhancement

        source = EnhancementFixtureFactory.example()
        if "id" in source:
            del source["id"]

        pub_dao = PublicAPC()
        wfs_dao = WorkflowState()

        # first make a public record for us to enhance
        first = PublicAPCFixtureFactory.example()
        del first["record"]["dc:title"]
        pub = PublicAPC(first)
        pub.save(blocking=True)

        # now create an enhancements on the record
        second = deepcopy(source)
        second["record"]["dc:title"] = "Update"
        second["created_date"] = "2002-01-01T00:00:00Z"
        en = Enhancement(second)
        en.public_id = pub.id
        en.save(blocking=True)

        # run the job
        WorkflowApi.process_enhancements()

        time.sleep(2)

        # check that the workflow state was created
        wfs = wfs_dao.pull("enhancements")
        assert wfs is not None
        assert wfs.last_request == en.created_date
        assert wfs.already_processed == [en.id]

        # check the public record was updated
        pubs = pub_dao.find_by_doi("10.1234/me")
        assert len(pubs) == 1
        assert pubs[0].record.get("dc:title") == "Update"

        # now run an update with the same date, to observe the difference in the workflow state
        third = deepcopy(source)
        third["record"]["dc:title"] = "Update 2"
        third["created_date"] = "2002-01-01T00:00:00Z"
        en2 = Enhancement(third)
        en2.public_id = pub.id
        en2.save(blocking=True)

        # run the job again
        WorkflowApi.process_enhancements()

        time.sleep(2)

        # check the public record was updated
        pubs = pub_dao.find_by_doi("10.1234/me")
        assert len(pubs) == 1
        assert (
            pubs[0].record.get("dc:title") == "Update"
        )  # should not have been updated, since data was already present

        # check that the workflow state was updated
        wfs = wfs_dao.pull("enhancements")
        assert wfs is not None
        assert wfs.last_request == en2.created_date
        assert wfs.already_processed == [en.id, en2.id]  # processed records should have been appended