Ejemplo n.º 1
0
class TestIndex(unittest.TestCase):
    """indexController中各个方法的测试用例
    """
    def setUp(self):
        """
        测试用例初始化操作
        """
        self.r = HttpUtils()
        self.files = {'file': open(BASE_DIR + '/resources/test.md', 'rb')}
        self.data = {
            'id': '61e04cca-9213-451b-94ae-8d4dc2a1a5ea',
            'height': 300,
            'width': 300
        }

    def tearDown(self):
        """
        执行结束恢复环境
        """
        pass

    def test_fastdfsTest(self):
        response = self.r.post(index.fastdfsTest, files=self.files)
        assert response.status_code == 200

    def test_ossTest(self):
        response = self.r.post(index.ossTest, files=self.files, data=self.data)
        assert response.status_code == 200, ''

    def test_imageTest(self):
        result = self.r.post(index.image, data=self.data)
        self.r.logJson(jsonObj=result.json())
        assert result.status_code == 200
Ejemplo n.º 2
0
class TestRichtext(unittest.TestCase):
    """富文本编辑器中文件上传接口测试

    Arguments:
        unittest {[type]} -- [description]
    """
    def setUp(self):
        self.r = HttpUtils()
        self.files = {'file': open(filename, 'rb')}
        self.token = getToken()
        self.contentType = http.text

    def tearDown(self):
        self.r.logJson(jsonStr=self.result.text)

    def test_fastdfs(self):
        self.result = self.r.post(url=richtext.fastdfs, files=self.files)

    def test_oss(self):
        self.result = self.r.post(url=richtext.oss, files=self.files)

    def test_streamFastdfs(self):
        """流式上传
        """
        with open(filename) as file:
            self.result = self.r.post(url=richtext.streamFastdfs, data=file)
Ejemplo n.º 3
0
class TestIndex(TestCase):
    """indexController中各个方法的测试用例
    """
    def setUp(self):
        """
        测试用例初始化操作
        """
        self.r = HttpUtils()
        self.files = {'file': open(BASE_DIR + '/resources/test.md', 'rb')}
        self.data = {
            'id': '61e04cca-9213-451b-94ae-8d4dc2a1a5ea',
            'height': 300,
            'width': 300
        }

    def tearDown(self):
        """
        执行结束恢复环境
        """
        pass

    def test_fastdfsTest(self):
        response = self.r.post(
            'http://localhost:8086/api/v1/course-study/course-import/courses-import-template?FROM_PC=1&FROM_WECHAT=1&FROM_APP=1',
            files=self.files)
        assert response.status_code == 200
Ejemplo n.º 4
0
class TestBase64(unittest.TestCase):
    """文件base64编码格式上传测试

    Arguments:
        unittest {[type]} -- [description]
    """
    def setUp(self):
        """测试用例初始化操作
        """
        self.r = HttpUtils()
        file = open(BASE_DIR + '/resources/plant.jpg', 'rb')
        filename = file.name
        suffix = os.path.splitext(filename)[1]
        contentType = mime[suffix]
        base64_str = base64.b64encode(file.read())
        self.data = {
            'trackerServerKey': 'default',
            'contentType': contentType,
            'fileName': filename,
            'body': base64_str,
            'cutSize': '300,300'
        }
        file.close()
        self.header = {'Authorization': getToken()}

    def tearDown(self):
        '用例执行完成的后置操作'
        pass

    def test_fastdfs(self):
        result = self.r.post(base64Upload.fastdfs,
                             data=self.data,
                             headers=self.header)
        self.r.logJson(jsonObj=result.json())
        assert result.status_code == 200

    def test_oss(self):
        result = self.r.post(base64Upload.oss,
                             data=self.data,
                             headers=self.header)
        self.r.logJson(jsonObj=result.json())
        assert result.status_code == 200
Ejemplo n.º 5
0
class TestcompanyConfig(unittest.TestCase):
    def setUp(self):
        """
        测试用例初始化操作
        """
        self.r = HttpUtils()

    def tearDown(self):
        assert self.result.status_code == 200
        self.r.logJson(jsonStr=self.result.text)

    def test_callbackConfig_insert(self):
        """新增企业鉴权接口配置信息
        """
        data = {
            'companyId': '61e04cca-9213-451b-94ae-8d4dc2a1a5ea',
            'callbackUrl': 'https://test9.zhixueyun.com/#/home'
        }
        self.result = self.r.post(CompanyConfig.CALLBACK_CONFIG, data=data)

    def test_callbackConfig_update(self):
        """修改企业鉴权接口配置信息
        """
        data = {
            'companyId':
            '61e04cca-9213-451b-94ae-8d4dc2a1a5ea',
            'callbackUrl':
            'http://confluence.zhixueyun.com/pages/viewpage.action?pageId=14109785'
        }
        self.result = self.r.post(CompanyConfig.CALLBACK_CONFIG, data=data)

    def test_callbackConfig_get(self):
        """查询企业鉴权接口配置信息
        """
        company_id = '61e04cca-9213-451b-94ae-8d4dc2a1a5ea'
        url = CompanyConfig.CALLBACK_CONFIG + f'?companyId={company_id}'
        self.result = self.r.get(url)
Ejemplo n.º 6
0
class TestResourcePark(unittest.TestCase):
    def setUp(self):
        """
        测试用例初始化操作
        """
        self.r = HttpUtils()

    def tearDown(self):
        assert self.result.status_code == 200
        self.r.logJson(jsonStr=self.result.text)

    def test_config_json(self):
        """
        """
        data = {
            'companyId': '61e04cca-9213-451b-94ae-8d4dc2a1a5ea',
            'json': '{"resourceKey":"","resourceSecret":"","resourceEffectiveDuration":"","accountType":"1","userInfoFields":"name,fullName,email,phoneNumber,sex"}'
        }
        self.result = self.r.post(ResourcePark.CONFIG_JSON, data=data)
Ejemplo n.º 7
0
def login(url=URL_AUTH, data=None):
    if data is None:
        return None

    r = HttpUtils()
    result = r.post(url, data=data)
    if result.status_code != 200:
        print('获取token失败')
        os._exit(0)
    token_file = open(token_json_path, 'w')
    jsonObj = json.loads(result.text)
    expires_in = jsonObj['expires_in']
    # 过期时间
    out_of_time = currentTimeMillis() + expires_in
    jsonObj['out_of_time'] = out_of_time
    jsonObj['expires_time'] = DateTime(out_of_time)
    jsonObj['create_time'] = DateTime()
    jsonStr = json.dumps(jsonObj)
    token_file.write(jsonStr)
    token_file.close()
    r.logJson(jsonStr)
    return jsonStr