class Test(unittest.TestCase):
    

    def setUp(self):
        # Setup mock GAE Data Store
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.user_datastore = UserAppengineDataStore()

    def tearDown(self):
        self.testbed.deactivate()


    def testFetch(self):
        user = UserData(username='******', password='******')
        user.put()
        user_id = user.key().id()
        actual = self.user_datastore.fetch(user_id)
        self.assertEquals(user.username, actual.username, "Found user: "******"Found user_id: " + str(actual.user_id))

    def testSave(self):
        user = UserData(username='******', password='******')
        new_user = self.user_datastore.save(user)
        user_id = user.key().id()
        actual = self.user_datastore.fetch(user_id)
        self.assertEquals(user.username, actual.username, "Found user: "******"Found user: "******"User count: " + str(users.count()))
        self.assertTrue(new_user1.user_id ==1, 'New user_id for user1: ' + str(new_user1.user_id))
        self.assertTrue(new_user2.user_id ==2, 'New user_id for user2: ' + str(new_user2.user_id))
#        count = 0
#         for user in users:
#            count += 1
#            self.assertTrue(user.user_id == count)
           
    def testFetchByUsername(self): 
        user1 = UserData(username='******', password='******')
        self.user_datastore.save(user1)
        user2 = UserData(username='******', password='******')
        self.user_datastore.save(user2)
        userfound1 = self.user_datastore.fetchByUsername('cdoremus1')
        self.assertEquals(userfound1.password, user1.password, 'Found user' + str(userfound1))
        self.assertTrue(userfound1.user_id == 1,"User id is not 1: " + str(userfound1.user_id))

    def testFetchByUsername_NotFound(self): 
        user1 = UserData(username='******', password='******')
        self.user_datastore.save(user1)
        user2 = UserData(username='******', password='******')
        self.user_datastore.save(user2)
        userfound1 = self.user_datastore.fetchByUsername('foo')
        self.assertTrue(userfound1 == None, 'Found user' + str(userfound1))
示例#2
0
class Test(unittest.TestCase):
    def setUp(self):
        # Setup mock GAE Data Store
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.user_datastore = UserAppengineDataStore()

    def tearDown(self):
        self.testbed.deactivate()

    def testFetch(self):
        user = UserData(username='******', password='******')
        user.put()
        user_id = user.key().id()
        actual = self.user_datastore.fetch(user_id)
        self.assertEquals(user.username, actual.username,
                          "Found user: "******"Found user_id: " + str(actual.user_id))

    def testSave(self):
        user = UserData(username='******', password='******')
        new_user = self.user_datastore.save(user)
        user_id = user.key().id()
        actual = self.user_datastore.fetch(user_id)
        self.assertEquals(user.username, actual.username,
                          "Found user: "******"Found user: "******"User count: " + str(users.count()))
        self.assertTrue(new_user1.user_id == 1,
                        'New user_id for user1: ' + str(new_user1.user_id))
        self.assertTrue(new_user2.user_id == 2,
                        'New user_id for user2: ' + str(new_user2.user_id))


#        count = 0
#         for user in users:
#            count += 1
#            self.assertTrue(user.user_id == count)

    def testFetchByUsername(self):
        user1 = UserData(username='******', password='******')
        self.user_datastore.save(user1)
        user2 = UserData(username='******', password='******')
        self.user_datastore.save(user2)
        userfound1 = self.user_datastore.fetchByUsername('cdoremus1')
        self.assertEquals(userfound1.password, user1.password,
                          'Found user' + str(userfound1))
        self.assertTrue(userfound1.user_id == 1,
                        "User id is not 1: " + str(userfound1.user_id))

    def testFetchByUsername_NotFound(self):
        user1 = UserData(username='******', password='******')
        self.user_datastore.save(user1)
        user2 = UserData(username='******', password='******')
        self.user_datastore.save(user2)
        userfound1 = self.user_datastore.fetchByUsername('foo')
        self.assertTrue(userfound1 == None, 'Found user' + str(userfound1))