Skip to content

Commit

Permalink
Merge pull request #1317 from longguikeji/feature-402
Browse files Browse the repository at this point in the history
feat: 🎸 增加一些测试代码
  • Loading branch information
hanbinloop authored Sep 29, 2022
2 parents 8dd4ba6 + 3f72d8a commit 7c6ab9c
Show file tree
Hide file tree
Showing 14 changed files with 632 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/v1/views/languape.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create_language(request, tenant_id: str,data:LanguageCreateIn):
)
@operation(LanguageDeleteOut, roles=[PLATFORM_ADMIN])
def delete_language(request, tenant_id: str,id:str):
""" 创建自定义语言包
""" 删除自定义语言包
"""
language_data = get_object_or_404(
LanguageData.valid_objects,
Expand Down
74 changes: 73 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,76 @@ def setUp(self):
"deny_request_url":""
},
type="approve_system_arkid"
)
)
# 认证因素
config = TenantExtensionConfig()
config.tenant = self.tenant
config.extension = Extension.active_objects.get(package='com.longgui.auth.factor.password')
config.config = {
"login_enabled_field_names":[
{
"key":"username"
}
],
"register_enabled_field_names":[
{
"key":"username"
}
],
"is_apply":False,
"regular":"",
"title":""
}
config.name = "default"
config.type = "password"
config.save()
self.auth_factor = config
# 认证规则
config = TenantExtensionConfig()
config.tenant = self.tenant
config.extension = Extension.active_objects.get(package='com.longgui.authrule.retrytimes')
config.config = {
"main_auth_factor":{
"id":"70f8d39e30cc40de8a70ec6495c21e84",
"name":"default",
"package":"com.longgui.auth.factor.password"
},
"try_times":3,
"second_auth_factor":{
"id":"7316fc337547450aa4d4038567949ec2",
"name":"图形验证码",
"package":"com.longgui.auth.factor.authcode"
},
"expired":30
}
config.name = '认证规则:登录失败三次启用图形验证码'
config.type = 'retry_times'
config.save()
self.auth_rules = config
# 自动认证
config = TenantExtensionConfig()
config.tenant = self.tenant
config.extension = Extension.active_objects.get(package='com.longgui.auto.auth.kerberos')
config.config = {
"service_principal":"http://localhost:8001"
}
config.name = 'test认证'
config.type = 'kerberos'
config.save()
self.auto_auth = config
# 一个插件
self.extension = Extension.active_objects.first()
# 主题
config = TenantExtensionConfig()
config.tenant = self.tenant
config.extension = Extension.active_objects.filter(package = 'com.longgui.theme.bootswatch').first()
config.config = {
"priority":1,
"css_url":"https://bootswatch.com/5/materia/bootstrap.min.css"
}
config.name = 'test'
config.type = 'materia'
config.save()
self.front_theme = config
# 语言
self.language_data = LanguageData.objects.create(name='语言包')
29 changes: 29 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from tests import TestCase

class TestAuthApi(TestCase):

def test_auth(self):
'''
认证
'''
url = '/api/v1/tenant/{}/auth/?event_tag=com.longgui.auth.factor.password.auth'.format(self.tenant.id)
body = {
"username":"admin",
"password":"admin",
"config_id":"70f8d39e-30cc-40de-8a70-ec6495c21e84"
}
resp = self.client.post(url, body ,content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_reset_passowrd(self):
'''
重置密码
'''
url = '/api/v1/tenant/{}/reset_password/?event_tag=com.longgui.auth.factor.password.auth'.format(self.tenant.id)
body = {
"username":"admin",
"password":"admin",
"config_id":"70f8d39e-30cc-40de-8a70-ec6495c21e84"
}
resp = self.client.post(url, body ,content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
87 changes: 87 additions & 0 deletions tests/test_auth_factor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from tests import TestCase

class TestAuthFactorApi(TestCase):

def test_list_auth_factors(self):
'''
认证因素列表
'''
url = '/api/v1/tenant/{}/auth_factors/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_get_auth_factor(self):
'''
获取认证因素
'''
url = '/api/v1/tenant/{}/auth_factors/{}/'.format(self.tenant.id, self.auth_factor.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_create_auth_factor(self):
'''
创建认证因素
'''
url = '/api/v1/tenant/{}/auth_factors/'.format(self.tenant.id)
body = {
"type":"password",
"config":{
"login_enabled":True,
"register_enabled":True,
"login_enabled_field_names":[
{
"key":None
}
],
"register_enabled_field_names":[
{
"key":None
}
],
"is_apply":False,
"regular":"",
"title":""
},
"name":"defaultpass",
"package":"com.longgui.auth.factor.password"
}
resp = self.client.post(url, body, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_update_auth_factor(self):
'''
编辑认证因素
'''
url = '/api/v1/tenant/{}/auth_factors/{}/'.format(self.tenant.id, self.auth_factor.id)
body = {
"type":"password",
"config":{
"login_enabled":True,
"register_enabled":True,
"login_enabled_field_names":[
{
"key":"username"
}
],
"register_enabled_field_names":[
{
"key":"username"
}
],
"is_apply":False,
"regular":"",
"title":""
},
"name":"default",
"package":"com.longgui.auth.factor.password"
}
resp = self.client.post(url, body, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_delete_auth_factor(self):
'''
删除认证因素
'''
url = '/api/v1/tenant/{}/auth_factors/{}/'.format(self.tenant.id, self.auth_factor.id)
resp = self.client.delete(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
82 changes: 82 additions & 0 deletions tests/test_auth_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from tests import TestCase

class TestAuthRulesApi(TestCase):

def test_list_auth_rules(self):
'''
认证规则列表
'''
url = '/api/v1/tenant/{}/auth_rules/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_get_auth_rule(self):
'''
获取认证规则
'''
url = '/api/v1/tenant/{}/auth_rules/{}/'.format(self.tenant.id, self.auth_rules.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_create_auth_rule(self):
'''
创建认证规则
'''
url = '/api/v1/tenant/{}/auth_rules/'.format(self.tenant.id)
body = {
"config":{
"main_auth_factor":{
"id":"70f8d39e30cc40de8a70ec6495c21e84",
"name":"default",
"package":"com.longgui.auth.factor.password"
},
"try_times":3,
"second_auth_factor":{
"id":"7316fc337547450aa4d4038567949ec2",
"name":"图形验证码",
"package":"com.longgui.auth.factor.authcode"
},
"expired":30
},
"name":"认证规则:登录失败三次启用图形验证码",
"type":"retry_times",
"package":"com.longgui.authrule.retrytimes"
}
resp = self.client.post(url, body, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_update_auth_rule(self):
'''
编辑认证规则
'''
url = '/api/v1/tenant/{}/auth_rules/{}/'.format(self.tenant.id, self.auth_rules.id)

body = {
"config":{
"main_auth_factor":{
"id":"70f8d39e30cc40de8a70ec6495c21e84",
"name":"default",
"package":"com.longgui.auth.factor.password"
},
"try_times":3,
"second_auth_factor":{
"id":"7316fc337547450aa4d4038567949ec2",
"name":"图形验证码",
"package":"com.longgui.auth.factor.authcode"
},
"expired":30
},
"name":"认证规则:登录失败三次启用图形验证码",
"type":"retry_times",
"package":"com.longgui.authrule.retrytimes"
}
resp = self.client.post(url, body, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_delete_auth_rule(self):
'''
删除认证规则
'''
url = '/api/v1/tenant/{}/auth_rules/{}/'.format(self.tenant.id, self.auth_rules.id)
resp = self.client.delete(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
59 changes: 59 additions & 0 deletions tests/test_auto_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from tests import TestCase

class TestAutoAuthApi(TestCase):

def test_list_auto_auths(self):
'''
自动认证列表
'''
url = '/api/v1/tenant/{}/auto_auths/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_get_auto_auth(self):
'''
获取自动认证
'''
url = '/api/v1/tenant/{}/auto_auths/{}/'.format(self.tenant.id, self.auto_auth.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_create_auto_auth(self):
'''
创建应用
'''
url = '/api/v1/tenant/{}/auto_auths/'.format(self.tenant.id)
body = {
"config":{
"service_principal":"http://localhost:8001"
},
"name":"test认证",
"type":"kerberos",
"package":"com.longgui.auto.auth.kerberos"
}
resp = self.client.post(url, body ,content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_update_auto_auth(self):
'''
编辑自动认证
'''
url = '/api/v1/tenant/{}/auto_auths/{}/'.format(self.tenant.id, self.auto_auth.id)
body = {
"config":{
"service_principal":"http://localhost:8001"
},
"name":"test认证",
"type":"kerberos",
"package":"com.longgui.auto.auth.kerberos"
}
resp = self.client.put(url, body ,content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_delete_auto_auth(self):
'''
删除自动认证
'''
url = '/api/v1/tenant/{}/auto_auths/{}/'.format(self.tenant.id, self.auto_auth.id)
resp = self.client.delete(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
11 changes: 11 additions & 0 deletions tests/test_bi_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from tests import TestCase

class TestBiSystemApi(TestCase):

def test_list_bi_systems(self):
'''
BI系统列表
'''
url = '/api/v1/tenant/{}/bi_systems/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
27 changes: 27 additions & 0 deletions tests/test_bind_saas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from tests import TestCase

class TestBindSaasApi(TestCase):

def test_get_bind_saas(self):
'''
查询 saas 绑定信息
'''
url = '/api/v1/tenant/{}/bind_saas/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_get_bind_saas_slug(self):
'''
查询 saas slug 绑定信息
'''
url = '/api/v1/tenant/{}/bind_saas/slug/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())

def test_get_bind_saas_info(self):
'''
查询 saas info 绑定信息
'''
url = '/api/v1/tenant/{}/bind_saas/info/'.format(self.tenant.id)
resp = self.client.get(url, content_type='application/json')
self.assertEqual(resp.status_code, 200, resp.content.decode())
Loading

0 comments on commit 7c6ab9c

Please sign in to comment.