Esempio n. 1
0
    def testCreateTables(self):
        sql1 = 'CREATE TABLE "team" (\n  "id" INTEGER PRIMARY KEY NOT NULL,\n  "name" VARCHAR(20) NOT NULL\n)'
        sql2 = """CREATE TABLE "member" (
  "id" INTEGER PRIMARY KEY NOT NULL,
  "team_id" INTEGER REFERENCES "team"("id") ON DELETE SET NULL ON UPDATE CASCADE,
  "first_name" VARCHAR(20) NOT NULL DEFAULT 'unknown',
  "last_name" VARCHAR(20) NOT NULL DEFAULT 'noname',
  "part" VARCHAR(10) NOT NULL,
  "age" INTEGER NOT NULL DEFAULT '16',
  UNIQUE ("first_name", "last_name")
)"""
        macaron.create_table(Team)
        self.assertEqual(macaron.history.lastsql, 'PRAGMA table_info("team")')
        self.assertEqual(macaron.history[1].sql, sql1)
        self.assertEqual(macaron.history[1].param_str, "[]")
        macaron.create_table(Member)
        self.assertEqual(macaron.history.lastsql, 'PRAGMA table_info("member")')
        self.assertEqual(macaron.history[1].sql, sql2)
        self.assertEqual(macaron.history[1].param_str, "[]")

        team = Team.create(name="Houkago Tea Time")

        # test for default values
        member = team.members.append(part="Vo")
        self.assertEqual(member.first_name, "unknown")
        self.assertEqual(member.last_name, "noname")
        self.assertEqual(member.part, "Vo")
        self.assertEqual(member.age, 16)

        # test for ordering
        team.members.append(first_name="Test1", part="Dr")
        team.members.append(first_name="Test2", part="Gt")
        ids = [3, 2, 1]
        for m in team.members:
            self.assertEqual(m.id, ids.pop(0))
        self.assertEqual(len(ids), 0)

        # test for ON DELETE SET NULL
        # This can work on sqlite3 >= 3.6.19
        team.delete()
        member = member.get(member.pk)
        if sqlite3.sqlite_version_info >= (3, 6, 19):
            self.assertEqual(member.team_id, None)
            self.assertEqual(member.team, None)
        else:
            print "Foreign key constraint works SQLite >= 3.6.19. Skip."

        team = Team.create(name="Houkago Tea Time")
        member.team_id = team.pk
        member.save()
        self.assertEqual(member.team_id, team.pk)
Esempio n. 2
0
    def setUp(self):
        macaron.macaronage(":memory:")
        macaron.create_table(Series)
        macaron.create_table(Group)
        macaron.create_table(Movie)
        macaron.create_table(Member)
        macaron.create_table(SubTitle)

        series1 = Series.create(name="Smile Precure")
        group1 = Group.create(name="Smile", series=series1)
        group2 = Group.create(name="Pink", series=series1)
        member1 = Member.create(curename="Happy", mygroup=group1, subgroup=group2, joined=datetime(2012, 2, 6))
        movie1 = Movie.create(title="NewStage")
        subtitle = SubTitle.create(title="Mirai no tomodachi", movie=movie1)
        member1.movies.append(movie1)

        series2 = Series.create(name="Happiness Charge Precure")
        group3 = Group.create(name="Happiness Charge", series=series2)
        group4 = Group.create(name="Purple", series=series2)
        member2 = Member.create(curename="Fortune", mygroup=group3, subgroup=group4, joined=datetime(2014, 2, 9))
        movie2 = Movie.create(title="NewStage2")
        subtitle2 = SubTitle.create(title="Eien no tomodachi", movie=movie2)
        member2.movies.append(movie2)
Esempio n. 3
0
    def setUp(self):
        macaron.macaronage(":memory:")
        macaron.create_table(Series)
        macaron.create_table(Group)
        macaron.create_table(Movie)
        macaron.create_table(Member)
        macaron.create_table(SubTitle)

        series1 = Series.create(name="Smile Precure")
        group1 = Group.create(name="Smile", series=series1)
        group2 = Group.create(name="Pink", series=series1)
        member1 = Member.create(curename="Happy", mygroup=group1, subgroup=group2, joined=datetime(2012, 2, 6))
        movie1 = Movie.create(title="NewStage")
        subtitle = SubTitle.create(title="Mirai no tomodachi", movie=movie1)
        member1.movies.append(movie1)

        series2 = Series.create(name="Happiness Charge Precure")
        group3 = Group.create(name="Happiness Charge", series=series2)
        group4 = Group.create(name="Purple", series=series2)
        member2 = Member.create(curename="Fortune", mygroup=group3, subgroup=group4, joined=datetime(2014, 2, 9))
        movie2 = Movie.create(title="NewStage2")
        subtitle2 = SubTitle.create(title="Eien no tomodachi", movie=movie2)
        member2.movies.append(movie2)
Esempio n. 4
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     macaron.create_table(Team)
     macaron.create_table(Member)
     macaron.create_table(Song)
Esempio n. 5
0
 def setUp(self):
     macaron.macaronage(":memory:")
     macaron.create_table(Member)
Esempio n. 6
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
Esempio n. 7
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
     macaron.create_table(Song)
     macaron.create_link_tables(Song)
Esempio n. 8
0
 def setUp(self):
     macaron.macaronage(dbfile=DB_FILE, lazy=True)
     macaron.create_table(MyRecord)
Esempio n. 9
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     #macaron.execute(SQL_TEAM)
     #macaron.execute(SQL_MEMBER)
     macaron.create_table(Team)
     macaron.create_table(Member)
Esempio n. 10
0
 def setUp(self):
     macaron.macaronage(dbfile=DB_FILE, lazy=True)
     #macaron.execute(sql_t_myrecord)
     macaron.create_table(MyRecord)
Esempio n. 11
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
Esempio n. 12
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     macaron.create_table(Team)
     macaron.create_table(Member)
     macaron.create_table(Song)
Esempio n. 13
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     #macaron.execute(SQL_TEAM)
     #macaron.execute(SQL_MEMBER)
     macaron.create_table(Team)
     macaron.create_table(Member)
Esempio n. 14
0
 def setUp(self):
     macaron.macaronage(dbfile=DB_FILE, lazy=True)
     #macaron.execute(sql_t_myrecord)
     macaron.create_table(MyRecord)