Commit 68ede6ea authored by liangfenglong's avatar liangfenglong

更新上传第一个demo:test_enter_live进入直播间

parent e982382b
# something here
LIVE_USER = {
'phone': '18633668899',
'password': '123456'
'phone': '12345678912',
'password': 'a123456'
}
LIVE_WATCHER = {
'phone': '13608913121',
'password': 'a123456'
}
HERA_SESSION = 'tm115sjlt2nzimgxfa34c91xghvor1ue'
# 公共参数
GENGMEI_PARAMS = {
'app_name': 'com.wanmeizhensuo.zhensuo',
......@@ -23,4 +29,5 @@ GENGMEI_PARAMS = {
'uuid': '19a56bb4-4ff7-46d4-b156-904297b91385' # 不影响逻辑
}
BACKEND_ADMIN = 'https://backend.igengmei.com'
# BACKEND_ADMIN = 'https://backend.igengmei.com'
BACKEND_ADMIN = 'http://backend.paas-develop.env'
......@@ -6,7 +6,11 @@ from utils.gmhttp import require_login
class LiveCase(unittest.TestCase):
live_id = None
'''
'''
channel_id = None
stream_id = None
@classmethod
def setUpClass(cls):
......@@ -16,7 +20,9 @@ class LiveCase(unittest.TestCase):
2. hera上为直播做配置
:return:
'''
cls.host = settings.BACKEND_ADMIN
cls.create_live()
cls.stream_info()
@classmethod
def tearDownClass(cls):
......@@ -29,20 +35,22 @@ class LiveCase(unittest.TestCase):
创建直播间
:return:
'''
if cls.live_status():
return
uri = '/api/live/push_live_info'
url = settings.BACKEND_ADMIN + uri
params = settings.GENGMEI_PARAMS.update(
{
'notice': '测试',
'tag_id': 3161,
'title': '测试',
'cover_url': '2021/01/04/1506/ba72d863e638',
'device_type': 1
}
)
params = dict(settings.GENGMEI_PARAMS,
**{
'notice': '测试',
'tag_id': 3161,
'title': '测试',
'cover_url': '2021/01/04/1506/ba72d863e638',
'device_type': 1
}
)
r = requests.get(url, params=params).json()
cls.live_id = r['data']['channel']
cls.channel_id = r['data']['channel']
print('创建直播间成功!')
@classmethod
@require_login
......@@ -51,12 +59,33 @@ class LiveCase(unittest.TestCase):
关闭直播间
:return:
'''
if cls.live_id == None:
if cls.stream_id == None:
print('没有成功创建直播间!')
return
uri = '/api/live/finish'
url = settings.BACKEND_ADMIN + uri
data = {'channel_id': cls.live_id}
data = {'channel_id': cls.channel_id}
r = requests.post(url, data=data).json()
if r['error'] == 0:
print('关闭直播间成功!')
@classmethod
@require_login
def stream_info(cls):
if cls.stream_id:
return
uri = '/api/live/get_live_info/anchor'
url = settings.BACKEND_ADMIN + uri
params = dict(settings.GENGMEI_PARAMS, channel_id=cls.channel_id)
r = requests.get(url, params=params).json()
cls.stream_id = r['data']['id']
@classmethod
def live_status(cls):
if not cls.stream_id:
return False
uri = '/api/janus/live/polling'
url = settings.BACKEND_ADMIN + uri
params = dict(settings.GENGMEI_PARAMS, stream_id=cls.stream_id)
r = requests.get(url, params=params).json()
return not r['data']['stream_status']['is_finish']
import requests
from utils.gmhttp import require_login
from .livecase import LiveCase
class LiveXXX(LiveCase):
@require_login
def test_xxx(self):
'''
to be continued
:return:
'''
# 直播id self.live_id
import requests
from utils.gmhttp import require_login
from .livecase import LiveCase
from conf import settings
class LiveEnter(LiveCase):
'''进入直播间'''
def setUp(self):
uri = '/api/live/enter'
self.url = self.host + uri
self.params = dict(settings.GENGMEI_PARAMS, **{
'channel_id': self.channel_id
})
def test_live_enter_visitor(self):
'''
游客进入直播间
'''
rep = requests.get(self.url, params=self.params).json()
assert rep['error'] == 0, rep
print('游客进入直播间成功!')
@require_login(settings.LIVE_WATCHER)
def test_live_enter_user(self):
'''
app用户进入直播间
'''
rep = requests.get(self.url, params=self.params).json()
assert rep['error'] == 0, rep
print('app用户进入直播间成功!')
@require_login(settings.LIVE_USER)
def test_live_enter_author(self):
'''
主播进入直播间
'''
rep = requests.get(self.url, params=self.params).json()
assert rep['error'] == 0, rep
print('主播进入直播间成功!')
......@@ -19,7 +19,6 @@ class LoginFailedException(Exception):
# 支持更换用户
def require_login(arg=None, **user_dict):
'''
依然使用requests,只不过在使用过程中被替换成了gmhttp
......@@ -84,7 +83,7 @@ class _Gmhttp(requests.Session):
self.params = deepcopy(self._params)
@classmethod
def instance(cls, userinfo):
def instance(cls, **userinfo):
# 登录,如果phone和password有任意None 则使用默认账户
phone = userinfo.get('phone', _Gmhttp._userinfo['phone'])
password = userinfo.get('password', _Gmhttp._userinfo['password'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment