forked from lithammer/passbook_flask_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
49 lines (36 loc) · 1.26 KB
/
tests.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
45
46
47
48
49
# -*- coding: utf-8 -*-
import os
import unittest
import tempfile
from datetime import datetime
from flask.ext.sqlalchemy import SQLAlchemy
from app import app, db, Pass, Registration
class PassbookTestCase(unittest.TestCase):
def setUp(self):
temp = tempfile.mkstemp()
self.temp = temp
self.db_fd = temp[0]
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % temp[1]
app.config['TESTING'] = True
self.app = app.test_client()
SQLAlchemy.create_all(db)
def tearDown(self):
os.close(self.db_fd)
os.unlink(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', ''))
def test_add_pass_and_registrations(self):
data = {
'foo': 57,
'bar': str(datetime.utcnow()),
'baz': 'Lorem ipsum dolar sit amet'
}
p = Pass('com.company.pass.example', 'ABC123', data)
db.session.add(p)
db.session.commit()
assert Pass.query.get(1)
r = Registration('123456789', '00000000 00000000 00000000 00000000 \
00000000 00000000 00000000 00000000', p)
db.session.add(r)
db.session.commit()
assert Registration.query.get(1)
if __name__ == '__main__':
unittest.main()