Last active
July 8, 2019 01:16
-
-
Save guitarical/0483d7826eadaa12f598 to your computer and use it in GitHub Desktop.
Url request unit testing debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
from kivy.network.urlrequest import UrlRequest | |
def on_success(req, request): | |
print "success: ", request | |
def on_redirect(req, request): | |
print "redirect: ", req, request | |
def on_failure(req, request): | |
print "failure: ", req, request | |
def on_error_method(req, request): | |
print "error: ", req, request | |
class RequestManager(object): | |
try: | |
req = UrlRequest('http://127.0.0.1:8000/restrouter/members/?format=json', | |
on_success, | |
on_redirect, | |
on_failure, | |
on_error_method) | |
#print request <-- this causes an error | |
print req | |
print "These are the attributes of the req object: " + str(dir(req)) | |
except: | |
print "ERROR" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from req_manager import RequestManager | |
from mock import MagicMock | |
import mock | |
class RequestManagerTest(unittest.TestCase): | |
@mock.patch('kivy.network.urlrequest.UrlRequest') | |
def test_request_manager(self, UrlRequest): | |
successful_request = RequestManager() | |
print "These are the attributes of RequestManager class: " + str(dir(successful_request)) | |
#print successful_request.url_request.im_class.req._result | |
expected_request = [{u'first_item': u'item1'}] | |
self.assertEqual(expected_request, successful_request.request) # <--- RequestManager does not have 'request' attribute | |
if __name__ == '__main__': | |
unittest.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment