Skip to content

Commit 7d22f7a

Browse files
authored
Merge branch 'main' into selective_stream
2 parents 4af1a64 + 5c6dd79 commit 7d22f7a

File tree

11 files changed

+173
-34
lines changed

11 files changed

+173
-34
lines changed

.bumpversion.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[bumpversion]
2+
current_version = 3.1.0
3+
commit = True
4+
tag = False
5+
6+
[bumpversion:file:opentok/version.py]

.github/workflows/ot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [2.7, 3.5, 3.6, 3.7]
11+
python-version: [3.5, 3.6, 3.7, 3.8.8, 3.9]
1212

1313
steps:
1414
- uses: actions/checkout@v2

DEVELOPING.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,30 @@ this project. If you use this package within your own software as is but don't p
1616
location on your system, which helps keep you out of dependency hell. You can exit the
1717
environment using `$ deactivate`.
1818

19-
* [tox](https://testrun.org/tox/): a testing automation tool that can load many Python versions.
20-
This tool allows the project to test against all the compatible versions of Python by leveraging
21-
virtualenv and describing the tasks in a metadata file.
19+
* [act](https://github.com/nektos/act): a tool for running Github Actions locally. This tool allows
20+
developers to easily replicate the same Continuous Integration pipelines we use for code validation.
2221

2322
## Tasks
2423

24+
## Setup
25+
26+
We currently recommend setting up a development environment using `virtualenv` and installing dependencies
27+
with `pip`. While the Python Packaging Authority recommends `Pipenv` to manage dependencies, `Pipenv` does
28+
not install the OpenTok library correctly from source at this time.
29+
30+
We recommend setting up a Python 3.5 or higher `virtualenv` environment. This allows you to isolate dependencies
31+
for work on the OpenTok library without interfering with any other projects or installations on your system.
32+
33+
$ virtualenv env
34+
$ source env/bin/activate
35+
$ pip install -r requirements.txt -r test_requirements.txt
36+
37+
Some IDEs, like Visual Studio Code, will automatically detect the `virtualenv` and use it.
38+
39+
When you are done, you can leave the `virtualenv` by deactivating it:
40+
41+
$ deactivate
42+
2543
### Building
2644

2745
Building isn't necessarily required for a python package, but it is possible. By running the command
@@ -32,10 +50,19 @@ other script in your environment, and continue to update and you make changes.
3250

3351
### Testing
3452

35-
This project's tests are kicked off by tox. The `tox.ini` file describes the automation. In
36-
a nutshell, it selects a Python version, installs test dependencies stored in
37-
`test_requirements.txt`, and then runs `nosetests`. [Nose](https://nose.readthedocs.org) is the
38-
actual test runner. All of this can be ran using the following command: `$ tox`
53+
This project's tests are built using the `unittest` [`Nose'](https://nose.readthedocs.org) modules.
54+
To run the unit tests, install the core as well as development dependencies inside your `virtualenv`:
55+
56+
$ pip install -r requirements.txt -r test_requirements.txt
57+
58+
You can manually run the test suite for your version of python with:
59+
60+
$ nosetests
61+
62+
If you would like to run the test suite against a variety of Python versions, we recommend installing
63+
`act` and running out Github Action "test" workflow:
64+
65+
$ act --quiet
3966

4067
### Generating Documentation
4168

@@ -45,19 +72,28 @@ actual test runner. All of this can be ran using the following command: `$ tox`
4572

4673
In order to create a release, the following should be completed in order.
4774

48-
1. Ensure all tests are passing (`tox`) and that there is enough test coverage.
75+
#### Prep the release
76+
77+
1. Ensure all tests are passing (`act`) and that there is enough test coverage.
4978
1. Make sure you are on the `master` branch of the repository, with all changes merged/committed already.
50-
1. Update the version number in the source code (`opentok/version.py`) and the README. See [Versioning](#versioning) for
79+
1. Create a new branch named `release-x.y.z`, with the release version number
80+
1. Update the version number with `bumpversion`. See [Versioning](#versioning) for
5181
information about selecting an appropriate version number.
5282
1. Commit the version number change with the message ("Update to version v.x.x.x"), substituting the new version number.
83+
1. Create a new pull request with this branch
84+
85+
#### Once PR is merged into `master`
86+
1. Make sure you are on the `master` branch of the repository
87+
1. Run `git pull --rebase origin master` to make sure your local code is up-to-date
5388
1. Create a git tag: `git tag -a vx.y.z -m "Release vx.y.z"`
89+
1. Run `git push origin vx.y.z` to push the tag to Github
5490
1. Ensure you have permission to update the `opentok` package on PyPI: <https://pypi.python.org/pypi/opentok>.
55-
1. Run `python setup.py sdist upload`, which will build and upload the package to PyPI.
56-
1. Change the version number for future development by adding "a1", then make another commit with the message
57-
"Beginning development on next version".
58-
1. Push the changes to the main repository (`git push origin master`).
59-
1. Upload the `dist/opentok-x.y.z.tar.gz` file to the
60-
[Github Releases](https://github.com/opentok/opentok-python-sdk/releases) page with a description and release notes.
91+
1. Run the deploy scripts:
92+
1. `make clean`
93+
1. `make dist`
94+
1. `make release`
95+
1. Create a new release on the [Github Releases](https://github.com/opentok/opentok-python-sdk/releases) page,
96+
and attach the files in `dist/` to the release
6197

6298
## Workflow
6399

@@ -73,10 +109,6 @@ from 1.
73109
### Branches
74110

75111
* `master` - the main development branch.
76-
* `feat.foo` - feature branches. these are used for longer running tasks that cannot be accomplished in one commit.
77-
once merged into master, these branches should be deleted.
78-
* `vx.x.x` - if development for a future version/milestone has begun while master is working towards a sooner
79-
release, this is the naming scheme for that branch. once merged into master, these branches should be deleted.
80112

81113
### Tags
82114

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: clean test dist coverage install requirements release release-test
2+
3+
clean:
4+
rm -rf dist build
5+
6+
coverage:
7+
pytest -v --cov
8+
coverage html
9+
10+
test:
11+
nosetests -v
12+
13+
dist:
14+
python setup.py sdist --formats zip,gztar bdist_wheel
15+
16+
release:
17+
twine upload dist/*
18+
19+
install: requirements
20+
21+
requirements: .requirements.txt
22+
23+
.requirements.txt: requirements.txt
24+
python -m pip install --upgrade pip setuptools
25+
python -m pip install -r requirements.txt
26+
python -m pip freeze > .requirements.txt

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Requirements
502502

503503
You need an OpenTok API key and API secret, which you can obtain at https://dashboard.tokbox.com/
504504

505-
The OpenTok Python SDK requires Python 2.6, 2.7, 3.3, 3.4, 3.5 or 3.6
505+
The OpenTok Python SDK requires Python 3.5 or higher
506506

507507
Release Notes
508508
-------------

opentok/endpoints.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Endpoints(object):
77
Class that provides the endpoint urls
88
"""
99

10+
1011
def __init__(self, api_url, api_key):
1112
self.api_url = api_url
1213
self.api_key = api_key
@@ -152,5 +153,3 @@ def get_broadcast_stream(self, broadcast_id=None):
152153
+ broadcast_id
153154
+ "/streams"
154155
)
155-
156-

opentok/opentok.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import random # _create_jwt_auth_header
1616
import logging # logging
1717
import warnings # Native. Used for notifying deprecations
18+
import os
1819

1920

2021
# compat
@@ -84,8 +85,6 @@ class ArchiveModes(Enum):
8485

8586
logger = logging.getLogger("opentok")
8687

87-
88-
8988
class Client(object):
9089

9190
"""Use this SDK to create tokens and interface with the server-side portion
@@ -405,6 +404,7 @@ def create_session(
405404
proxies=self.proxies,
406405
timeout=self.timeout,
407406
)
407+
408408
response.encoding = "utf-8"
409409

410410
if response.status_code == 403:
@@ -1561,6 +1561,8 @@ def _create_jwt_auth_header(self):
15611561
}
15621562

15631563
return jwt.encode(payload, self.api_secret, algorithm="HS256")
1564+
1565+
15641566

15651567
class OpenTok(Client):
15661568
def __init__(
@@ -1583,3 +1585,5 @@ def __init__(
15831585
timeout=timeout,
15841586
app_version=app_version
15851587
)
1588+
1589+

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ def find_version(*file_paths):
6262
'License :: OSI Approved :: MIT License',
6363

6464
'Programming Language :: Python :: 3',
65-
'Programming Language :: Python :: 3.3',
66-
'Programming Language :: Python :: 3.4',
6765
'Programming Language :: Python :: 3.5',
6866
'Programming Language :: Python :: 3.6',
67+
'Programming Language :: Python :: 3.7',
68+
'Programming Language :: Python :: 3.8',
69+
'Programming Language :: Python :: 3.9',
6970

7071
'Topic :: Communications',
7172
'Topic :: Communications :: Chat',

test_requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ nose
22
httpretty
33
expects
44
wheel
5-
sure
5+
twine
6+
bump2version
7+
sure

tests/test_opentok.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import unittest
2+
from requests.models import Response
3+
4+
from six import text_type, u, b, PY2, PY3
5+
from nose.tools import raises
6+
7+
import requests
8+
import httpretty
9+
from sure import expect
10+
import random
11+
import string
12+
13+
import json
14+
15+
import opentok
16+
from opentok import Client, OpenTok
17+
18+
19+
class OpenTokTest(unittest.TestCase):
20+
def setUp(self):
21+
self.api_key = "123456"
22+
self.api_secret = "1234567890abcdef1234567890abcdef1234567890"
23+
self.session_id = "SESSIONID"
24+
self.opentok = Client(self.api_key, self.api_secret)
25+
token = string.ascii_letters+string.digits
26+
self.jwt_token_string = ''.join(random.choice(token[:100]))
27+
self.stream_id_1 = "Stream1"
28+
29+
@httpretty.activate
30+
def test_mute_all_response(self):
31+
self.url = "https://api.opentok.com/v2/project/{0}/session/{1}/mute".format(
32+
self.api_key,
33+
self.session_id)
34+
35+
httpretty.register_uri(httpretty.POST,
36+
self.url,
37+
responses=[
38+
httpretty.Response(body="Testing text matches inside of the JSON file",
39+
content_type="application/json",
40+
adding_headers= {"x-opentok-auth": self.jwt_token_string},
41+
status=201)
42+
])
43+
44+
45+
response = requests.post(self.url)
46+
47+
response.status_code.should.equal(201)
48+
response.text.should.equal("Testing text matches inside of the JSON file")
49+
response.headers["x-opentok-auth"].should.equal(self.jwt_token_string)
50+
response.headers["Content-Type"].should.equal("application/json")
51+
52+
@httpretty.activate
53+
def test_mute_stream_response(self):
54+
self.url = "https://api.opentok.com/v2/project/${0}/session/${1}/stream/${2}/mute".format(
55+
self.api_key,
56+
self.session_id,
57+
self.stream_id_1)
58+
59+
httpretty.register_uri(httpretty.POST,
60+
self.url,
61+
responses=[
62+
httpretty.Response(body="Testing body of the JSON file",
63+
content_type="application/json",
64+
adding_headers= {"x-opentok-auth": self.jwt_token_string},
65+
status=201)
66+
])
67+
68+
69+
response = requests.post(self.url)
70+
71+
response.status_code.should.equal(201)
72+
response.text.should.equal("Testing body of the JSON file")
73+
response.headers["x-opentok-auth"].should.equal(self.jwt_token_string)
74+
response.headers["Content-Type"].should.equal("application/json")
75+

0 commit comments

Comments
 (0)