Beispiel #1
0
 def test_query_set_get_with_valid_filter_param(self):
     resource = AddressableUserQuerySetResource(mock_orm.QuerySet(
         User(pk=1, name='Alice', age=31),
         User(pk=2, name='Bob', age=20)
     ))
     resource.allow_unfiltered_query = False
     resource.filters = [ParameterizedFilter('name', 'name')]
     data = resource.get(mock_context(), _ParamsImpl(QueryDict('name=Alice')))
     self.assertEqual(data['objects'][0]['name'], 'Alice')
Beispiel #2
0
 def test_query_set_get_with_valid_filter_param(self):
     resource = AddressableUserQuerySetResource(mock_orm.QuerySet(
         User(pk=1, name='Alice', age=31),
         User(pk=2, name='Bob', age=20)
     ))
     resource.allow_unfiltered_query = False
     resource.filters = [ParameterizedFilter('name', 'name')]
     data = resource.get(mock_context(), _ParamsImpl(QueryDict('name=Alice')))
     self.assertEqual(data['objects'][0]['name'], 'Alice')
Beispiel #3
0
    def test_get_list(self):
        get = Mock(name='mock')
        get.getlist.return_value = ['bar', 'baz']
        params = _ParamsImpl(get)

        result = params.get_list('foo')

        self.assertEqual(result, ['bar', 'baz'])
        get.getlist.assert_called_with('foo')
Beispiel #4
0
    def test_get_list(self):
        get = Mock(name='mock')
        get.getlist.return_value = ['bar', 'baz']
        params = _ParamsImpl(get)

        result = params.get_list('foo')

        self.assertEqual(result, ['bar', 'baz'])
        get.getlist.assert_called_with('foo')
Beispiel #5
0
 def test_query_set_get_with_invalid_filter_param(self):
     resource = AddressableUserQuerySetResource(mock_orm.QuerySet(
         User(pk=1, name='Alice', age=31),
         User(pk=2, name='Bob', age=20)
     ))
     resource.allow_unfiltered_query = False
     resource.filters = [ParameterizedFilter('name', 'name')]
     data = None
     with self.assertRaises(SavoryPieError):
         data = resource.get(mock_context(), _ParamsImpl(QueryDict('[object Object]=12345')))
     self.assertEqual(data, None)
Beispiel #6
0
 def test_query_set_get_with_invalid_filter_param(self):
     resource = AddressableUserQuerySetResource(mock_orm.QuerySet(
         User(pk=1, name='Alice', age=31),
         User(pk=2, name='Bob', age=20)
     ))
     resource.allow_unfiltered_query = False
     resource.filters = [ParameterizedFilter('name', 'name')]
     data = None
     with self.assertRaises(SavoryPieError):
         data = resource.get(mock_context(), _ParamsImpl(QueryDict('[object Object]=12345')))
     self.assertEqual(data, None)
Beispiel #7
0
 def test_parameters_get_default(self):
     params = _ParamsImpl({'key1': 'value1'})
     self.assertEqual(params.get('some', 'other'), 'other')
Beispiel #8
0
 def test_get_item(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertEqual(params['key1'], 'value1')
Beispiel #9
0
 def test_contains(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertTrue('key1' in params)
     self.assertFalse('key3' in params)
Beispiel #10
0
 def test_parameters_get_as_wrong_type(self):
     params = _ParamsImpl({'key1': 1})
     self.assertEqual(params.get_as('key1', str, 'other'), '1')
Beispiel #11
0
 def test_contains(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertTrue('key1' in params)
     self.assertFalse('key3' in params)
Beispiel #12
0
 def test_get_list_of(self):
     params = _ParamsImpl({'key1': [1]})
     self.assertEqual(params.get_list_of('key1', str), ['1'])
Beispiel #13
0
 def test_parameters_get_as_default(self):
     params = _ParamsImpl({'key1': 1})
     self.assertEqual(params.get_as('key2', str, 'other'), 'other')
Beispiel #14
0
 def test_get_list_of_not_found(self):
     params = _ParamsImpl({'key1': [1]})
     self.assertEqual(params.get_list_of('key2', str), [])
Beispiel #15
0
 def test_parameters_get_default(self):
     params = _ParamsImpl({'key1': 'value1'})
     self.assertEqual(params.get('some', 'other'), 'other')
Beispiel #16
0
 def test_get_list_of(self):
     params = _ParamsImpl({'key1': [1]})
     self.assertEqual(params.get_list_of('key1', str), ['1'])
Beispiel #17
0
 def test_parameters_get_list(self):
     get = mock.Mock()
     get.getlist.return_value = ['value1']
     params = _ParamsImpl(get)
     self.assertEqual(params.get_list('key1'), ['value1'])
Beispiel #18
0
 def test_parameters_get_as_default(self):
     params = _ParamsImpl({'key1': 1})
     self.assertEqual(params.get_as('key2', str, 'other'), 'other')
Beispiel #19
0
 def test_parameters_get_as(self):
     params = _ParamsImpl({'key1': 'value1'})
     self.assertEqual(params.get_as('key1', str, 'other'), 'value1')
Beispiel #20
0
 def test_get_item(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertEqual(params['key1'], 'value1')
Beispiel #21
0
 def test_parameters_get_as_wrong_type(self):
     params = _ParamsImpl({'key1': 1})
     self.assertEqual(params.get_as('key1', str, 'other'), '1')
Beispiel #22
0
 def test_keys(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertEqual(sorted(params.keys()), ['key1', 'key2'])
Beispiel #23
0
 def test_parameters_get_list(self):
     get = mock.Mock()
     get.getlist.return_value = ['value1']
     params = _ParamsImpl(get)
     self.assertEqual(params.get_list('key1'), ['value1'])
Beispiel #24
0
 def test_init(self):
     params = _ParamsImpl('some var')
     self.assertEqual(params._GET, 'some var')
Beispiel #25
0
 def test_get_list_of_not_found(self):
     params = _ParamsImpl({'key1': [1]})
     self.assertEqual(params.get_list_of('key2', str), [])
Beispiel #26
0
 def test_keys(self):
     params = _ParamsImpl({'key1': 'value1', 'key2': 'value2'})
     self.assertEqual(sorted(params.keys()), ['key1', 'key2'])
Beispiel #27
0
 def test_init(self):
     params = _ParamsImpl('some var')
     self.assertEqual(params._GET, 'some var')
Beispiel #28
0
 def test_parameters_get_as(self):
     params = _ParamsImpl({'key1': 'value1'})
     self.assertEqual(params.get_as('key1', str, 'other'), 'value1')