Ejemplo n.º 1
0
    def test_distinct_cmodels(self, mocksunburnt, mockrequests):
        # set empty response
        mockrequests.codes.ok = 200
        mocksession = mockrequests.Session.return_value
        mocksession.get.return_value.status_code = 200
        mocksession.get.return_value.json.return_value = {}

        index = SiteIndex("http://foo/index", "foo")
        cmodels = {
            "coll": "info:fedora/emory-control:Collection-1.1",
            "audio": "info:fedora/emory-control:EuterpeAudio-1.0",
            "item": "info:fedora/emory-control:Item-1.0",
        }
        # set some content model combinations for testing
        index.content_models = [
            set([cmodels["coll"]]),
            set([cmodels["audio"]]),
            set([cmodels["coll"], cmodels["audio"]]),
            set([cmodels["item"]]),
            set([cmodels["audio"], cmodels["item"]]),
        ]
        distinct_cmodels = index.distinct_content_models()
        # each cmodel should be included once and only once
        self.assert_(cmodels["coll"] in distinct_cmodels)
        self.assert_(cmodels["audio"] in distinct_cmodels)
        self.assert_(cmodels["item"] in distinct_cmodels)
        self.assertEqual(len(cmodels.keys()), len(distinct_cmodels))
Ejemplo n.º 2
0
    def test_index_item(self, mocksunburnt, mockrequests):
        # return empty json data for index init/load config
        mockrequests.codes.ok = 200
        mocksession = mockrequests.Session.return_value
        mocksession.get.return_value.status_code = 200
        mocksession.get.return_value.json.return_value = {}
        index = SiteIndex("test-site-url", "test-site")
        testpid = "test:abc1"
        # replace solr interface with a mock we can inspect
        index.solr_interface = Mock()

        index_data = {"foo": "bar", "baz": "qux"}
        mockresponse = mocksession.get.return_value
        mockresponse.json.return_value = index_data
        mockresponse.status_code = 200

        indexed = index.index_item(testpid)
        # solr 'add' should be called with data returned via index data webservice
        index.solr_interface.add.assert_called_with(index_data)
        self.assertTrue(indexed, "index_item should return True on success")

        # solr error on attempt to add should be re-raised
        index.solr_interface.add.side_effect = SolrError
        self.assertRaises(SolrError, index.index_item, testpid)

        mocksession.get.side_effect = Exception
        # error on attempt to read index data should be raised as a recoverable error
        self.assertRaises(IndexDataReadError, index.index_item, testpid)
Ejemplo n.º 3
0
 def test_delete_item(self, mocksunburnt, mockrequests):
     # return empty json data for index init/load config
     mocksession = mockrequests.Session.return_value
     mocksession.get.return_value.status_code = 200
     mockrequests.codes.ok = 200
     mocksession.get.return_value.json.return_value = {}
     index = SiteIndex("test-site-url", "site name")
     index.solr_interface = Mock()
     keyfield = "Pid"
     index.solr_interface.schema.unique_field.name = keyfield
     testpid = "test:abc1"
     index.delete_item(testpid)
     index.solr_interface.delete.assert_called_with({keyfield: testpid})
Ejemplo n.º 4
0
    def test_indexes_item(self, mocksunburnt, mockrequests):
        mockrequests.codes.ok = 200
        mockrequests.Session.return_value.get.return_value.status_code = 200
        mockrequests.Session.return_value.get.return_value.json.return_value = {}
        index = SiteIndex("test-site-url", "test-site")
        # define some content models and sets of cmodels for testing
        cmodels = {
            "item": "info:fedora/test:item",
            "item-plus": "info:fedora/test:item-plus",
            "group": "info:fedora/test:group",
            "other": "info:fedora/test:other",
        }
        index.content_models = [
            set([cmodels["item"]]),
            set([cmodels["item"], cmodels["item-plus"]]),
            set([cmodels["group"]]),
        ]

        # single cmodel in a group
        self.assertTrue(index.indexes_item([cmodels["item"]]))
        # single cmodel not included anywhere in our sets
        self.assertFalse(index.indexes_item([cmodels["other"]]))
        # single cmodel - only included with another cmodel, not sufficient by itself
        self.assertFalse(index.indexes_item([cmodels["item-plus"]]))

        # two cmodels matching
        self.assertTrue(index.indexes_item([cmodels["item"], cmodels["item-plus"]]))
        # two cmodels - only one matches
        self.assertFalse(index.indexes_item([cmodels["item-plus"], cmodels["other"]]))

        # superset - all required cmodels, plus others
        self.assertTrue(index.indexes_item([cmodels["item"], cmodels["item-plus"], cmodels["other"]]))