Example #1
0
 def test_unique_null_clash(self):
     conn = connect()
     baz = Baz.new(s2=None)
     conn.insert(Baz, baz)
     baz_list = conn.select(Baz)
     self.assertEquals([baz], baz_list)
     baz2 = Baz.new(s2=None)
     try:
         conn.insert(Baz, baz2)
     except conn.DbError, e:
         self.assertIn(
             e.args,
             [
                 ("column s3 is not unique",),
                 (
                     'duplicate key value violates unique constraint "baz_s3_key"\nDETAIL:  Key (s3)=() already exists.\n',
                 ),
                 (1062, "Duplicate entry '' for key 's3'"),
             ],
         )
Example #2
0
 def test_update_unique_clash(self):
     conn = connect()
     baz1 = Baz.new(f3=101, s3="alpha")
     baz2 = Baz.new(f3=23, s3="beta")
     baz3 = Baz.new(f3=42.42, s3="gamma")
     conn.insert(Baz, baz1)
     conn.insert(Baz, baz2)
     conn.insert(Baz, baz3)
     baz3["s3"] = "beta"
     try:
         conn.update(Baz, baz3, Baz.q.f3 == 42.42)
     except conn.DbError, e:
         self.assertIn(
             e.args,
             [
                 ("column s3 is not unique",),
                 ('duplicate key value violates unique constraint "baz_s3_key"\nDETAIL:  Key (s3)=(beta) already exists.\n',),
                 (1062, "Duplicate entry \'beta\' for key \'s3\'"),
                 ]
             )
Example #3
0
    def test_roundtrip_float_fidelity(self):
        before = 3.14159265358979323846264338327950288
        if connect == connect_sqlite:
            expected = before
        else:
            # XXX Postgres & Mysql roundtrip issues
            # Postgres: http://psycopg.lighthouseapp.com/projects/62710/tickets/145
            # MySQL: http://sourceforge.net/p/mysql-python/bugs/292/
            expected = 3.14159265358979000737349451810587198
        import math

        conn = connect()
        conn.insert(Baz, Baz.new(f3=before, s3="pi"))
        after = conn.select_one(Baz, Baz.q.s3 == "pi")["f3"]
        self.assertEquals(expected, after)