forked from hhyo/Archery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 重构 audit 相关代码, 改为面向对象实现 * 使用 pytst 运行测试 * fix tests * fix coverage generation * more coverage * 修复 audit_groups 的类型错误 * 不抛错给用户, 改为输出日志
- Loading branch information
Showing
19 changed files
with
1,500 additions
and
1,438 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import datetime | ||
|
||
import pytest | ||
|
||
from common.utils.const import WorkflowStatus | ||
from sql.models import ( | ||
Instance, | ||
ResourceGroup, | ||
SqlWorkflow, | ||
SqlWorkflowContent, | ||
QueryPrivilegesApply, | ||
ArchiveConfig, | ||
) | ||
from common.config import SysConfig | ||
|
||
|
||
@pytest.fixture | ||
def normal_user(django_user_model): | ||
user = django_user_model.objects.create( | ||
username="test_user", display="中文显示", is_active=True | ||
) | ||
yield user | ||
user.delete() | ||
|
||
|
||
@pytest.fixture | ||
def super_user(django_user_model): | ||
user = django_user_model.objects.create( | ||
username="super_user", display="超级用户", is_active=True, is_superuser=True | ||
) | ||
yield user | ||
user.delete() | ||
|
||
|
||
@pytest.fixture | ||
def db_instance(db): | ||
ins = Instance.objects.create( | ||
instance_name="some_ins", | ||
type="slave", | ||
db_type="mysql", | ||
host="some_host", | ||
port=3306, | ||
user="ins_user", | ||
password="some_str", | ||
) | ||
yield ins | ||
ins.delete() | ||
|
||
|
||
@pytest.fixture | ||
def resource_group(db) -> ResourceGroup: | ||
res_group = ResourceGroup.objects.create(group_id=1, group_name="group_name") | ||
yield res_group | ||
res_group.delete() | ||
|
||
|
||
@pytest.fixture | ||
def sql_workflow(db_instance): | ||
wf = SqlWorkflow.objects.create( | ||
workflow_name="some_name", | ||
group_id=1, | ||
group_name="g1", | ||
engineer_display="", | ||
audit_auth_groups="some_audit_group", | ||
create_time=datetime.datetime.now(), | ||
status="workflow_timingtask", | ||
is_backup=True, | ||
instance=db_instance, | ||
db_name="some_db", | ||
syntax_type=1, | ||
) | ||
wf_content = SqlWorkflowContent.objects.create( | ||
workflow=wf, sql_content="some_sql", execute_result="" | ||
) | ||
yield wf, wf_content | ||
wf.delete() | ||
wf_content.delete() | ||
|
||
|
||
@pytest.fixture | ||
def sql_query_apply(db_instance): | ||
tomorrow = datetime.datetime.today() + datetime.timedelta(days=1) | ||
query_apply_1 = QueryPrivilegesApply.objects.create( | ||
group_id=1, | ||
group_name="some_name", | ||
title="some_title1", | ||
user_name="some_user", | ||
instance=db_instance, | ||
db_list="some_db,some_db2", | ||
limit_num=100, | ||
valid_date=tomorrow, | ||
priv_type=1, | ||
status=0, | ||
audit_auth_groups="some_audit_group", | ||
) | ||
yield query_apply_1 | ||
query_apply_1.delete() | ||
|
||
|
||
@pytest.fixture | ||
def archive_apply(db_instance, resource_group): | ||
archive_apply_1 = ArchiveConfig.objects.create( | ||
title="title", | ||
resource_group=resource_group, | ||
audit_auth_groups="", | ||
src_instance=db_instance, | ||
src_db_name="src_db_name", | ||
src_table_name="src_table_name", | ||
dest_instance=db_instance, | ||
dest_db_name="src_db_name", | ||
dest_table_name="src_table_name", | ||
condition="1=1", | ||
mode="file", | ||
no_delete=True, | ||
sleep=1, | ||
status=WorkflowStatus.WAITING, | ||
state=False, | ||
user_name="some_user", | ||
user_display="display", | ||
) | ||
yield archive_apply_1 | ||
archive_apply_1.delete() | ||
|
||
|
||
@pytest.fixture | ||
def setup_sys_config(db): | ||
sys_config = SysConfig() | ||
yield sys_config | ||
sys_config.purge() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pytest | ||
pytest-django | ||
pytest-mock | ||
pytest-cov | ||
codecov | ||
flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[tool.pytest.ini_options] | ||
DJANGO_SETTINGS_MODULE = "archery.settings" | ||
python_files = "tests.py test_*.py *_tests.py" | ||
|
||
[tool.coverage.run] | ||
source = [ | ||
"." | ||
] | ||
omit = [ | ||
# omit anything in a .local directory anywhere | ||
"src*", | ||
# omit everything in /usr | ||
"downloads*", | ||
# omit this single file | ||
"sql/migrations/*", | ||
"venv*" | ||
] | ||
|
||
[tool.coverage.report] | ||
omit = [ | ||
# omit anything in a .local directory anywhere | ||
"src*", | ||
# omit everything in /usr | ||
"downloads*", | ||
# omit this single file | ||
"sql/migrations/*", | ||
"venv*" | ||
] |
Oops, something went wrong.