Ejemplo n.º 1
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"]]))