Ejemplo n.º 1
0
 def test_params_with_files(self):
     params = {
         'data': {
             'user': {
                 'name': 'gena'
             },
             'avatar': {
                 'big': open(
                     os.path.join(self.CONFIG['FILES_PATH'], '1.txt')
                 )
             }
         }
     }
     expected_data = flatten(prepare_payload(params['data'])[1])
     expected_data['user.name'] = (
         None, 
         json.dumps(expected_data['user.name'])
     )
     assert_that(
         get_payload(params, self.definitions),
         equal_to({
             'type': 'files',
             'data': expected_data
         })
     )
Ejemplo n.º 2
0
 def test_payload_property_params(self):
     assert_that(
         get_payload(
             {
                 'find_filter': {
                     'some': 'value'
                 },
                 'find_text': {
                     'another_some': 'another_value'
                 },
             },
             self.definitions
         ),
         equal_to({
             'type': 'json',
             'data': {
                 'filter': {
                     'some': 'value',
                 },
                 'text': {
                     'another_some': 'another_value',
                 }
             }
         })
     )
Ejemplo n.º 3
0
 def test_full_payload_param(self):
     assert_that(
         get_payload({'data': {'some': 'value'}}, self.definitions),
         equal_to({
             'type': 'json',
             'data': {'some': 'value'}
         })
     )
Ejemplo n.º 4
0
 def test_params_with_root_file(self):
     file_object = open(os.path.join(self.CONFIG['FILES_PATH'], '1.txt'))
     params = {'data': file_object}
     assert_that(get_payload(params, self.definitions),
                 equal_to({
                     'type': 'files',
                     'data': {
                         'file': file_object
                     }
                 }))
Ejemplo n.º 5
0
 def test_full_payload_param(self):
     assert_that(get_payload({'data': {
         'some': 'value'
     }}, self.definitions),
                 equal_to({
                     'type': 'json',
                     'data': {
                         'some': 'value'
                     }
                 }))
Ejemplo n.º 6
0
 def test_params_with_root_file(self):
     file_object = open(
         os.path.join(self.CONFIG['FILES_PATH'], '1.txt')
     )
     params = {
         'data': file_object
     }
     assert_that(
         get_payload(params, self.definitions),
         equal_to({
             'type': 'files',
             'data': {'file': file_object}
         })
     )
Ejemplo n.º 7
0
 def test_params_with_files(self):
     params = {
         'data': {
             'user': {
                 'name': 'gena'
             },
             'avatar': {
                 'big':
                 open(os.path.join(self.CONFIG['FILES_PATH'], '1.txt'))
             }
         }
     }
     expected_data = flatten(prepare_payload(params['data'])[1])
     expected_data['user.name'] = (None,
                                   json.dumps(expected_data['user.name']))
     assert_that(get_payload(params, self.definitions),
                 equal_to({
                     'type': 'files',
                     'data': expected_data
                 }))
Ejemplo n.º 8
0
    def get_context(self, params):
        params_definitions = self.get_params_definitions()
        params_by_destination = get_params_by_destination(
            params,
            definitions=params_definitions
        )
        context = {
            'url': get_url(
                base_uri=self.base_uri,
                path=self.path,
                params=params_by_destination.get('uri', {}),
                definitions=params_definitions,
            ),
            'headers': get_headers(
                auth_header=self.auth_header,
                params=params_by_destination.get('headers', {}),
                definitions=params_definitions,
            ),
            'params': get_query_params(
                params=params_by_destination.get('query_params', {}),
                definitions=params_definitions,
            ),
        }
        delete_keys = []
        for key, value in context.items():
            if not value:
                delete_keys.append(key)
        for key in delete_keys:
            del context[key]

        payload = get_payload(
            params_by_destination.get('payload'),
            definitions=params_definitions
        )
        if self.action:
            context['headers']['X-Action'] = self.action
        if payload:
            context[payload['type']] = payload['data']
        else:
            context['headers']['Content-Type'] = 'application/json'
        return context
Ejemplo n.º 9
0
    def get_context(self, params):
        params_definitions = self.get_params_definitions()
        params_by_destination = get_params_by_destination(
            params, definitions=params_definitions)
        context = {
            'url':
            get_url(
                base_uri=self.base_uri,
                path=self.path,
                params=params_by_destination.get('uri', {}),
                definitions=params_definitions,
            ),
            'headers':
            get_headers(
                auth_header=self.auth_header,
                params=params_by_destination.get('headers', {}),
                definitions=params_definitions,
            ),
            'params':
            get_query_params(
                params=params_by_destination.get('query_params', {}),
                definitions=params_definitions,
            ),
        }
        delete_keys = []
        for key, value in context.items():
            if not value:
                delete_keys.append(key)
        for key in delete_keys:
            del context[key]

        payload = get_payload(params_by_destination.get('payload'),
                              definitions=params_definitions)
        if self.action:
            context['headers']['X-Action'] = self.action
        if payload:
            context[payload['type']] = payload['data']
        else:
            context['headers']['Content-Type'] = 'application/json'
        return context
Ejemplo n.º 10
0
 def test_payload_property_params(self):
     assert_that(
         get_payload(
             {
                 'find_filter': {
                     'some': 'value'
                 },
                 'find_text': {
                     'another_some': 'another_value'
                 },
             }, self.definitions),
         equal_to({
             'type': 'json',
             'data': {
                 'filter': {
                     'some': 'value',
                 },
                 'text': {
                     'another_some': 'another_value',
                 }
             }
         }))
Ejemplo n.º 11
0
 def test_no_params(self):
     for i in [None, {}]:
         assert_that(get_payload(i, self.definitions), equal_to(None))
Ejemplo n.º 12
0
 def test_no_params(self):
     for i in [None, {}]:
         assert_that(
             get_payload(i, self.definitions),
             equal_to(None)
         )