Beispiel #1
0
 def test__determine_path_5(self):
     db = db1.clone()
     q = join_.Join()
     q._determine_path(db.t_footers)
     self.assertEqual(len(q.tables), 5)
     self.assertIs(q.tables[0], db.t_footers)
     self.assertIs(q.tables[1], db.t_pages)
     self.assertIs(q.tables[2], db.t_reports)
     self.assertIs(q.tables[3], db.t_documents)
     self.assertIs(q.tables[4], db.t_headers)
Beispiel #2
0
 def test__jointype_setter_1(self):
     db = SampleDB()
     q = join_.Join(db.t_documents)
     self.assertEqual(q.default_jointype, join_.INNER_JOIN)
     q.default_jointype = join_.LEFT_JOIN
     self.assertEqual(q.default_jointype, join_.LEFT_JOIN)
     q.default_jointype = join_.RIGHT_JOIN
     self.assertEqual(q.default_jointype, join_.RIGHT_JOIN)
     q.default_jointype = join_.OUTER_JOIN
     self.assertEqual(q.default_jointype, join_.OUTER_JOIN)
     q.default_jointype = join_.INNER_JOIN
     self.assertEqual(q.default_jointype, join_.INNER_JOIN)
Beispiel #3
0
 def test__init_4(self):
     db = SampleDB()
     q = join_.Join(db.t_documents, jointype = join_.LEFT_JOIN)
     self.assertTrue(hasattr(q, '_root'))
     self.assertTrue(hasattr(q, '_tables'))
     self.assertEqual(q._default_jointype, join_.LEFT_JOIN)
     self.assertIsInstance(q._tables, table_.TableList)
     self.assertEqual(len(q._tables), len(db.tables))
     self.assertIs(q._tables[0], db.t_documents)
     self.assertIs(q._tables[1], db.t_reports)
     self.assertIs(q._tables[2], db.t_pages)
     self.assertIs(q._tables[3], db.t_headers)
     self.assertIs(q._tables[4], db.t_footers)
Beispiel #4
0
    def test__rows_2(self):
        University = declare(
            DataType, 'University',
            ('fullname', 'city'),
            plural = 'Universities'
        )
        UE = entityclass(University)

        db = db1.clone()
        db.t_universities = tableclass(University)()
        db.tables.insert(-1,db.t_universities)
        db.l_header_university = link_.Link(
                (db.t_headers, db.t_universities),
                ('university', 'header'),
                column = 'university')
        db.t_universities['UTH'] = UE(('Uniwersytet Techniczno-Humanistyczny w Radomiu', 'Radom'))
        db.t_universities['PW'] = UE(('Politechnika Warszawska', 'Warszawa'))
        db.t_universities['UJ'] = UE(('Uniwersytet Jagielloński', 'Kraków'))

        q = join_.Join(db.t_documents)
        e = [
            [0, 0, 0, 0, 'PW',  0],
            [0, 0, 1, 0, 'PW',  1],
            [0, 1, 2, 0, 'PW',  0],
            [1, 2, 3, 1, 'UTH', 0],
            [1, 2, 4, 1, 'UTH', 1]
        ]
        for i in range(len(e)):
            for j in range(len(e[i])):
                k = e[i][j]
                e[i][j] = db.tables[j].getrecord(k)

        r = q.rows()
        self.assertEqual(next(r), e[0])
        self.assertEqual(next(r), e[1])
        self.assertEqual(next(r), e[2])
        self.assertEqual(next(r), e[3])
        self.assertEqual(next(r), e[4])
        with self.assertRaises(StopIteration):
            next(r)
Beispiel #5
0
    def test__rows_1(self):
        db = db1.clone()
        q = join_.Join(db.t_documents)
        e = [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 1],
            [0, 1, 2, 0, 0],
            [1, 2, 3, 1, 0],
            [1, 2, 4, 1, 1]
        ]
        for i in range(len(e)):
            for j in range(len(e[i])):
                k = e[i][j]
                e[i][j] = db.tables[j].getrecord(k)

        r = q.rows()
        self.assertEqual(next(r), e[0])
        self.assertEqual(next(r), e[1])
        self.assertEqual(next(r), e[2])
        self.assertEqual(next(r), e[3])
        self.assertEqual(next(r), e[4])
        with self.assertRaises(StopIteration):
            next(r)
Beispiel #6
0
 def test__jointype_setter_2(self):
     db = SampleDB()
     q = join_.Join(db.t_documents)
     with self.assertRaisesRegex(ValueError, r'invalid join type %s' % repr('asdf')):
         q.default_jointype = 'asdf'
Beispiel #7
0
 def test__jointype_1(self):
     db = SampleDB()
     q = join_.Join(db.t_documents)
     self.assertEqual(q.default_jointype, join_.INNER_JOIN)
Beispiel #8
0
 def test__init_5(self):
     db = SampleDB()
     with self.assertRaisesRegex(ValueError, 'invalid join type %s' % repr('asdf')):
             join_.Join(db.t_documents, jointype = 'asdf')
Beispiel #9
0
 def test__init_2(self):
     msg = r'%s is not an instance of %s' % (repr('asdf'), repr(table_.Table))
     with self.assertRaisesRegex(TypeError, msg):
         join_.Join('asdf')
Beispiel #10
0
 def test__init_1(self):
     q = join_.Join()
     self.assertFalse(hasattr(q, '_root'))
     self.assertFalse(hasattr(q, '_tables'))
     self.assertEqual(q._default_jointype, join_.INNER_JOIN)