Exemple #1
0
    def test_buildings(self):
        from skosprovider_sqlalchemy.models import (Concept as ConceptModel)

        buildingprovider = _get_buildings()
        cs = self._get_cs()
        self.session.add(cs)
        import_provider(buildingprovider, cs, self.session)
        vc = VisitationCalculator(self.session)
        visit = vc.visit(cs)
        assert len(visit) == 5
        # Check that castle is present twice
        ids = [
            self.session.query(ConceptModel).get(v['id']).concept_id
            for v in visit
        ]
        assert ids.count(2) == 2
        for v in visit:
            # Check that fortification has one child
            if v['id'] == 1:
                assert v['lft'] + 3 == v['rght']
                assert 1 == v['depth']
            # Check that habitations has two children
            if v['id'] == 3:
                assert v['lft'] + 5 == v['rght']
                assert 1 == v['depth']
            # Check that castle has no children
            if v['id'] == 2:
                assert v['lft'] + 1 == v['rght']
                assert 2 == v['depth']
Exemple #2
0
    def test_empty_provider(self):
        from skosprovider.providers import DictionaryProvider

        p = DictionaryProvider({'id': 'EMPTY'}, [])
        cs = self._get_cs()
        self.session.add(cs)
        import_provider(p, cs, self.session)
        vc = VisitationCalculator(self.session)
        v = vc.visit(cs)
        assert 0 == len(v)
Exemple #3
0
 def test_menu(self):
     csvprovider = _get_menu()
     cs = self._get_cs()
     self.session.add(cs)
     import_provider(csvprovider, cs, self.session)
     vc = VisitationCalculator(self.session)
     visit = vc.visit(cs)
     assert 11 == len(visit)
     for v in visit:
         assert v['lft'] + 1 == v['rght']
         assert 1 == v['depth']
Exemple #4
0
 def test_menu_sorted(self):
     csvprovider = _get_menu()
     cs = self._get_cs()
     self.session.add(cs)
     import_provider(csvprovider, cs, self.session)
     vc = VisitationCalculator(self.session)
     visit = vc.visit(cs)
     assert 11 == len(visit)
     left = 1
     for v in visit:
         assert v['lft'] == left
         left += 2
Exemple #5
0
def create_visitation(session):
    from skosprovider_sqlalchemy.utils import (VisitationCalculator)
    from skosprovider_sqlalchemy.models import (Visitation, ConceptScheme)
    vc = VisitationCalculator(session)
    conceptschemes = session.query(ConceptScheme).all()
    for cs in conceptschemes:
        visit = vc.visit(cs)
        for v in visit:
            vrow = Visitation(conceptscheme=cs,
                              concept_id=v['id'],
                              lft=v['lft'],
                              rght=v['rght'],
                              depth=v['depth'])
            session.add(vrow)
    session.commit()
Exemple #6
0
    def test_geo(self):
        from skosprovider_sqlalchemy.models import (Concept as ConceptModel)

        geoprovider = _get_geo()
        cs = self._get_cs()
        self.session.add(cs)
        import_provider(geoprovider, cs, self.session)
        vc = VisitationCalculator(self.session)
        visit = vc.visit(cs)
        assert 10 == len(visit)
        world = visit[0]
        assert self.session.query(ConceptModel).get(
            world['id']).concept_id == 1
        assert 1 == world['lft']
        assert 20 == world['rght']
        assert 1 == world['depth']
        for v in visit:
            if v['id'] == 3:
                assert v['lft'] + 3 == v['rght']
                assert 2 == v['depth']
            if v['id'] == 6:
                assert v['lft'] + 1 == v['rght']
                assert 3 == v['depth']