Example #1
0
    def test_parse_response_200_queue_full(self):
        # Mocking response headers
        test_tile_URI = "http://testuri.com/"
        httpretty.register_uri(httpretty.POST,
                               test_tile_URI,
                               content_type='text/json',
                               adding_headers={"x-deviceconnectionstatus": "Test",
                                               "x-notificationstatus": "QueueFull",
                                               "x-subscriptionstatus": "Test",
                                               "x-messageid": "Test"},
                               status=200)

        # Creating MPNS object, posting request and
        # submitting response to parse_response
        test_tile = MPNSTile()
        response = requests.post(test_tile_URI)
        status = test_tile.parse_response(response)

        # Checking status code, error message and ensuring
        # other headers passed without unaltered
        assert status['http_status_code'] == 200
        assert status['error'] == 'Queue full, try again later'
        assert status['backoff_seconds'] == 60
        assert status['device_connection_status'] == 'Test'
        assert status['subscription_status'] == 'Test'
        assert status['notification_status'] == 'QueueFull'
        assert status['message_id'] == 'Test'
Example #2
0
    def test_parse_response_400(self):
        # Mocking response headers
        test_tile_URI = "http://testuri.com/"
        httpretty.register_uri(httpretty.POST,
                               test_tile_URI,
                               content_type='text/json',
                               adding_headers={"x-deviceconnectionstatus": "Test",
                                               "x-notificationstatus": "Test",
                                               "x-subscriptionstatus": "Test",
                                               "x-messageid": "Test"},
                               status=400)

        # Creating MPNS object, posting request and
        # submitting response to parse_response
        test_tile = MPNSTile()
        response = requests.post(test_tile_URI)
        status = test_tile.parse_response(response)

        # Checking status code, error message and ensuring
        # other headers passed without unaltered
        assert status['http_status_code'] == 400
        assert status['error'] == 'Bad Request - invalid payload or subscription URI'
        assert status['device_connection_status'] == 'Test'
        assert status['subscription_status'] == 'Test'
        assert status['notification_status'] == 'Test'
        assert status['message_id'] == 'Test'
Example #3
0
    def test_parse_response_406(self):
        # Mocking response headers
        test_tile_URI = "http://testuri.com/"
        httpretty.register_uri(httpretty.POST,
                               test_tile_URI,
                               content_type='text/json',
                               adding_headers={"x-deviceconnectionstatus": "Test",
                                               "x-notificationstatus": "Test",
                                               "x-subscriptionstatus": "Test",
                                               "x-messageid": "Test"},
                               status=406)

        # Creating MPNS object, posting request and
        # submitting response to parse_response
        test_tile = MPNSTile()
        response = requests.post(test_tile_URI)
        status = test_tile.parse_response(response)

        # Checking status code, error message and ensuring
        # other headers passed without unaltered
        assert status['http_status_code'] == 406
        assert status['error'] == 'Not Acceptable - per-day throttling limit reached'
        assert status['backoff_seconds'] == 24*60*60
        assert status['device_connection_status'] == 'Test'
        assert status['subscription_status'] == 'Test'
        assert status['notification_status'] == 'Test'
        assert status['message_id'] == 'Test'
Example #4
0
    def send_notification(self, auction_id, bid_value):
        customers = self.db.customers.find({"auction": auction_id})

        for doc in customers:
            toast = MPNSToast()
            tile = MPNSTile()
            toast.send(doc["channelURI"], {'text1': 'Nova oferta', 'text2': 'Com o valor ' + str(bid_value) + ' eur'})
            tile.send(doc["channelURI"], {'title': 'Nova oferta no valor de ' + str(bid_value) + ' eur'})