Skip to content

Commit

Permalink
Created dlep unicode unit test
Browse files Browse the repository at this point in the history
Also fixed test HTTP producer on error.
  • Loading branch information
qstokkink committed Sep 5, 2017
1 parent ad5bd7f commit a747256
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Tribler/Test/Core/Modules/RestApi/base_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def startProducing(self, consumer):
consumer.write(self.body)
return succeed(None)

def stopProducing(self):
return succeed(None)


class AbstractBaseApiTest(TestAsServer):
"""
Expand Down Expand Up @@ -69,7 +72,9 @@ def setUpPreSession(self):
def do_request(self, endpoint, request_type, post_data, raw_data):
agent = Agent(reactor, pool=self.connection_pool)
return agent.request(request_type, 'http://localhost:%s/%s' % (self.session.get_http_api_port(), endpoint),
Headers({'User-Agent': ['Tribler ' + version_id]}), POSTDataProducer(post_data, raw_data))
Headers({'User-Agent': ['Tribler ' + version_id],
"Content-Type": ["text/plain; charset=utf-8"]}),
POSTDataProducer(post_data, raw_data))


class AbstractApiTest(AbstractBaseApiTest):
Expand Down
22 changes: 22 additions & 0 deletions Tribler/Test/Core/Modules/RestApi/test_downloads_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ def verify_download(_):
return self.do_request('downloads', expected_code=200, request_type='PUT', post_data=post_data,
expected_json=expected_json).addCallback(verify_download)

@deferred(timeout=10)
def test_start_download_from_file_unicode(self):
"""
Testing whether we can start a download from a file with a unicode name
"""
def verify_download(response):
self.assertTrue(json.loads(response)['started'])
self.assertGreaterEqual(len(self.session.get_downloads()), 1)
dl = self.session.get_downloads()[0]
dl.tracker_status[u"\u266b"] = [0, 'Not contacted yet']
tdef = dl.get_def()
tdef.input['name'] = u'video\u266b'
return self.do_request('downloads?get_peers=1&get_pieces=1', expected_code=200)

ufile = os.path.join(TESTS_DATA_DIR, u'video\u266b.avi.torrent')
udest = os.path.join(self.session_base_dir, u'video\u266b')

post_data = (u'uri=file:%s&destination=%s' % (ufile, udest)).encode('utf-8')
self.should_check_equality = False
return self.do_request('downloads', expected_code=200, request_type='PUT', post_data=post_data,
raw_data=True).addCallback(verify_download)

@deferred(timeout=10)
def test_start_download_from_magnet(self):
"""
Expand Down
Binary file added Tribler/Test/data/video♫.avi.torrent
Binary file not shown.

0 comments on commit a747256

Please sign in to comment.