Change in vdsm[master]: imagetickets: add tests

nsoffer at redhat.com nsoffer at redhat.com
Sun Feb 28 15:31:23 UTC 2016


Nir Soffer has posted comments on this change.

Change subject: imagetickets: add tests
......................................................................


Patch Set 9:

(4 comments)

https://gerrit.ovirt.org/#/c/52900/9/tests/imagetickets_test.py
File tests/imagetickets_test.py:

Line 53:     GET = "GET"
Line 54:     PATCH = "PATCH"
Line 55:     PUT = "PUT"
Line 56: 
Line 57:     def __init__(self, response=FakeResponse()):
You cannot use mutable object as default value - all the tests using FakeUHHTP will share this object.

Instead, do:

    def __init__(self, response=None):
        self.response = response or FakeResponse()
Line 58:         self.closed = False
Line 59:         self.response = response
Line 60: 
Line 61:     def UnixHTTPConnection(self, sock_path):


Line 121: 
Line 122:     @MonkeyPatch(imagetickets, 'uhttp',
Line 123:                  FakeUHTTP(
Line 124:                      FakeResponse(status=300,
Line 125:                                   headers={"content-length": "invalid"})))
This works, but it will be easier to replace the response on the fake http inside the test:

    imagetickets.uhttp.response = FakeResponse(...)

This is safe since uhttp is new instance for this test, only this test share this fake response.
Line 126:     def test_res_header_error(self):
Line 127:         with self.assertRaises(se.ImageDaemonError):
Line 128:             imagetickets.remove_ticket("uuid")
Line 129: 


Line 128:             imagetickets.remove_ticket("uuid")
Line 129: 
Line 130:     @MonkeyPatch(imagetickets, 'uhttp',
Line 131:                  FakeUHTTP(FakeResponse(status=300,
Line 132:                                         data=u"not a json string")))
Same
Line 133:     def test_res_invalid_json_ret(self):
Line 134:         with self.assertRaises(se.ImageDaemonError):
Line 135:             imagetickets.remove_ticket("uuid")
Line 136: 


Line 136: 
Line 137:     @MonkeyPatch(imagetickets, 'uhttp',
Line 138:                  FakeUHTTP(FakeResponse(status=300,
Line 139:                                         data=u'{"image_daemon_message":'
Line 140:                                              u'"content"}')))
Same
Line 141:     def test_image_daemon_error_ret(self):
Line 142:         try:
Line 143:             imagetickets.remove_ticket("uuid")
Line 144:         except se.ImageDaemonError as e:


-- 
To view, visit https://gerrit.ovirt.org/52900
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I2728851a91529ec35501f423d9a798af961fb82a
Gerrit-PatchSet: 9
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Amit Aviram <aaviram at redhat.com>
Gerrit-Reviewer: Amit Aviram <aaviram at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list