Esempio n. 1
0
    def test_build_dict_no_list(self):
        items = 'test'
        result = build_dict(items)
        self.assertIsNone(result)

        items = {}
        result = build_dict(items)
        self.assertIsNone(result)
Esempio n. 2
0
    def get_data(self):
        data = utils.build_dict(self.data.get('data'))

        if not data or len(data) <= 0:
            # I can follow any coding style needed. Even having returns
            # in the middle of a function! I know some people hate it...
            return None

        if self.hook_type == self.HOOK_GET:
            get_data = '?'
            for key, value in data.items():
                get_data += '{0}={1}&'.format(key, value)
            # Oh hi return, almost didnt see you there.
            return get_data[:-1]

        payload_type = self.data.get('payloadType', 'form')
        if payload_type == 'json':
            # ┬─┬ ノ( ゜-゜ノ)
            return json.dumps(data)
        elif payload_type == 'xml':
            # (╯°□°)╯︵ ┻━┻
            return dicttoxml(data)

        # (ノ^_^)ノ┻━┻ ┬─┬ ノ( ^_^ノ)
        return data
Esempio n. 3
0
 def get_headers(self, headers={}):
     results = list(utils.search_dict('headers', self.data))
     # import ipdb; ipdb.set_trace()
     if results and len(results) > 0:
         _, list_headers = results[0]
         if len(list_headers) > 0:
             headers.update(utils.build_dict(list_headers))
     return headers
Esempio n. 4
0
    def test_build_dict_unexpected_list(self):
        items = ['test1', 'test2']
        expected_result = {
            'test1': 'test1',
            'test2': 'test2'
        }
        result = build_dict(items)

        self.assertEquals(result, expected_result)
Esempio n. 5
0
    def test_build_dict(self):
        items = [{
            'key': 'key1',
            'value': 'value1'
        }, {
            'key': 'key2',
            'value': 'value2'
        }]
        expected_result = {
            'key1': 'value1',
            'key2': 'value2'
        }
        result = build_dict(items)

        self.assertEquals(result, expected_result)