Ejemplo n.º 1
0
    def test_07_save_delete(self):
        # Work through acycle of saves and deletes to observe the outputs

        source = RequestFixtureFactory.record()
        acc = MonitorUKAccount()
        acc.save(blocking=True)

        req = ApiRequest(source, account=acc)
        req.save()

        dao = Request()
        req2 = dao.pull(req.request.id)
        assert req2 is not None
        assert req2.owner == acc.id
        assert req2.record == source
        assert req2.action == "update"

        # now publish the request
        PublicApi.publish(req2)
        time.sleep(2)

        # now pull the object as identified by its API identifier (which should be the DOI)
        source2 = deepcopy(source)
        source2["dc:title"] = "An update"
        next = ApiRequest.pull(req.id, account=acc)
        next.update(source2)
        next.save()

        # now, at this point we should have 2 request objects in the index.  One for the
        # original save, and one for the new save
        req3 = dao.pull(next.request.id)
        assert req3 is not None
        assert req3.owner == acc.id
        assert req3.record == source2
        assert req3.action == "update"

        # now issue a delete on the same record
        next.delete()

        # by now we should have 3 request objects in the index, 2 for the above updates
        # and one for the delete request
        req4 = dao.pull(next.request.id)
        assert req4 is not None
        assert req4.owner == acc.id
        assert req4.record == source2
        assert req4.action == "delete"
Ejemplo n.º 2
0
    def test_09_responses(self):
        # Check that we get appropriate JSON responses

        source = RequestFixtureFactory.record()
        acc = MonitorUKAccount()
        acc.save(blocking=True)

        req = ApiRequest(source, account=acc)
        req.save()

        # have a look at what we'd expect the responses to be if this was a create
        cr = req.created_response()
        assert cr.get("status") == "created"
        assert cr.get("request_id") is not None
        assert cr.get("public_id") == "10.1234/me"

        # now look at the responses if this was an update/append
        ur = req.updated_response()
        assert ur.get("status") == "updated"
        assert ur.get("request_id") is not None
        assert ur.get("public_id") == "10.1234/me"

        # now look at a delete
        dr = req.deleted_response()
        assert dr.get("status") == "deleted"
        assert dr.get("request_id") is not None
        assert dr.get("public_id") == "10.1234/me"

        # just make a quick check to be sure that if no DOI is present, we get the right kind of info in the public_id
        source2 = RequestFixtureFactory.record()
        source2["dc:identifier"] = [{"type" : "pmcid", "id" : "PMC1234"}]
        req2 = ApiRequest(source2, account=acc)
        req2.save()

        cr = req.created_response()
        assert cr.get("public_id") == req.id

        ur = req.updated_response()
        assert ur.get("public_id") == req.id

        dr = req.deleted_response()
        assert dr.get("public_id") == req.id