0

This is my test so far:

test_500(self):

    client = ClientConfiguration(token=token, url=url)
    client.url = 'https://localhost:1234/v1/' + bucket

    keys = None        

    try:
        get_bucket = json.loads(str(client.get_bucket(bucket)))
        result = get_bucket['result']
    except Exception as e:
        expected_status_code = 500
        failure_message = "Expected status code %s but got status code %s" % (expected_status_code, e)
        self.assertEquals(e, expected_status_code, failure_message)

I need to write a mock that will return a 500 response when the 'https://localhost:1234/v1/' + bucket url is used. Can this be done with unittest and if so, how or where can I find some documentation on this? I've been through this site, the unittest documentation and Youtube and can't find anythingspecific to what I want to do.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118

1 Answers1

0

I ended up using this to create my test.

The end result is:

@responses.activate
test_500(self):

    responses.add(responses.GET, 'https://localhost:1234/v1/' + bucket,
        json={'error': 'server error'}, status=500)

    client = ClientConfiguration(token=token, url=url)
    client.url = 'https://localhost:1234/v1/'

    keys = None        

    try:
        get_bucket = json.loads(str(client.get_bucket(bucket)))
        result = get_bucket['result']
except Exception as e:
        expected_status_code = 500
        failure_message = "Expected status code %s but got status code %s" % (expected_status_code, e)
        self.assertEquals(e, expected_status_code, failure_message)
runnerpaul
  • 5,942
  • 8
  • 49
  • 118