Пример #1
0
    def test_append_no_index(self):
        params = {}
        build_param_structure(params, 'foo[]', 123)
        self.assertEqual(params['foo'], [123])

        build_param_structure(params, 'foo[]', 456)
        self.assertEqual(params['foo'], [123, 456])
Пример #2
0
    def test_append_no_index(self):
        params = {}
        build_param_structure(params, 'foo[]', 123)
        self.assertEqual(params['foo'], [123])

        build_param_structure(params, 'foo[]', 456)
        self.assertEqual(params['foo'], [123, 456])
Пример #3
0
    def test_append_no_index(self):
        params = {}
        build_param_structure(params, 'foo[]', 123)
        assert params['foo'] == [123]

        build_param_structure(params, 'foo[]', 456)
        assert params['foo'] == [123, 456]
Пример #4
0
 def test_modify_existing(self):
     params = {
         'foo': [
             {'key': 'abc'}
         ]
     }
     build_param_structure(params, 'foo[0].secret', 123)
     self.assertEqual(params['foo'][0]['key'], 'abc')
     self.assertEqual(params['foo'][0]['secret'], 123)
Пример #5
0
    def test_provided_index_with_wildcard(self):
        params = {}
        index = 0
        build_param_structure(params, 'foo[*].bar', 123, index)
        build_param_structure(params, 'foo[*].baz', 456, index)
        self.assertEqual(params['foo'][index], {'bar': 123, 'baz': 456})

        index = 1
        build_param_structure(params, 'foo[*].bar', 789, index)
        build_param_structure(params, 'foo[*].baz', 123, index)
        self.assertEqual(params['foo'], [
            {'bar': 123, 'baz': 456},
            {'bar': 789, 'baz': 123}
        ])
Пример #6
0
    def test_provided_index_with_wildcard(self):
        params = {}
        index = 0
        build_param_structure(params, 'foo[*].bar', 123, index)
        build_param_structure(params, 'foo[*].baz', 456, index)
        self.assertEqual(params['foo'][index], {'bar': 123, 'baz': 456})

        index = 1
        build_param_structure(params, 'foo[*].bar', 789, index)
        build_param_structure(params, 'foo[*].baz', 123, index)
        self.assertEqual(params['foo'], [{
            'bar': 123,
            'baz': 456
        }, {
            'bar': 789,
            'baz': 123
        }])
Пример #7
0
 def test_nested_list(self):
     params = {}
     build_param_structure(params, 'foo.bar[0]', 'test')
     assert params['foo']['bar'][0] == 'test'
Пример #8
0
 def test_simple_value(self):
     params = {}
     build_param_structure(params, 'foo', 'bar')
     assert params['foo'] == 'bar'
Пример #9
0
 def test_modify_existing(self):
     params = {'foo': [{'key': 'abc'}]}
     build_param_structure(params, 'foo[0].secret', 123)
     self.assertEqual(params['foo'][0]['key'], 'abc')
     self.assertEqual(params['foo'][0]['secret'], 123)
Пример #10
0
 def test_nested_list(self):
     params = {}
     build_param_structure(params, 'foo.bar[0]', 'test')
     self.assertEqual(params['foo']['bar'][0], 'test')
Пример #11
0
 def test_modify_existing(self):
     params = {'foo': [{'key': 'abc'}]}
     build_param_structure(params, 'foo[0].secret', 123)
     assert params['foo'][0]['key'] == 'abc'
     assert params['foo'][0]['secret'] == 123
Пример #12
0
 def test_simple_value(self):
     params = {}
     build_param_structure(params, 'foo', 'bar')
     self.assertEqual(params['foo'], 'bar')
Пример #13
0
 def test_nested_list_dict(self):
     params = {}
     build_param_structure(params, 'foo.bar[0].baz', 123)
     self.assertEqual(params['foo']['bar'][0]['baz'], 123)
Пример #14
0
 def test_strange_offset(self):
     params = {}
     build_param_structure(params, 'foo[2]', 'test')
     self.assertEqual(params['foo'], [{}, {}, 'test'])
Пример #15
0
 def test_strange_offset(self):
     params = {}
     build_param_structure(params, 'foo[2]', 'test')
     assert params['foo'] == [{}, {}, 'test']
Пример #16
0
 def test_nested_list_dict(self):
     params = {}
     build_param_structure(params, 'foo.bar[0].baz', 123)
     assert params['foo']['bar'][0]['baz'] == 123
Пример #17
0
 def test_nested_dict(self):
     params = {}
     build_param_structure(params, 'foo.bar.baz', 123)
     self.assertEqual(params['foo']['bar']['baz'], 123)
Пример #18
0
 def test_strange_offset(self):
     params = {}
     build_param_structure(params, 'foo[2]', 'test')
     self.assertEqual(params['foo'], [{}, {}, 'test'])
Пример #19
0
 def test_simple_value(self):
     params = {}
     build_param_structure(params, 'foo', 'bar')
     self.assertEqual(params['foo'], 'bar')