예제 #1
0
    def test_set_table(self):
        i = self.get_interface()
        s = self.get_schema()
        r = i.has_table(str(s))
        self.assertFalse(r)

        r = i.set_table(s)

        r = i.has_table(str(s))
        self.assertTrue(r)

        # make sure known indexes are there
        indexes = i.get_indexes(s)
        count = 0
        for known_index_name, known_index in s.indexes.items():
            for index_name, index_fields in indexes.items():
                if known_index.fields == index_fields:
                    count += 1

        self.assertEqual(len(s.indexes), count)

        # make sure more exotic datatypes are respected
        s_ref = self.get_schema()
        i.set_table(s_ref)
        s_ref_id = self.insert(i, s_ref, 1)[0]

        s = prom.Schema(
            self.get_table_name(),
            _id=Field(int, pk=True),
            one=Field(bool, True),
            two=Field(int, True, size=50),
            three=Field(decimal.Decimal),
            four=Field(float, True, size=10),
            six=Field(
                long,
                True,
            ),
            seven=Field(s_ref, False),
            eight=Field(datetime.datetime),
            nine=Field(datetime.date),
        )
        r = i.set_table(s)
        d = {
            'one': True,
            'two': 50,
            'three': decimal.Decimal('1.5'),
            'four': 1.987654321,
            'six': 40000,
            'seven': s_ref_id,
            'eight': datetime.datetime(2005, 7, 14, 12, 30),
            'nine': datetime.date(2005, 9, 14),
        }
        pk = i.insert(s, d)
        q = query.Query()
        q.is__id(pk)
        odb = i.get_one(s, q)
        #d['five'] = 1.98765
        for k, v in d.items():
            self.assertEqual(v, odb[k])
예제 #2
0
    def test_query_modified_table(self):
        i = self.get_interface()
        s = prom.Schema('test_table', one=Field(int, True))
        i.set_table(s)

        # Add new column
        s.set_field("two", Field(int, False))
        q = query.Query()
        q.is_two(None)

        # Test if query succeeds
        i.get_one(s, q)
예제 #3
0
 def test_set_table_postgres(self):
     """test some postgres specific things"""
     i = self.get_interface()
     s = prom.Schema(
         self.get_table_name(),
         _id=Field(int, pk=True),
         four=Field(float, True, size=10),
         five=Field(float, True),
         six=Field(long, True),
     )
     r = i.set_table(s)
     d = {
         'four': 1.987654321,
         'five': 1.98765,
         'six': 4000000000,
     }
     pk = i.insert(s, d)
     q = Query()
     q.is__id(pk)
     odb = i.get_one(s, q)
     for k, v in d.items():
         self.assertEqual(v, odb[k])