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']
예제 #2
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']
 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)
     self.assertEqual(0, len(v))
예제 #4
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)
 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']
 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)
     self.assertEqual(11, len(visit))
     for v in visit:
         self.assertEqual(v['lft']+1, v['rght'])
         self.assertEqual(1, v['depth'])
예제 #7
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']
 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
 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)
     self.assertEqual(11, len(visit))
     left = 1
     for v in visit:
         self.assertEqual(v['lft'], left)
         left += 2
예제 #10
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
예제 #11
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()
예제 #12
0
 def test_geo(self):
     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)
     self.assertEqual(10, len(visit))
     world = visit[0]
     self.assertEqual(1, world['id'])
     self.assertEqual(1, world['lft'])
     self.assertEqual(20, world['rght'])
     self.assertEqual(1, world['depth'])
     for v in visit:
         if v['id'] == 3:
             self.assertEqual(v['lft']+3, v['rght'])
             self.assertEqual(2, v['depth'])
         if v['id'] == 6:
             self.assertEqual(v['lft']+1, v['rght'])
             self.assertEqual(3, v['depth'])
예제 #13
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()
예제 #14
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']
    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']
예제 #16
0
 def test_buildings(self):
     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)
     self.assertEqual(5, len(visit))
     # Check that castle is present twice
     ids = [v['id'] for v in visit]
     self.assertEqual(2, ids.count(2))
     for v in visit:
         # Check that fortification has one child
         if v['id'] == 1:
             self.assertEqual(v['lft']+3, v['rght'])
             self.assertEqual(1, v['depth'])
         # Check that habitations has two children
         if v['id'] == 3:
             self.assertEqual(v['lft']+5, v['rght'])
             self.assertEqual(1, v['depth'])
         # Check that castle has no children
         if v['id'] == 2:
             self.assertEqual(v['lft']+1, v['rght'])
             self.assertEqual(2, v['depth'])