Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
    def get(self):
        received = 0
        _token = self.request.get("token").encode('ascii', 'ignore')
        eventid = self.request.get("eventid").encode('ascii', 'ignore')
        attend_func = self.request.get("isAttend").encode('ascii', 'ignore')

        if eventid == "":
            received = -1
            self.post(received)
        elif id == "":
            received = -2
            self.post(received)
        else:
            mydb = DAL()
            try:
                int_token = int(_token)
                if mydb.check_token(int_token) is True:  #check if the token is valid
                    if attend_func == "true":
                        self.post(mydb.attend(int_token, int(eventid)))
                    elif attend_func == "false":
                        self.post(mydb.unattend(int_token, int(eventid)))
                else:
                    self.post(-3)
                    return
            except ValueError:
                self.post(3)
Ejemplo n.º 4
0
    def get(self):
        received = 0
        _token = self.request.get("token").encode('ascii', 'ignore')
        eventid = self.request.get("eventid").encode('ascii', 'ignore')
        attend_func = self.request.get("isAttend").encode('ascii', 'ignore')

        if eventid == "":
            received = -1
            self.post(received)
        elif id == "":
            received = -2
            self.post(received)
        else:
            mydb = DAL()
            try:
                int_token = int(_token)
                if mydb.check_token(
                        int_token) is True:  #check if the token is valid
                    if attend_func == "true":
                        self.post(mydb.attend(int_token, int(eventid)))
                    elif attend_func == "false":
                        self.post(mydb.unattend(int_token, int(eventid)))
                else:
                    self.post(-3)
                    return
            except ValueError:
                self.post(3)
Ejemplo n.º 5
0
 def get(self):
     token = self.request.get("token").encode('ascii', 'ignore')
     if token == "":
         self.post(False)
     else:
         mydb = DAL()
         try:
             int_token = int(token)
             if mydb.check_token(int_token) is not False:
                 reply_json = mydb.get_all_user_events(int_token)
                 self.post(reply_json)
             else:
                 self.post(0)
         except ValueError:
             self.post(2)
Ejemplo n.º 6
0
 def get(self):
     token = self.request.get("token").encode('ascii', 'ignore')
     if token == "":
         self.post(False)
     else:
         mydb = DAL()
         try:
             int_token = int(token)
             if mydb.check_token(int_token) is not False:
                 reply_json = mydb.get_all_user_events(int_token)
                 self.post(reply_json)
             else:
                 self.post(0)
         except ValueError:
             self.post(2)