def test_all_no_parameters_fail(self): for action, cadasta_endpoint in post_api_map.items(): print "testing {action}".format(action=action), # read our expected json output as <action_name>.json filepath = os.path.join(self.data_dir, ".".join([action, "json"])) body = open(filepath).read() # add the expected parameters (everything is a 1) api_url = cadasta_endpoint.url url_args = dict([(a[1], 1) for a in string.Formatter().parse(api_url) if a[1]]) # if this endpoint needs no parameters, quit early, test does not # apply if not url_args: return # make sure the point parameters are filled out endpoint = urljoin(self.test_api, api_url).format(**url_args) # fake out our response responses.add(responses.POST, endpoint, body=body, content_type="application/json") # call our action with no arguments with assert_raises(toolkit.ValidationError) as cm: helpers.call_action(action) for error in cm.exception.error_dict.values(): assert_equal(["Missing value"], error) print "\t[OK]"
def test_all_no_parameters_fail(self): for action, cadasta_endpoint in post_api_map.items(): print 'testing {action}'.format(action=action), # read our expected json output as <action_name>.json filepath = os.path.join(self.data_dir, '.'.join([action, 'json'])) body = open(filepath).read() # add the expected parameters (everything is a 1) api_url = cadasta_endpoint.url url_args = dict([(a[1], 1) for a in string.Formatter().parse(api_url) if a[1]]) # if this endpoint needs no parameters, quit early, test does not # apply if not url_args: return # make sure the point parameters are filled out endpoint = urljoin(self.test_api, api_url).format(**url_args) # fake out our response responses.add(responses.POST, endpoint, body=body, content_type="application/json") # call our action with no arguments with assert_raises(toolkit.ValidationError) as cm: helpers.call_action(action) for error in cm.exception.error_dict.values(): assert_equal(['Missing value'], error) print '\t[OK]'
def test_all_post_actions_success(self): for i, (action, cadasta_endpoint) in enumerate(post_api_map.items()): print "testing {action}".format(action=action), # read our expected json output as <action_name>.json filepath = os.path.join(self.data_dir, ".".join([action, "json"])) body = open(filepath).read() expected = json.loads(body) # add the expected parameters (everything is a 1) api_url = cadasta_endpoint.url url_args = dict([(a[1], 1) for a in string.Formatter().parse(api_url) if a[1]]) # make sure the point parameters are filled out endpoint = urljoin(self.test_api, api_url).format(**url_args) # fake out our response responses.add(responses.POST, endpoint, body=body, content_type="application/json") url_args["test_param"] = "test parameter" # call our action with the same arguments passed result = helpers.call_action(action, **url_args) assert_equal(expected, result) request = responses.calls[i].request # assert_equal(request.body, 'test_param=test+parameter') if action == "cadasta_create_project_parcel": assert_equal(request.body, '{"test_param": "test parameter", "project_id": 1}') else: assert_equal(request.body, '{"test_param": "test parameter"}') print "\t[OK]"
def test_all_post_actions_success(self): for i, (action, cadasta_endpoint) in enumerate(post_api_map.items()): print 'testing {action}'.format(action=action), # read our expected json output as <action_name>.json filepath = os.path.join(self.data_dir, '.'.join([action, 'json'])) body = open(filepath).read() expected = json.loads(body) # add the expected parameters (everything is a 1) api_url = cadasta_endpoint.url url_args = dict([(a[1], 1) for a in string.Formatter().parse(api_url) if a[1]]) # make sure the point parameters are filled out endpoint = urljoin(self.test_api, api_url).format(**url_args) # fake out our response responses.add(responses.POST, endpoint, body=body, content_type="application/json") url_args['test_param'] = 'test parameter' # call our action with the same arguments passed result = helpers.call_action(action, **url_args) assert_equal(expected, result) request = responses.calls[i].request assert_equal(request.body, 'test_param=test+parameter') print '\t[OK]'