jeudi 14 février 2019

Mocking a 500 response when an operation is performed

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.

Aucun commentaire:

Enregistrer un commentaire