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 }) )
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', } } }) )
def test_full_payload_param(self): assert_that( get_payload({'data': {'some': 'value'}}, self.definitions), equal_to({ 'type': 'json', 'data': {'some': 'value'} }) )
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 } }))
def test_full_payload_param(self): assert_that(get_payload({'data': { 'some': 'value' }}, self.definitions), equal_to({ 'type': 'json', 'data': { 'some': 'value' } }))
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} }) )
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 }))
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
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
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', } } }))
def test_no_params(self): for i in [None, {}]: assert_that(get_payload(i, self.definitions), equal_to(None))
def test_no_params(self): for i in [None, {}]: assert_that( get_payload(i, self.definitions), equal_to(None) )