示例#1
0
class UserDetails(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub(User)
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()
        self.mydb = DAL()
        self.obj = SearchEventsUsingAPI()

    def test_check_login_that_already_fb_logged_in(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        token = self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        qry = User.query(User.email == "*****@*****.**")
        print "token", token
        for q in qry:
            print q.first_name , q.last_name, q.email
        self.assertTrue(qry.count() == 1)

    def test_register_new_user(self):
        token = self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        qry = User.query(User.email == "*****@*****.**")
        print "token", token
        for q in qry:
            print q.first_name , q.last_name, q.email
        self.assertTrue(qry.count() == 1)

    def test_error_is_1_on_wrong_password(self):
        self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        res = self.mydb.user_login("*****@*****.**", "12134")
        self.assertEqual(res, 1)

    def test_error_is_false_on_not_existing_email(self):
        self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        res = self.mydb.user_login("*****@*****.**", "1213")
        self.assertFalse(res)

    def test_error_is_2_on_none_password(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        qry = User.query(User.email == "*****@*****.**")
        res = self.mydb.user_login("*****@*****.**", "1213")
        self.assertEqual(res, 2)

    def test_check_token_exist(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        self.assertTrue(self.mydb.check_token(1))

    def test_check_token_not_exist(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        self.assertFalse(self.mydb.check_token(2))

    def test_check_json_for_get_user_by_token(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        print self.mydb.get_user_by_token(1)
        self.assertTrue(json.loads(self.mydb.get_user_by_token(1)))

    def test_check_json_for_get_user_by_token_error(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        res = self.mydb.get_user_by_token(35)
        self.assertEqual(1, res)
示例#2
0
class UserDetails(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub(User)
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()
        self.mydb = DAL()
        self.obj = SearchEventsUsingAPI()

    def test_check_login_that_already_fb_logged_in(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        token = self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        qry = User.query(User.email == "*****@*****.**")
        print "token", token
        for q in qry:
            print q.first_name , q.last_name, q.email
        self.assertTrue(qry.count() == 1)

    def test_register_new_user(self):
        token = self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        qry = User.query(User.email == "*****@*****.**")
        print "token", token
        for q in qry:
            print q.first_name , q.last_name, q.email
        self.assertTrue(qry.count() == 1)

    def test_error_is_1_on_wrong_password(self):
        self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        res = self.mydb.user_login("*****@*****.**", "12134")
        self.assertEqual(res, 1)

    def test_error_is_false_on_not_existing_email(self):
        self.mydb.register("*****@*****.**", "12134", "Itamar", "Sharify")
        res = self.mydb.user_login("*****@*****.**", "1213")
        self.assertFalse(res)

    def test_error_is_2_on_none_password(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        qry = User.query(User.email == "*****@*****.**")
        res = self.mydb.user_login("*****@*****.**", "1213")
        self.assertEqual(res, 2)

    def test_check_token_exist(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        self.assertTrue(self.mydb.check_token(1))

    def test_check_token_not_exist(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        self.assertFalse(self.mydb.check_token(2))

    def test_check_json_for_get_user_by_token(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        print self.mydb.get_user_by_token(1)
        self.assertTrue(json.loads(self.mydb.get_user_by_token(1)))

    def test_check_json_for_get_user_by_token_error(self):
        self.mydb.set_user_details(12, "Itamar", "Sharify", "*****@*****.**")
        res = self.mydb.get_user_by_token(35)
        self.assertEqual(1, res)
示例#3
0
 def get(self):
     mydb = DAL()
     token = self.request.get("token")
     if token is "":
         self.post(-1)
     else:
         try:
             json_response = mydb.get_user_by_token(int(token))
             self.post(json_response)
         except ValueError:
             self.post(2)
示例#4
0
 def get(self):
     mydb = DAL()
     token = self.request.get("token")
     if token is "":
         self.post(-1)
     else:
         try:
             json_response = mydb.get_user_by_token(int(token))
             self.post(json_response)
         except ValueError:
             self.post(2)