Skip to content

Commit 25f815f

Browse files
committed
add user_agent as a property and create append method
1 parent 4b4d82f commit 25f815f

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

opentok/opentok.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def __init__(
115115
self._proxies = None
116116
self.endpoints = Endpoints(api_url, self.api_key)
117117
self._app_version = __version__ if app_version == None else app_version
118+
self._user_agent = (
119+
f"OpenTok-Python-SDK/{self.app_version} python/{platform.python_version()}"
120+
)
118121
# JWT custom claims - Default values
119122
self._jwt_livetime = 3 # In minutes
120123

@@ -134,6 +137,17 @@ def app_version(self):
134137
def app_version(self, value):
135138
self._app_version = value
136139

140+
@property
141+
def user_agent(self):
142+
return self._user_agent
143+
144+
@user_agent.setter
145+
def user_agent(self, value):
146+
self._user_agent = value
147+
148+
def append_to_user_agent(self, value):
149+
self.user_agent = self.user_agent + value
150+
137151
@property
138152
def jwt_livetime(self):
139153
return self._jwt_livetime

tests/test_getter_setter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import unittest
2-
from six import text_type, u, b, PY2, PY3
3-
from nose.tools import raises
2+
from six import u
43
from expects import *
54

65
from opentok import Client, __version__
7-
import time
86

97

108
class GetterSetterTest(unittest.TestCase):

tests/test_initialization.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# import time
2-
# import urllib2
31
import unittest
42
from nose.tools import raises
3+
import platform
54

6-
# from xml.dom.minidom import parseString
7-
8-
from opentok import Client # , OpenTokException
5+
from opentok import Client
96

107

118
class OpenTokInitializationTest(unittest.TestCase):
@@ -40,6 +37,16 @@ def test_initialization_with_timeout(self):
4037
opentok = Client(self.api_key, self.api_secret, timeout=5)
4138
assert isinstance(opentok, Client)
4239

40+
def test_user_agent(self):
41+
opentok = Client(self.api_key, self.api_secret, self.api_url)
42+
assert opentok.user_agent == f"OpenTok-Python-SDK/{opentok.app_version} python/{platform.python_version()}"
43+
44+
def test_append_to_user_agent(self):
45+
opentok = Client(self.api_key, self.api_secret, self.api_url)
46+
opentok.append_to_user_agent('/my_appended_user_agent_string')
47+
assert opentok.user_agent == f"OpenTok-Python-SDK/{opentok.app_version} python/{platform.python_version()}/my_appended_user_agent_string"
48+
49+
4350

4451
if __name__ == "__main__":
4552
unittest.main()

tests/test_session_creation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
2-
from six import text_type, u, b, PY2, PY3
2+
from six import u, b
33
from six.moves.urllib.parse import parse_qs
44
from nose.tools import raises
55
from expects import *
66
import httpretty
77
from .validate_jwt import validate_jwt_header
8+
import platform
89

910
from opentok import (
1011
Client,
@@ -38,7 +39,7 @@ def test_create_default_session(self):
3839

3940
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
4041
expect(httpretty.last_request().headers[u("user-agent")]).to(
41-
contain(u("OpenTok-Python-SDK/") + __version__)
42+
equal(u("OpenTok-Python-SDK/") + __version__ + ' python/' + platform.python_version())
4243
)
4344
body = parse_qs(httpretty.last_request().body)
4445
expect(body).to(have_key(b("p2p.preference"), [b("enabled")]))

0 commit comments

Comments
 (0)