def test_normalize_body_urlencoded(self):
        """
        Test that the correct data is returned
        when the request body is urlencoded.
        """
        content_type = 'application/json'
        request_body = '{"category":"button","action":"pressed"}'
        data = utils.normalize_body(content_type, request_body)

        self.assertIn('category', data)
        self.assertIn('action', data)
        self.assertEqual(data['category'], 'button')
        self.assertEqual(data['action'], 'pressed')
    def test_normalize_body_json(self):
        """
        Test that the correct data is returned
        when the request body is in json format.
        """
        content_type = 'application/x-www-form-urlencoded'
        request_body = 'category=button&action=pressed'
        data = utils.normalize_body(content_type, request_body)

        self.assertIn('category', data)
        self.assertIn('action', data)
        self.assertEqual(data['category'], 'button')
        self.assertEqual(data['action'], 'pressed')
Exemple #3
0
    def post(self):
        content_type = self.request.headers.get('Content-Type')

        data = utils.normalize_body(content_type, self.request.body)

        if "type" in data:
            tracking_id = data.pop("id", None)
            event_type = data.pop("type", None)

            Obj = get_model_for_type(event_type)
            obj = Obj(tracking_id, data)

            if obj.is_valid():
                self.database.add(obj)
Exemple #4
0
    def post(self):
        content_type = self.request.headers.get('Content-Type')

        data = utils.normalize_body(content_type, self.request.body)

        if "type" in data:
            tracking_id = data.pop("id", None)
            event_type = data.pop("type", None)

            Obj = get_model_for_type(event_type)
            obj = Obj(tracking_id, data)

            if obj.is_valid():
                self.database.add(obj)