|
1 | 1 | import unittest |
2 | | -from six import text_type, u, b, PY2, PY3 |
3 | | -from six.moves.urllib.parse import parse_qs |
4 | 2 | from nose.tools import raises |
5 | | -from sure import expect |
6 | 3 | import httpretty |
| 4 | +import requests |
7 | 5 |
|
8 | | -from opentok import OpenTok, Session, MediaModes, OpenTokException, __version__ |
| 6 | +from opentok import OpenTok, OpenTokException |
| 7 | + |
| 8 | +def _raise_timeout(*args): |
| 9 | + raise requests.Timeout('Timeout occurred') |
9 | 10 |
|
10 | 11 | class OpenTokSessionCreationTest(unittest.TestCase): |
11 | 12 | def setUp(self): |
12 | 13 | self.api_key = u('123456') |
13 | 14 | self.api_secret = u('1234567890abcdef1234567890abcdef1234567890') |
14 | 15 | httpretty.enable() |
15 | 16 | httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/session/create'), |
16 | | - body=u('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'), |
| 17 | + body=_raise_timeout, |
17 | 18 | status=200, |
18 | 19 | content_type=u('text/xml')) |
19 | 20 |
|
20 | 21 | def tearDown(self): |
21 | 22 | httpretty.disable() |
22 | 23 |
|
| 24 | + @raises(OpenTokException) |
23 | 25 | def test_timeout(self): |
24 | | - # TODO: tell httpretty to timeout |
25 | | - opentok = OpenTok(self.api_key, self.api_secret, timeout=5) |
26 | | - |
27 | | - session = opentok.create_session() |
28 | | - |
29 | | - # TODO: expect an exception |
| 26 | + opentok = OpenTok(self.api_key, self.api_secret, timeout=1) |
| 27 | + opentok.create_session() |
0 commit comments