Esempio n. 1
0
 def test_create_account_2(self):
     data = {'username': '******'}
     response = self.client.post(self.__class__.PREFIX + 'create_account_2',
                                 {'data': json_encode(data)})
     result = json.loads(response.content)
     self.assertEqual(result['error']['type'], 'UserNameTakenError')
     self.assertTrue(len(result['error']['data']) == 2)
Esempio n. 2
0
    def test_html_safe(self):
        input = {"<script>": "&amp; </script>"}
        encoded = json_encode(input)
        self.assertFalse("<" in encoded)
        self.assertFalse(">" in encoded)
        self.assertFalse("&" in encoded)

        output = json.loads(encoded)
        self.assertEqual(input, output)
Esempio n. 3
0
    def test_post_with_params(self):
        param1 = 1234
        param2 = 'hello world!'
        data = {'param1': param1, 'param2': param2}

        response = self.client.post(self.__class__.PREFIX + 'post_with_params',
                                    {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error'], None)
        self.assertEqual(result['data'], data)
Esempio n. 4
0
    def test_get_with_form_params(self):
        param1 = '2013-01-03T01:02:03Z'
        param2 = 'hello'
        data = {'param1': param1, 'param2': param2}

        response = self.client.get(
            self.__class__.PREFIX + 'get_with_form_params',
            {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error'], None)
        self.assertEqual(result['data'], data)
Esempio n. 5
0
    def test_post_with_form_params_error(self):
        param1 = None
        param2 = 'hello world'
        data = {'param1': param1, 'param2': param2}

        response = self.client.post(
            self.__class__.PREFIX + 'post_with_form_params',
            {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error']['type'], 'AjaxParamError')
        self.assertTrue('param2' in result['error']['data'])
        self.assertTrue('param1' not in result['error']['data'])
        self.assertTrue(result['error']['data']['param2'][0] != '')
        self.assertEqual(result['data'], None)
Esempio n. 6
0
    def test_encode(self):
        data = (
            (_('Test Only. Do Not Translate'), '"%s"' % _('Test Only. Do Not Translate')),
            (None, "null"),
            (JSONTest.SimpleObject(), '"hello"'),
            (timezone.make_aware(datetime(2013, 1, 30, 11, 12, 13, 0), timezone=timezone.utc), '"2013-01-30T11:12:13Z"'),
            (date(2013, 1, 30), '"2013-01-30"'),
        )

        for test in data:
            test_input      = test[0]
            test_expected   = test[1]

            output = json_encode(test_input)
            self.assertEqual(output, test_expected)
Esempio n. 7
0
def _ajax_json(error=None, data=None):
    """
    :type   error: Exception 
    """

    error_dict = None

    if error:
        error_dict = {
            'type': error.__class__.__name__,
        }

        # As security feature, we include more stuff only when it is AjaxError
        if isinstance(error, AjaxError):
            error_dict['message'] = force_text(error)
            error_dict['data'] = error.data

    return json_encode({'error': error_dict, 'data': data})
Esempio n. 8
0
def _ajax_json(error=None, data=None):
    """
    :type   error: Exception 
    """

    error_dict = None

    if error:
        error_dict = {
            'type':     error.__class__.__name__,
        }

        # As security feature, we include more stuff only when it is AjaxError
        if isinstance(error, AjaxError):
            error_dict['message'] = force_text(error)             
            error_dict['data'] = error.data 

    return json_encode({'error': error_dict, 'data': data})
Esempio n. 9
0
    def test_get_with_form_params(self):
        param1 = '2013-01-03T01:02:03Z'
        param2 = 'hello'
        data = {'param1': param1, 'param2' : param2}

        response = self.client.get(self.__class__.PREFIX + 'get_with_form_params', {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error'], None)
        self.assertEqual(result['data'], data)
Esempio n. 10
0
 def test_create_account_2(self):
     data = {'username': '******'}
     response = self.client.post(self.__class__.PREFIX + 'create_account_2', {'data': json_encode(data)})
     result = json.loads(response.content)
     self.assertEqual(result['error']['type'], 'UserNameTakenError')
     self.assertTrue(len(result['error']['data']) == 2)
Esempio n. 11
0
    def test_post_with_form_params_error(self):
        param1 = None
        param2 = 'hello world'
        data = {'param1': param1, 'param2' : param2}

        response = self.client.post(self.__class__.PREFIX + 'post_with_form_params', {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error']['type'], 'AjaxParamError')
        self.assertTrue('param2' in result['error']['data'])
        self.assertTrue('param1' not in result['error']['data'])
        self.assertTrue(result['error']['data']['param2'][0] != '')
        self.assertEqual(result['data'], None)
Esempio n. 12
0
    def test_post_with_params(self):
        param1 = 1234
        param2 = 'hello world!'
        data = {'param1': param1, 'param2' : param2}

        response = self.client.post(self.__class__.PREFIX + 'post_with_params', {'data': json_encode(data)})
        result = json.loads(response.content)
        self.assertEqual(result['error'], None)
        self.assertEqual(result['data'], data)