forked from fernandojunior/python-sqlite-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
33 lines (27 loc) · 739 Bytes
/
tests.py
File metadata and controls
33 lines (27 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from random import random
from orm import Database
db = Database('db.sqlite.test')
class Post(db.Model):
random = float
text = str
def __init__(self, text):
self.text = text
self.random = random()
try:
post = Post('Hello World').save()
assert(post.id == 1)
post.text = 'Hello Mundo'
post.update()
db.commit()
assert(post.text == 'Hello Mundo')
post.delete()
db.commit()
objects = Post.manager()
objects.save(Post('Hello World'))
assert(set(objects.get(2).public.keys()) == set(['id', 'text', 'random']))
assert(isinstance(objects.get(2).random, float))
db.close()
assert(list(objects.all()) == [])
finally:
os.remove('db.sqlite.test')