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_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"]]))