Beispiel #1
0
    def test_process_dictionary_against_whitelist_global_keys(self):
        test_dictionary = {u'_href': u'foo', u'_id': u'bar', u'_ns': u'baz'}

        test_dictionary_before = copy.deepcopy(test_dictionary)
        JSONController.process_dictionary_against_whitelist(
            test_dictionary, [])

        util.compare_dict(test_dictionary_before, test_dictionary)
Beispiel #2
0
    def test_process_dictionary_against_whitelisty_global_and_local_keys(self):
        test_dictionary = {
            u'_href': u'foo',
            u'_id': u'bar',
            u'_ns': u'baz',
            u'qux': u'quux'
        }

        test_dictionary_before = copy.deepcopy(test_dictionary)
        JSONController.process_dictionary_against_whitelist(test_dictionary, [u'qux'])
        util.compare_dict(test_dictionary_before, test_dictionary)
Beispiel #3
0
    def test_process_dictionary_against_whitelist_filter_key(self):
        test_dictionary = {
            u'_href': u'foo',
            u'_id': u'bar',
            u'_ns': u'baz',
            u'qux': u'quux'
        }

        target_result = copy.deepcopy(test_dictionary)
        target_result.pop(u'qux', None)

        JSONController.process_dictionary_against_whitelist(test_dictionary, [])
        util.compare_dict(target_result, test_dictionary)
Beispiel #4
0
    def test_process_dictionary_against_whitelist_filter_key(self):
        test_dictionary = {
            u'_href': u'foo',
            u'_id': u'bar',
            u'_ns': u'baz',
            u'qux': u'quux'
        }

        target_result = copy.deepcopy(test_dictionary)
        target_result.pop(u'qux', None)

        JSONController.process_dictionary_against_whitelist(
            test_dictionary, [])
        util.compare_dict(target_result, test_dictionary)
Beispiel #5
0
    def _process_users(users):
        """
        Apply standard processing to a collection of users being returned
        to a client.  Adds the object link and removes user password.

        @param users: collection of users
        @type  users: list, tuple

        @return the same list that was passed in, just for convenience. The list
                itself is not modified- only its members are modified in-place.
        @rtype  list of User instances
        """
        for user in users:
            user.update(serialization.link.search_safe_link_obj(user['login']))
            JSONController.process_dictionary_against_whitelist(user, USER_WHITELIST)
        return users
Beispiel #6
0
    def _process_users(users):
        """
        Apply standard processing to a collection of users being returned
        to a client.  Adds the object link and removes user password.

        @param users: collection of users
        @type  users: list, tuple

        @return the same list that was passed in, just for convenience. The list
                itself is not modified- only its members are modified in-place.
        @rtype  list of User instances
        """
        for user in users:
            user.update(serialization.link.search_safe_link_obj(user['login']))
            JSONController.process_dictionary_against_whitelist(
                user, USER_WHITELIST)
        return users
Beispiel #7
0
    def test_output(self, json, header):
        """
        Test json encoding.
        """
        data = {'test': 1234}
        json.dumps.return_value = repr(data)
        header.side_effect = ['h1', 'h2']

        # test
        controller = JSONController()
        encoded = controller._output(data)

        # validation
        json.dumps.assert_called_once_with(data, default=json_encoder)
        self.assertEqual(encoded, json.dumps.return_value)
        self.assertEqual(header.call_args_list, [
            (('Content-Type', 'application/json'), {}),
            (('Content-Length', len(encoded)), {}),
        ])
Beispiel #8
0
    def test_output(self, json, header):
        """
        Test json encoding.
        """
        data = {'test': 1234}
        json.dumps.return_value = repr(data)
        header.side_effect = ['h1', 'h2']

        # test
        controller = JSONController()
        encoded = controller._output(data)

        # validation
        json.dumps.assert_called_once_with(data, default=json_encoder)
        self.assertEqual(encoded, json.dumps.return_value)
        self.assertEqual(
            header.call_args_list,
            [
                (('Content-Type', 'application/json'), {}),
                (('Content-Length', len(encoded)), {}),
            ])