Skip to content

Commit 3c3d354

Browse files
committed
fix archive stream methods and endpoints
1 parent 9ddaf26 commit 3c3d354

File tree

3 files changed

+51
-91
lines changed

3 files changed

+51
-91
lines changed

opentok/endpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def get_archive_stream(self, archive_id=None):
181181
self.api_url
182182
+ "/v2/project/"
183183
+ self.api_key
184-
+ "archive/"
184+
+ "/archive/"
185185
+ archive_id
186186
+ "/streams"
187187
)
@@ -194,7 +194,7 @@ def get_broadcast_stream(self, broadcast_id=None):
194194
self.api_url
195195
+ "/v2/partner/"
196196
+ self.api_key
197-
+ "broadcast/"
197+
+ "/broadcast/"
198198
+ broadcast_id
199199
+ "/streams"
200200
)

opentok/opentok.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -864,26 +864,27 @@ def add_archive_stream(
864864
)
865865

866866
if response:
867-
return Archive(self, response.json())
868-
elif response.status_code == 403:
869-
raise AuthError()
870-
elif response.status_code == 400:
871-
"""
872-
The HTTP response has a 400 status code in the following cases:
873-
You do not pass in a session ID or you pass in an invalid session ID.
874-
No clients are actively connected to the OpenTok session.
875-
You specify an invalid resolution value.
876-
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
877-
"""
878-
raise RequestError(response.json().get("message"))
879-
elif response.status_code == 404:
880-
raise NotFoundError("Archive or Stream not found")
881-
elif response.status_code == 405:
882-
raise ArchiveStreamModeError(
883-
"Your archive is configured with a streamMode that does not support stream manipulation."
884-
)
885-
elif response.status_code == 409:
886-
raise ArchiveError(response.json().get("message"))
867+
if response.status_code == 204:
868+
return None
869+
elif response.status_code == 403:
870+
raise AuthError()
871+
elif response.status_code == 400:
872+
"""
873+
The HTTP response has a 400 status code in the following cases:
874+
You do not pass in a session ID or you pass in an invalid session ID.
875+
No clients are actively connected to the OpenTok session.
876+
You specify an invalid resolution value.
877+
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
878+
"""
879+
raise RequestError(response.json().get("message"))
880+
elif response.status_code == 404:
881+
raise NotFoundError("Archive or Stream not found")
882+
elif response.status_code == 405:
883+
raise ArchiveStreamModeError(
884+
"Your archive is configured with a streamMode that does not support stream manipulation."
885+
)
886+
elif response.status_code == 409:
887+
raise ArchiveError(response.json().get("message"))
887888
else:
888889
raise RequestError("An unexpected error occurred", response.status_code)
889890

@@ -910,26 +911,27 @@ def remove_archive_stream(
910911
)
911912

912913
if response:
913-
return Archive(self, response.json())
914-
elif response.status_code == 403:
915-
raise AuthError()
916-
elif response.status_code == 400:
917-
"""
918-
The HTTP response has a 400 status code in the following cases:
919-
You do not pass in a session ID or you pass in an invalid session ID.
920-
No clients are actively connected to the OpenTok session.
921-
You specify an invalid resolution value.
922-
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
923-
"""
924-
raise RequestError(response.json().get("message"))
925-
elif response.status_code == 404:
926-
raise NotFoundError("Archive or Stream not found")
927-
elif response.status_code == 405:
928-
raise ArchiveStreamModeError(
929-
"Your archive is configured with a streamMode that does not support stream manipulation."
930-
)
931-
elif response.status_code == 409:
932-
raise ArchiveError(response.json().get("message"))
914+
if response.status_code == 204:
915+
return None
916+
elif response.status_code == 403:
917+
raise AuthError()
918+
elif response.status_code == 400:
919+
"""
920+
The HTTP response has a 400 status code in the following cases:
921+
You do not pass in a session ID or you pass in an invalid session ID.
922+
No clients are actively connected to the OpenTok session.
923+
You specify an invalid resolution value.
924+
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
925+
"""
926+
raise RequestError(response.json().get("message"))
927+
elif response.status_code == 404:
928+
raise NotFoundError("Archive or Stream not found")
929+
elif response.status_code == 405:
930+
raise ArchiveStreamModeError(
931+
"Your archive is configured with a streamMode that does not support stream manipulation."
932+
)
933+
elif response.status_code == 409:
934+
raise ArchiveError(response.json().get("message"))
933935
else:
934936
raise RequestError("An unexpected error occurred", response.status_code)
935937

tests/test_archive.py

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
2-
from six import text_type, u, b, PY2, PY3
3-
from nose.tools import raises
2+
from six import u, PY2, PY3
43
from expects import *
54
import httpretty
65
from sure import expect
@@ -102,64 +101,23 @@ def test_stop_archive(self):
102101
expect(archive).to(have_property(u("output_mode"), OutputModes.composed))
103102
expect(archive).to(have_property(u("url"), None))
104103

105-
106-
107104
@httpretty.activate
108105
def test_add_archive_stream(self):
109106
archive_id = u("ARCHIVEID")
110107
url = f"https://api.opentok.com/v2/project/{self.api_key}/archive/{archive_id}/streams"
111-
112-
payload = {
113-
"hasAudio": True,
114-
"hasVideo": True,
115-
"addStream": self.stream1
116-
}
108+
httpretty.register_uri(httpretty.PATCH, url, responses=[httpretty.Response(body=u(""), status=204)])
117109

118-
httpretty.register_uri(httpretty.PATCH,
119-
url,
120-
responses=[
121-
httpretty.Response(body=json.dumps(payload),
122-
content_type="application/json",
123-
status=200)
124-
])
125-
126-
response = requests.patch(url)
127-
128-
response.status_code.should.equal(200)
129-
response.json().should.equal({
130-
"hasAudio": True,
131-
"hasVideo": True,
132-
"addStream": self.stream1
133-
})
134-
135-
response.headers["Content-Type"].should.equal("application/json")
110+
response = self.opentok.add_archive_stream(archive_id=archive_id, stream_id=self.stream1)
111+
assert response == None
136112

137113
@httpretty.activate
138114
def test_remove_archive_stream(self):
139115
archive_id = u("ARCHIVEID")
140116
url = f"https://api.opentok.com/v2/project/{self.api_key}/archive/{archive_id}/streams"
141-
142-
payload = {
143-
"removeStream": self.stream1
144-
}
145-
146-
httpretty.register_uri(httpretty.PATCH,
147-
url,
148-
responses=[
149-
httpretty.Response(body=json.dumps(payload),
150-
content_type="application/json",
151-
status=200)
152-
])
117+
httpretty.register_uri(httpretty.PATCH, url, responses=[httpretty.Response(body=u(""), status=204)])
153118

154-
response = requests.patch(url)
155-
156-
response.status_code.should.equal(200)
157-
response.json().should.equal({
158-
"removeStream": self.stream1
159-
})
160-
161-
response.headers["Content-Type"].should.equal("application/json")
162-
119+
response = self.opentok.remove_archive_stream(archive_id=archive_id, stream_id=self.stream1)
120+
assert response == None
163121

164122
@httpretty.activate
165123
def test_delete_archive(self):

0 commit comments

Comments
 (0)