コード例 #1
0
ファイル: crud.py プロジェクト: JiscMonitor/monitor-uk
    def save(self):
        """
        Save the incoming request.  This passes the (validated) data on to the RequestApi for processing

        :return:
        """
        self.request = RequestApi.update(self.raw, account=self.account, public_id=self.public_id)
コード例 #2
0
ファイル: test_api.py プロジェクト: JiscMonitor/monitor-uk
    def test_01_request_update(self):
        # Create an update Request

        record = RequestFixtureFactory.record()

        acc = BasicAccount()
        acc.id = "test1"

        # without a public id
        r1 = RequestApi.update(record, acc)

        # with a public id
        r2 = RequestApi.update(record, acc, "01010101")

        # now check they were saved correctly
        assert r1 is not None
        assert r2 is not None

        r11 = r1.pull(r1.id)
        assert r11 is not None

        r21 = r2.pull(r2.id)
        assert r21 is not None
コード例 #3
0
ファイル: crud.py プロジェクト: JiscMonitor/monitor-uk
    def delete(self):
        """
        Delete the associated object.

        This passes to the RequestApi to raise a delete request, so does not necessarily happen immediately

        :return:
        """
        # only allow delete to be called on a record where the requester has a stake in it
        # in reality, this doesn't really matter, as a request with no stake will just have no
        # effect, but this may be a clearer reaction to the user's request, and also may cut down
        # on effect-less requests.
        if self.public_record is not None:
            if self.account.id not in self.public_record.list_owners():
                raise AuthorisationException("You may only request delete on a record where you have previously provided data")
        self.request = RequestApi.delete(self.raw, account=self.account, public_id=self.public_id)
コード例 #4
0
ファイル: test_api.py プロジェクト: JiscMonitor/monitor-uk
    def test_01_request_delete(self):
        # Create a delete request

        record = RequestFixtureFactory.record()

        acc = BasicAccount()
        acc.id = "test1"

        r = RequestApi.delete(record, acc, "01010101")

        # now check it was saved correctly
        assert r is not None

        r1 = r.pull(r.id)
        assert r1 is not None
        assert r1.owner == acc.id
        assert r1.action == "delete"
        assert r1.public_id == "01010101"
コード例 #5
0
ファイル: test_api.py プロジェクト: JiscMonitor/monitor-uk
    def test_10_find_request(self):
        # Find a Request through a number of routes

        source = RequestFixtureFactory.example()
        req = Request(source)
        req.save(blocking=True)

        time.sleep(2)

        source = RequestFixtureFactory.example()
        req1 = Request(source)
        req1.save(blocking=True)

        # document to form the basis of the queries
        source2 = RequestFixtureFactory.example()

        # create sources with one of each kind of identifier, then look them up using the
        # find_request_by_identifier method
        result = RequestApi.find_request_by_identifier("doi", "10.1234/me", "abcdefghij")
        assert result is not None
        assert result.created_date == req1.created_date

        result = RequestApi.find_request_by_identifier("pmid", "87654321", "abcdefghij")
        assert result is not None
        assert result.created_date == req1.created_date

        result = RequestApi.find_request_by_identifier("pmcid", "PMC1234", "abcdefghij")
        assert result is not None
        assert result.created_date == req1.created_date

        result = RequestApi.find_request_by_identifier("url", "http://example.com/whatever", "abcdefghij")
        assert result is not None
        assert result.created_date == req1.created_date

        # finally, ensure that you don't get a match when you shouldn't
        result = RequestApi.find_request_by_identifier("doi", "10.1234/another", "abcdefghij")
        assert result is None

        result = RequestApi.find_request_by_identifier("doi", "10.1234/me", "test")
        assert result is None