示例#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
class UserLoginHandler(webapp2.RequestHandler):
    def get(self):
        email = self.request.get("email")  #.encode('ascii', 'ignore')
        hashed_password = self.request.get("password")
        first_name = self.request.get("firstname")
        last_name = self.request.get("lastname")

        self.mydb = DAL()

        if email is "" or hashed_password is "":
            self.post(-1)
        elif email is not "" and hashed_password is not "":
            isvalid = isValidEmailAddress(email)
            logging.info(isvalid)
            if not isvalid:
                self.post(-4)
            else:
                if first_name is "" and last_name is "":
                    self.login(email, hashed_password)
                else:
                    if first_name is not "" and last_name is "":
                        self.post(-3)
                    elif first_name is "" and last_name is not "":
                        self.post(-2)
                    else:
                        self.register(email, hashed_password, first_name,
                                      last_name)

    def login(self, email, hashed_password):
        token = self.mydb.user_login(email, hashed_password)
        self.post(token)

    def register(self, email, hashed_password, first_name, last_name):
        token = self.mydb.register(email, hashed_password, first_name,
                                   last_name)
        self.post(token)

    def post(self, response):
        if response is -4:
            self.response.set_status(403)
            self.response.write("ERROR: Invalid mail")
        elif response is -3:
            self.response.set_status(402)
            self.response.write("ERROR: Missing Last Name")
        elif response is -2:
            self.response.set_status(401)
            self.response.write("ERROR: Missing First Name")
        elif response is -1:
            self.response.set_status(400)
            self.response.write("ERROR: Missing Parameters")
        elif response is False:
            self.response.set_status(501)
            self.response.write("ERROR: User Not Exist")
        elif response is 1:
            self.response.set_status(500)
            self.response.write("ERROR: Wrong Password")
        elif response is 2:
            self.response.set_status(502)
            self.response.write("ERROR: User already exist!")
        else:
            self.response.set_status(200)
            self.response.write(response)
示例#4
0
class UserLoginHandler(webapp2.RequestHandler):
    def get(self):
        email = self.request.get("email")#.encode('ascii', 'ignore')
        hashed_password = self.request.get("password")
        first_name = self.request.get("firstname")
        last_name = self.request.get("lastname")

        self.mydb = DAL()

        if email is "" or hashed_password is "":
            self.post(-1)
        elif email is not "" and hashed_password is not "":
            isvalid = isValidEmailAddress(email)
            logging.info(isvalid)
            if not isvalid:
                self.post(-4)
            else:
                if first_name is "" and last_name is "":
                    self.login(email, hashed_password)
                else:
                    if first_name is not "" and last_name is "":
                        self.post(-3)
                    elif first_name is "" and last_name is not "":
                        self.post(-2)
                    else:
                        self.register(email, hashed_password, first_name, last_name)

    def login(self, email, hashed_password):
        token = self.mydb.user_login(email, hashed_password)
        self.post(token)

    def register(self, email, hashed_password, first_name, last_name):
        token = self.mydb.register(email, hashed_password, first_name, last_name)
        self.post(token)

    def post(self,response):
        self.response.headers.add_header("Access-Control-Allow-Origin", "*")
        self.response.headers['Content-Type'] = 'application/json'
        if response is -4:
            self.response.set_status(403)
            self.response.write("ERROR: Invalid mail")
        elif response is -3:
            self.response.set_status(402)
            self.response.write("ERROR: Missing Last Name")
        elif response is -2:
            self.response.set_status(401)
            self.response.write("ERROR: Missing First Name")
        elif response is -1:
            self.response.set_status(400)
            self.response.write("ERROR: Missing Parameters")
        elif response is False:
            self.response.set_status(501)
            self.response.write("ERROR: User Not Exist")
        elif response is 1:
            self.response.set_status(500)
            self.response.write("ERROR: Wrong Password")
        elif response is 2:
            self.response.set_status(502)
            self.response.write("ERROR: User already exist!")
        else:
            self.response.set_status(200)
            self.response.write(response)