예제 #1
0
    def test_http_resonse_200_fail_MissingCollapseKey(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="  Error =MissingCollapseKey ")

        with self.assertRaises(MissingCollapseKeyException):
            tasks.send_message(*self.get_message())
예제 #2
0
    def test_http_resonse_200_fail_UnknownCodeXX(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="  Error =UnknownCodeXX ")

        with self.assertRaises(UnknownErrorCodeException):
            tasks.send_message(*self.get_message())
예제 #3
0
    def test_http_resonse_200_fail_DeviceQuotaExceeded(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="  Error =DeviceQuotaExceeded ")

        with self.assertRaises(DeviceQuotaExceededException):
            tasks.send_message(*self.get_message())
예제 #4
0
    def test_http_resonse_200_fail_MessageTooBig(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="  Error =MessageTooBig ")

        with self.assertRaises(MessageTooBigException):
            tasks.send_message(*self.get_message())
예제 #5
0
    def test_http_resonse_200_fail_InvalidRegistration(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="Error=InvalidRegistration")

        with self.assertRaises(InvalidRegistrationException):
            tasks.send_message(*self.get_message())
예제 #6
0
    def test_http_resonse_200_fail_NotRegistered(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response="  Error =   NotRegistered ")

        with self.assertRaises(NotRegisteredException):
            tasks.send_message(*self.get_message())
예제 #7
0
    def test_http_resonse_401_fail_InvalidAuthToken(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(code=401)

        with self.assertRaises(ErrorInvalidAuthTokenException):
            tasks.send_message(*self.get_message())
예제 #8
0
    def test_http_resonse_503_fail(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(code=503)

        with self.assertRaises(RetryTaskError):
            tasks.send_message(*self.get_message())
예제 #9
0
    def assertInputOutput(self, get, code=200, response='id=123'):
        request = HttpRequest()
        request.method = 'GET'
        request.GET = get
        # register device
        with patch('urllib2.urlopen') as urlopen:
            urlopen.return_value = make_fake_urlopen(
                                     response=response)(request)
            response = views.set_registration_id(request)

        self.assertIsInstance(response, HttpResponse)
        self.assertEqual(response.status_code, code)
예제 #10
0
    def test_http_resonse_200_success(self):
        tasks.urllib2.urlopen = make_fake_urlopen()

        tasks.urllib2.urlopen = make_fake_urlopen(response=" id  =   123  ")
        response = tasks.send_message(*self.get_message())
        self.assertEqual(response, "123")
예제 #11
0
    def test_register_device(self):
        # Create new device
        request = HttpRequest()
        request.method = 'GET'
        request.GET = {
                       'device_id': 'devid_001',
                       'registration_id': 'reg_id_001'}
        # register device
        with patch('urllib2.urlopen') as urlopen:
            urlopen.return_value = make_fake_urlopen(
                                     response='id=123')(request)
            response = views.set_registration_id(request)

        self.assertIsInstance(response, HttpResponse)
        self.assertEqual(response.status_code, 200)

        ad = AndroidDevice.objects.get(device_id='devid_001')
        self.assertEqual(ad.registration_id, '')

        # wait to the time to send a token
        task = response.task_registration
        res = task.wait()

        adt = AndroidDeviceToken.objects.get(registration_id='reg_id_001')
        self.assertTrue(len(adt.token) == REGISTRATION_TOKEN_LEN)

        # check token
        request = HttpRequest()
        request.method = 'GET'
        request.GET = {
                       'device_id': 'devid_001',
                       'registration_token': adt.token}

        response = views.check_token(request)
        self.assertEqual(response.status_code, 200)

        # check if has been set registration_id
        ad = AndroidDevice.objects.get(registration_id='reg_id_001')
        self.assertEqual('devid_001', ad.device_id)

        ##############################
        # update registration_id

        # Create new device
        request = HttpRequest()
        request.method = 'GET'
        request.GET = {
                       'device_id': 'devid_001',
                       'registration_id': 'reg_id_002'}
        # register device
        with patch('urllib2.urlopen') as urlopen:
            urlopen.return_value = make_fake_urlopen(
                                         response='id=1234')(request)
            response = views.set_registration_id(request)

        self.assertIsInstance(response, HttpResponse)
        self.assertEqual(response.status_code, 200)

        ad = AndroidDevice.objects.get(device_id='devid_001')
        self.assertEqual(ad.registration_id, 'reg_id_001')

        # wait to the time to send a token
        task = response.task_registration
        task.wait()

        adt = AndroidDeviceToken.objects.get(registration_id='reg_id_002')
        self.assertTrue(len(adt.token) == REGISTRATION_TOKEN_LEN)

        # check token
        request = HttpRequest()
        request.method = 'GET'
        request.GET = {
                       'device_id': 'devid_001',
                       'registration_token': adt.token}

        response = views.check_token(request)
        self.assertEqual(response.status_code, 200)

        # check if has been set registration_id
        ad = AndroidDevice.objects.get(registration_id='reg_id_002')
        self.assertEqual('devid_001', ad.device_id)