コード例 #1
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)
コード例 #2
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)
コード例 #3
0
class UserDetails(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(User)
        self.testbed.init_memcache_stub()
        # Clear ndb's in-context cache between tests.
        # This prevents data from leaking between tests.
        # Alternatively, you could disable caching by
        # using ndb.get_context().set_cache_policy(False)
        ndb.get_context().clear_cache()
        self.mydb = DAL()
        self.obj = SearchEventsUsingAPI()
        event_id = self.mydb.set_event_details("222342395", "Hadoop Ecosystem Workshop", datetime.now(),
                                               "Tel Aviv-Yafo",  "Kiryat Atidim", "long-story-short", "rika pedro-shoham", "http://www.meetup.com", 64, "free", "All", "meetup")
        self.ev = event_id.id()

        self.mydb.set_user_details(10204308876621622, 'Itamar', 'Sharify', '*****@*****.**')
        self.mydb.set_user_details(10204308876621633, 'Olesya', 'Shapira', '*****@*****.**')
        self.mydb.set_user_details(10204308876621644, 'Rita', 'Markovich', '*****@*****.**')

    def test_get_attendings_after_attend(self):
        self.mydb.attend(2, self.ev)
        self.mydb.attend(3, self.ev)
        self.mydb.attend(4, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 4)
        self.assertTrue(json.loads(res1))

    def test_get_attendings_after_unattend(self):
        self.mydb.attend(2, self.ev)
        self.mydb.unattend(2, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 4)
        self.assertEqual(res1, '[]')

    def _test_get_attendings_not_my_self(self):
        self.mydb.attend(2, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 2)
        self.assertEqual(res1, '[]')

    def test_attend(self):
        res = self.mydb.attend(2, self.ev)
        self.assertEqual(0, res)

    def test_attend_wrong_user_id_return_1(self):
        res = self.mydb.attend(1, self.ev)
        self.assertTrue(1, res)

    def test_attend_wrong_event_id_return_2(self):
        res = self.mydb.attend(2, 12)
        self.assertTrue(2, res)

    def test_unattend(self):
        self.mydb.attend(2, self.ev)
        res = self.mydb.unattend(2, self.ev)
        self.assertEqual(0, res)

    def test_get_all_user_events(self):
        self.mydb.attend(2, self.ev)
        event_id = self.mydb.set_event_details("2296", "Some Event", datetime.now(),
                                               "Tel Aviv-Yafo",  "Kiryat Atidim", "long-story-short", "rika pedro-shoham", "http://www.meetup.com", 64, "free", "All", "meetup")

        self.mydb.attend(2, event_id.id())
        res = self.mydb.get_all_user_events(2)
        print res
        self.assertTrue(json.loads(res))

    def tearDown(self):
        self.testbed.deactivate()
コード例 #4
0
class UserDetails(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(User)
        self.testbed.init_memcache_stub()
        # Clear ndb's in-context cache between tests.
        # This prevents data from leaking between tests.
        # Alternatively, you could disable caching by
        # using ndb.get_context().set_cache_policy(False)
        ndb.get_context().clear_cache()
        self.mydb = DAL()
        self.obj = SearchEventsUsingAPI()
        event_id = self.mydb.set_event_details("222342395", "Hadoop Ecosystem Workshop", datetime.now(),
                                               "Tel Aviv-Yafo",  "Kiryat Atidim", "long-story-short", "rika pedro-shoham", "http://www.meetup.com", 64, "free", "All", "meetup")
        self.ev = event_id.id()

        self.mydb.set_user_details(10204308876621622, 'Itamar', 'Sharify', '*****@*****.**')
        self.mydb.set_user_details(10204308876621633, 'Olesya', 'Shapira', '*****@*****.**')
        self.mydb.set_user_details(10204308876621644, 'Rita', 'Markovich', '*****@*****.**')

    def test_get_attendings_after_attend(self):
        self.mydb.attend(2, self.ev)
        self.mydb.attend(3, self.ev)
        self.mydb.attend(4, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 4)
        self.assertTrue(json.loads(res1))

    def test_get_attendings_after_unattend(self):
        self.mydb.attend(2, self.ev)
        self.mydb.unattend(2, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 4)
        self.assertEqual(res1, '[]')

    def _test_get_attendings_not_my_self(self):
        self.mydb.attend(2, self.ev)
        res1 = self.mydb.get_attendings(self.ev, 2)
        self.assertEqual(res1, '[]')

    def test_attend(self):
        res = self.mydb.attend(2, self.ev)
        self.assertEqual(0, res)

    def test_attend_wrong_user_id_return_1(self):
        res = self.mydb.attend(1, self.ev)
        self.assertTrue(1, res)

    def test_attend_wrong_event_id_return_2(self):
        res = self.mydb.attend(2, 12)
        self.assertTrue(2, res)

    def test_unattend(self):
        self.mydb.attend(2, self.ev)
        res = self.mydb.unattend(2, self.ev)
        self.assertEqual(0, res)

    def test_get_all_user_events(self):
        self.mydb.attend(2, self.ev)
        event_id = self.mydb.set_event_details("2296", "Some Event", datetime.now(),
                                               "Tel Aviv-Yafo",  "Kiryat Atidim", "long-story-short", "rika pedro-shoham", "http://www.meetup.com", 64, "free", "All", "meetup")

        self.mydb.attend(2, event_id.id())
        res = self.mydb.get_all_user_events(2)
        print res
        self.assertTrue(json.loads(res))

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