def setUp(self): db = Database() class Student(db.Entity): id = PrimaryKey(int) name = Required(unicode) group = Required('Group') class Group(db.Entity): number = PrimaryKey(int) students = Set(Student) self.db = db self.Group = Group self.Student = Student setup_database(db) with db_session: g101 = Group(number=101) g102 = Group(number=102) g103 = Group(number=103) s1 = Student(id=1, name='Student1', group=g101) s2 = Student(id=2, name='Student2', group=g101) s3 = Student(id=3, name='Student3', group=g102) s4 = Student(id=4, name='Student3', group=g102) db_session.__enter__()
def setUp(self): db = self.db = Database() class Group(db.Entity): number = PrimaryKey(int) students = Set('Student', volatile=True) class Student(db.Entity): id = PrimaryKey(int) name = Required(str) group = Required('Group') courses = Set('Course') class Course(db.Entity): id = PrimaryKey(int) name = Required(str) students = Set('Student', volatile=True) setup_database(db) with db_session: g1 = Group(number=123) s1 = Student(id=1, name='A', group=g1) s2 = Student(id=2, name='B', group=g1) c1 = Course(id=1, name='C1', students=[s1, s2]) c2 = Course(id=2, name='C1', students=[s1]) self.Group = Group self.Student = Student self.Course = Course
def setUpClass(cls): setup_database(db) with db_session: d1 = Department(number=44) d2 = Department(number=43) g1 = Group(id=1, dept=d1) g2 = Group(id=2, dept=d2) s1 = Student(id=1, name='S1', group=g1, scholarship=0) s2 = Student(id=2, name='S2', group=g1, scholarship=100) s3 = Student(id=3, name='S3', group=g2, scholarship=500) c1 = Course(name='Math', semester=1, dept=d1) c2 = Course(name='Economics', semester=1, dept=d1, credits=3) c3 = Course(name='Physics', semester=2, dept=d2) t1 = Teacher(id=101, name="T1") t2 = Teacher(id=102, name="T2") Grade(student=s1, course=c1, value='C', teacher=t2, date=date(2011, 1, 1)) Grade(student=s1, course=c3, value='A', teacher=t1, date=date(2011, 2, 1)) Grade(student=s2, course=c2, value='B', teacher=t1) r1 = Room(name='Room1') r2 = Room(name='Room2') r3 = Room(name='Room3') g1.rooms = [r1, r2] g2.rooms = [r2, r3] c1.students.add(s1) c1.students.add(s2) c2.students.add(s2) setup_database(db2)
def setUpClass(cls): setup_database(db) with db_session: d1 = Department(number=1) d2 = Department(number=2) d3 = Department(number=3) g1 = Group(number=101, department=d1) g2 = Group(number=102, department=d1) g3 = Group(number=201, department=d2) c1 = Course(name='C1', department=d1) c2 = Course(name='C2', department=d1) c3 = Course(name='C3', department=d2) c4 = Course(name='C4', department=d2) c5 = Course(name='C5', department=d3) s1 = Student(name='S1', group=g1, courses=[c1, c2]) s2 = Student(name='S2', group=g1, courses=[c1, c3]) s3 = Student(name='S3', group=g1, courses=[c2, c3]) s4 = Student(name='S4', group=g2, courses=[c1, c2]) s5 = Student(name='S5', group=g2, courses=[c1, c2]) s6 = Student(name='A', group=g3, courses=[c5])
def setUpClass(cls): setup_database(db) with db_session: Person(id=1, first_name='Alexander', last_name='Tischenko', age=23, value=1.4) Person(id=2, first_name='Alexander', last_name='Kozlovskiy', age=42, value=1.2) Person(id=3, first_name='Arthur', last_name='Pendragon', age=54, value=1.33) Person(id=4, first_name='Okita', last_name='Souji', age=15, value=2.1) Person(id=5, first_name='Musashi', last_name='Miyamoto', age=None, value=0.9) Person(id=6, first_name='Jeanne', last_name="d'Arc", age=30, value=43.212)
def setUpClass(cls): setup_database(db) with orm.db_session: p1 = Person(id=1, name='Andrew', lastName='Bodroue', age=40, rate=0.980000000001, salaryRate=0.98000001) p2 = Person(id=2, name='Vladimir', lastName='Andrew ', nickName='vlad ') p3 = Person(id=3, name='Nick', lastName='Craig', middleName=None, timeStmp='2010-12-10 14:12:09.019473', vehicle='dodge')
def setUpClass(cls): setup_database(db) with db_session: g41 = Group(number=41, department=101) g42 = Group(number=42, department=102) g43 = Group(number=43, department=102) g44 = Group(number=44, department=102) s1 = Student(id=1, name="Joe", scholarship=None, group=g41) s2 = Student(id=2, name="Bob", scholarship=100, group=g41) s3 = Student(id=3, name="Beth", scholarship=500, group=g41) s4 = Student(id=4, name="Jon", scholarship=500, group=g42) s5 = Student(id=5, name="Pete", scholarship=700, group=g42) s6 = Student(id=6, name="Mary", scholarship=300, group=g44) Math = Subject(name="Math") Physics = Subject(name="Physics") History = Subject(name="History") g41.subjects = [Math, Physics, History] g42.subjects = [Math, Physics] g43.subjects = [Physics] Mark(value=5, student=s1, subject=Math) Mark(value=4, student=s2, subject=Physics) Mark(value=3, student=s2, subject=Math) Mark(value=2, student=s2, subject=History) Mark(value=1, student=s3, subject=History) Mark(value=2, student=s3, subject=Math) Mark(value=2, student=s4, subject=Math)
def setUpClass(cls): setup_database(db) with db_session: g1 = Group(id=1) g2 = Group(id=2) p = Passport(id=1) Student(id=1, first_name='Mashu', last_name='Kyrielight', login='******', group=g1) Student(id=2, first_name='Okita', last_name='Souji', login='******', group=g1) Student(id=3, first_name='Francis', last_name='Drake', group=g2, graduated=True) Student(id=4, first_name='Oda', last_name='Nobunaga', group=g2, graduated=True) Student(id=5, first_name='William', last_name='Shakespeare', group=g2, graduated=True, passport=p)
def setUp(self): db = self.db class Genre(db.Entity): name = orm.Required(str) artists = orm.Set('Artist') class Hobby(db.Entity): name = orm.Required(str) artists = orm.Set('Artist') class Artist(db.Entity): name = orm.Required(str) age = orm.Optional(int) hobbies = orm.Set(Hobby) genres = orm.Set(Genre) setup_database(db) with orm.db_session: pop = Genre(name='Pop') Artist(name='Sia', age=40, genres=[pop]) Hobby(name='Swimming') pony.options.INNER_JOIN_SYNTAX = True
def test_composite_key_update(self): db = self.db = Database() class Entity1(db.Entity): s = Set('Entity3') class Entity2(db.Entity): s = Set('Entity3') class Entity3(db.Entity): a = Required(Entity1) b = Required(Entity2) composite_key(a, b) setup_database(db) with db_session: x = Entity1(id=1) y = Entity2(id=1) z = Entity3(id=1, a=x, b=y) with db_session: z = Entity3[1] self.assertEqual(z.a, Entity1[1]) self.assertEqual(z.b, Entity2[1]) with db_session: z = Entity3[1] w = Entity1(id=2) z.a = w with db_session: z = Entity3[1] self.assertEqual(z.a, Entity1[2]) self.assertEqual(z.b, Entity2[1])
def setUpClass(cls): setup_database(db) with db_session: g1 = Group(number=1) g2 = Group(number=2) c1 = Course(name='Math') c2 = Course(name='Physics') c3 = Course(name='Computer Science') Student(id=1, name='S1', group=g1, gpa=3.1, courses=[c1, c2], biography='some text') Student(id=2, name='S2', group=g1, gpa=3.2, scholarship=100, dob=date(2000, 1, 1)) Student(id=3, name='S3', group=g1, gpa=3.3, scholarship=200, dob=date(2001, 1, 2), courses=[c2, c3])
def setUpClass(cls): setup_database(db) with db_session: x1 = X(id=1) x2 = X(id=2, parent=x1) x3 = X(id=3, parent=x1) x4 = X(id=4, parent=x3) x5 = X(id=5, parent=x3) x6 = X(id=6, parent=x5) x7 = X(id=7, parent=x3) x8 = X(id=8, parent=x7) x9 = X(id=9, parent=x7) x10 = X(id=10) x11 = X(id=11, parent=x10) x12 = X(id=12, parent=x10) y1 = Y(id=1) y2 = Y(id=2, parent=y1) y3 = Y(id=3, parent=y1) y4 = Y(id=4, parent=y3) y5 = Y(id=5, parent=y3) y6 = Y(id=6, parent=y5) y7 = Y(id=7, parent=y3) y8 = Y(id=8, parent=y7) y9 = Y(id=9, parent=y7) y10 = Y(id=10) y11 = Y(id=11, parent=y10) y12 = Y(id=12, parent=y10)
def setUpClass(cls): setup_database(db) with db_session: p1 = Person(id=1, first_name='Alexander', last_name='Kozlovsky', favorite_color='white') p2 = Person(id=2, first_name='Alexei', last_name='Malashkevich', favorite_color='green') p3 = Person(id=3, first_name='Vitaliy', last_name='Abetkin') p4 = Person(id=4, first_name='Alexander', last_name='Tischenko', favorite_color='blue') c1 = Car(id=1, brand='Peugeot', model='306', owner=p1, year=2006, price=14000, color='red') c2 = Car(id=2, brand='Honda', model='Accord', owner=p1, year=2007, price=13850, color='white') c3 = Car(id=3, brand='Nissan', model='Skyline', owner=p2, year=2008, price=29900, color='black') c4 = Car(id=4, brand='Volkswagen', model='Passat', owner=p1, year=2012, price=9400, color='blue') c5 = Car(id=5, brand='Koenigsegg', model='CCXR', owner=p4, year=2016, price=4850000, color='white') c6 = Car(id=6, brand='Lada', model='Kalina', owner=p4, year=2015, price=5000, color='white')
def setUpClass(cls): setup_database(db) with db_session: g1 = Group(id=1, major='Math') g2 = Group(id=2, major='Physics') s1 = Student(id=1, name='S1', group=g1) s2 = Student(id=2, name='S2', group=g1) s3 = Student(id=3, name='S3', group=g2)
def setUpClass(cls): setup_database(db) with db_session: d1 = Department(number=44) g1 = Group(number=101, dept=d1) Student(name='S1', group=g1) Student(name='S2', group=g1) Student(name='S3', group=g1)
def setUpClass(cls): if db_params['provider'] not in ('sqlite', 'postgres'): raise unittest.SkipTest('Arrays are only available for SQLite and PostgreSQL') setup_database(db) with db_session: Foo(id=1, a=1, b=3, c=-2, array1=[10, 20, 30, 40, 50], array2=[1.1, 2.2, 3.3, 4.4, 5.5], array3=['foo', 'bar'])
def setUpClass(cls): setup_database(db) with db_session: Student(id=1, name="B", scholarship=None, group=41) Student(id=2, name="C", scholarship=700, group=41) Student(id=3, name="A", scholarship=500, group=42) Student(id=4, name="D", scholarship=500, group=43) Student(id=5, name="E", scholarship=700, group=42)
def setUpClass(cls): setup_database(db) with db_session: Student(id=1, name="Ann", unstripped="Ann", foo='Abcdef', bar='b%d') Student(id=2, name="Bob", unstripped=" Bob ", foo='Ab%def', bar='b%d') Student(id=3, name="Beth", unstripped=" Beth ", foo='Ab_def', bar='b%d') Student(id=4, name="Jonathan", unstripped="\nJonathan\n") Student(id=5, name="Pete", unstripped="\n Pete\n ")
def setUpClass(cls): setup_database(db) with db_session: g1 = Group(id=1, number='g111') g2 = Group(id=2, number='g222') s1 = Student(id=1, name='S1', group=g1) s2 = Student(id=2, name='S2', group=g1) s3 = Student(id=3, name='S3', group=g2)
def setUp(self): setup_database(db) with db_session: c1 = Country(id=1, name='Russia') c2 = Country(id=2, name='Japan') Person(id=1, name='Alexander Nevskiy', country=c1) Person(id=2, name='Raikou Minamoto', country=c2) Person(id=3, name='Ibaraki Douji', country=c2)
def setUp(self): setup_database(db) with db_session: x1 = X(id=123) y1 = Y(id=456) b1 = B(id=day) c1 = C(x=x1, y=y1) A(b=b1, c=c1)
def setUpClass(cls): setup_database(db) with orm.db_session: pop = Genre(name='pop') rock = Genre(name='rock') Artist(name='Sia', age=40, genres=[pop, rock]) Artist(name='Lady GaGa', age=30, genres=[pop])
def setUpClass(cls): setup_database(db) with db_session: Person(id=1, name='John') Person(id=2, name='Mary') Person(id=3, name='Bob') Person(id=4, name='Mike') Person(id=5, name='Ann')
def test_str_max_len(self): db = self.db class Entity1(db.Entity): a = Required(str, 10) setup_database(db) with db_session: obj = Entity1(a='1234567890' * 1000)
def test_py_check_5(self): db = self.db class Entity1(db.Entity): a = Optional(date, py_check=lambda val: val.year >= 2000) setup_database(db) with db_session: obj = Entity1(a=date(2010, 1, 1))
def test_py_check_2(self): db = self.db class Entity1(db.Entity): a = Required(int, py_check=lambda val: val > 5 and val < 10) setup_database(db) with db_session: obj = Entity1(a=7)
def setUp(self): self.db = Database() class X(self.db.Entity): a = PrimaryKey(int) b = Optional(int) self.X = X setup_database(self.db) with db_session: x1 = X(a=1, b=1) x2 = X(a=2, b=2)
def setUpClass(cls): setup_database(db) with db_session: g1 = Group(id=1, major='Math') g2 = Group(id=2, major='Physics') s1 = Student(id=1, name='S1', age=19, email='*****@*****.**', group=g1) s2 = Student(id=2, name='S2', age=21, email='*****@*****.**', group=g1) s3 = Student(id=3, name='S3', email='*****@*****.**', group=g2) c1 = Course(id=1, name='Math', semester=1) c2 = Course(id=2, name='Math', semester=2) c3 = Course(id=3, name='Physics', semester=1)
def test_5(self): db = self.db = Database() class Person(self.db.Entity): name = Required(str) group = Set('Group', cascade_delete=True) class Group(self.db.Entity): persons = Required(Person, cascade_delete=True) setup_database(db)
def setUpClass(cls): db = cls.db = Database() class TestPost(db.Entity): category = Optional('TestCategory') name = Optional(str, default='Noname') class TestCategory(db.Entity): posts = Set(TestPost) setup_database(db)