-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_test.py
44 lines (29 loc) · 1.04 KB
/
rest_test.py
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
34
35
36
37
38
39
40
41
42
43
44
import unittest
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.orm import sessionmaker
from rest import DBApi
Base = declarative_base()
class NTest(Base):
__tablename__ = 'test'
uid = Column(Integer, primary_key=True)
value = Column(Integer)
class DBTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
engine = create_engine('sqlite://')
cls.sessionmaker = sessionmaker(bind=engine)
cls.dbapi = DBApi(NTest)
Base.metadata.create_all(engine)
def test_db(self):
session = self.sessionmaker()
key = self.dbapi.create(session, {'uid': 1, 'value': 2})
session.commit()
to_get = self.dbapi._get_dbobj(session, 1)
self.assertEquals(2, to_get.value)
assert self.dbapi.update(session, 1, {'value': 5})
session.commit()
to_get = self.dbapi._get_dbobj(session, 1)
self.assertEquals(5, to_get.value)
if __name__ == '__main__':
unittest.main()