Ejemplo n.º 1
0
    def test_14_process_enhancements_exception(self):
        # What happens when processing an enhancement fails

        sources = EnhancementFixtureFactory.request_per_day("2001-01", 9)

        dois = ["10.1234/first", "10.1234/second", "10.1234/third"]

        # we're going to construct a series of enhancements for each doi
        for i in range(len(sources)):
            s = sources[i]
            doi_idx = i % 3  # iterate over the dois 3 times
            doi = dois[doi_idx]
            s["record"]["dc:identifier"] = [{"type": "doi", "id": doi}]
            en = Enhancement(s)
            en.save()

        time.sleep(2)

        # set up the mock
        PublicApi.publish = publish_mock

        # now run the process job back to the first day
        with self.assertRaises(TestException):
            WorkflowApi.process_enhancements()

        time.sleep(2)

        # we know this died during the 6th update request being processed,
        # so just check that the workflow state reflects that
        wfs_dao = WorkflowState()
        wfs = wfs_dao.pull("enhancements")
        assert wfs.last_request == "2001-01-05T00:00:00Z"
        assert len(wfs.already_processed) == 1
Ejemplo n.º 2
0
    def test_20_enhancement_iterator(self):
        # Check we can successfully iterate over enhancements

        sources = EnhancementFixtureFactory.request_per_day("2001-01", 10)

        for s in sources:
            req = Enhancement(s)
            req.save()

        time.sleep(2)

        dao = Enhancement()
        gen = dao.list_all_since("2001-01-01T00:00:00Z", page_size=5)   # set the page size small, to ensure the iterator has to work
        results = [x for x in gen]

        assert len(results) == 10

        dates = [r.created_date for r in results]
        comp = deepcopy(dates)
        comp.sort()     # this puts the dates in ascending order (i.e. oldest first)

        # the point of this comparison is to show that the results came out in the right order.
        # that is, oldest first
        assert dates == comp