-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
43 lines (33 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
import unittest
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from token_auth.models import Token
from users.models import User
class TestTokenApp(unittest.TestCase):
def setUp(self):
# First, create an instance of the Testbed class.
self.testbed = testbed.Testbed()
# Then activate the testbed, which prepares the service stubs for use.
self.testbed.activate()
# Next, declare which service stubs you want to use.
self.testbed.init_datastore_v3_stub()
# Clear ndb's in-context cache between tests.
# This prevents data from leaking between tests.
ndb.get_context().clear_cache()
def tearDown(self):
self.testbed.deactivate()
def test_creation(self):
""" Should create a token. """
print 'Testing creation'
user_info = User.create_user()
user = User.get_by_id(user_info['user_id'])
token = Token()
token.user = user
token.put()
results = Token.query().fetch(2)
self.assertEqual(1, len(results))
self.assertEqual(user, results[0].user)
def test_validation(self):
""" Should return False when the token expires. """
if __name__ == "__main__":
unittest.main()