Browse Source
- Add CURD in project
- Add CURD in tenant
- Add CURD in user
- Add test in user
Co-authored-by: Jiajie Zhong <zhongjiajie955@gmail.com>
(cherry picked from commit cc492c3e13
)
3.1.2-release
Lyle Shaw
2 years ago
committed by
Jay Chung
12 changed files with 484 additions and 14 deletions
@ -0,0 +1,78 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one |
||||
# or more contributor license agreements. See the NOTICE file |
||||
# distributed with this work for additional information |
||||
# regarding copyright ownership. The ASF licenses this file |
||||
# to you under the Apache License, Version 2.0 (the |
||||
# "License"); you may not use this file except in compliance |
||||
# with the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, |
||||
# software distributed under the License is distributed on an |
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
# KIND, either express or implied. See the License for the |
||||
# specific language governing permissions and limitations |
||||
# under the License. |
||||
|
||||
"""Test pydolphinscheduler project.""" |
||||
import pytest |
||||
|
||||
from pydolphinscheduler.models import Project, User |
||||
|
||||
|
||||
def get_user( |
||||
name="test-name", |
||||
password="test-password", |
||||
email="test-email@abc.com", |
||||
phone="17366637777", |
||||
tenant="test-tenant", |
||||
queue="test-queue", |
||||
status=1, |
||||
): |
||||
"""Get a test user.""" |
||||
user = User(name, password, email, phone, tenant, queue, status) |
||||
user.create_if_not_exists() |
||||
return user |
||||
|
||||
|
||||
def get_project(name="test-name-1", description="test-description", code=1): |
||||
"""Get a test project.""" |
||||
project = Project(name, description, code=code) |
||||
user = get_user() |
||||
project.create_if_not_exists(user=user.name) |
||||
return project |
||||
|
||||
|
||||
def test_create_and_get_project(): |
||||
"""Test create and get project from java gateway.""" |
||||
project = get_project() |
||||
project_ = Project.get_project_by_name(user="test-name", name=project.name) |
||||
assert project_.name == project.name |
||||
assert project_.description == project.description |
||||
|
||||
|
||||
def test_update_project(): |
||||
"""Test update project from java gateway.""" |
||||
project = get_project() |
||||
project = project.get_project_by_name(user="test-name", name=project.name) |
||||
project.update( |
||||
user="test-name", |
||||
project_code=project.code, |
||||
project_name="test-name-updated", |
||||
description="test-description-updated", |
||||
) |
||||
project_ = Project.get_project_by_name(user="test-name", name="test-name-updated") |
||||
assert project_.description == "test-description-updated" |
||||
|
||||
|
||||
def test_delete_project(): |
||||
"""Test delete project from java gateway.""" |
||||
project = get_project() |
||||
project.get_project_by_name(user="test-name", name=project.name) |
||||
project.delete(user="test-name") |
||||
|
||||
with pytest.raises(AttributeError) as excinfo: |
||||
_ = project.name |
||||
|
||||
assert excinfo.type == AttributeError |
@ -0,0 +1,86 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one |
||||
# or more contributor license agreements. See the NOTICE file |
||||
# distributed with this work for additional information |
||||
# regarding copyright ownership. The ASF licenses this file |
||||
# to you under the Apache License, Version 2.0 (the |
||||
# "License"); you may not use this file except in compliance |
||||
# with the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, |
||||
# software distributed under the License is distributed on an |
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
# KIND, either express or implied. See the License for the |
||||
# specific language governing permissions and limitations |
||||
# under the License. |
||||
|
||||
"""Test pydolphinscheduler tenant.""" |
||||
import pytest |
||||
|
||||
from pydolphinscheduler.models import Tenant, User |
||||
|
||||
|
||||
def get_user( |
||||
name="test-name", |
||||
password="test-password", |
||||
email="test-email@abc.com", |
||||
phone="17366637777", |
||||
tenant="test-tenant", |
||||
queue="test-queue", |
||||
status=1, |
||||
): |
||||
"""Get a test user.""" |
||||
user = User(name, password, email, phone, tenant, queue, status) |
||||
user.create_if_not_exists() |
||||
return user |
||||
|
||||
|
||||
def get_tenant( |
||||
name="test-name-1", |
||||
queue="test-queue-1", |
||||
description="test-description", |
||||
tenant_code="test-tenant-code", |
||||
user_name=None, |
||||
): |
||||
"""Get a test tenant.""" |
||||
tenant = Tenant(name, queue, description, code=tenant_code, user_name=user_name) |
||||
tenant.create_if_not_exists(name) |
||||
return tenant |
||||
|
||||
|
||||
def test_create_tenant(): |
||||
"""Test create tenant from java gateway.""" |
||||
tenant = get_tenant() |
||||
assert tenant.tenant_id is not None |
||||
|
||||
|
||||
def test_get_tenant(): |
||||
"""Test get tenant from java gateway.""" |
||||
tenant = get_tenant() |
||||
tenant_ = Tenant.get_tenant(tenant.code) |
||||
assert tenant_.tenant_id == tenant.tenant_id |
||||
|
||||
|
||||
def test_update_tenant(): |
||||
"""Test update tenant from java gateway.""" |
||||
tenant = get_tenant(user_name="admin") |
||||
tenant.update( |
||||
user="admin", |
||||
code="test-code-updated", |
||||
queue_id=1, |
||||
description="test-description-updated", |
||||
) |
||||
tenant_ = Tenant.get_tenant(code=tenant.code) |
||||
assert tenant_.code == "test-code-updated" |
||||
assert tenant_.queue == 1 |
||||
|
||||
|
||||
def test_delete_tenant(): |
||||
"""Test delete tenant from java gateway.""" |
||||
tenant = get_tenant(user_name="admin") |
||||
tenant.delete() |
||||
with pytest.raises(AttributeError) as excinfo: |
||||
_ = tenant.tenant_id |
||||
|
||||
assert excinfo.type == AttributeError |
@ -0,0 +1,107 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one |
||||
# or more contributor license agreements. See the NOTICE file |
||||
# distributed with this work for additional information |
||||
# regarding copyright ownership. The ASF licenses this file |
||||
# to you under the Apache License, Version 2.0 (the |
||||
# "License"); you may not use this file except in compliance |
||||
# with the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, |
||||
# software distributed under the License is distributed on an |
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||
# KIND, either express or implied. See the License for the |
||||
# specific language governing permissions and limitations |
||||
# under the License. |
||||
|
||||
"""Test pydolphinscheduler user.""" |
||||
|
||||
import hashlib |
||||
|
||||
import pytest |
||||
|
||||
from pydolphinscheduler.models import User |
||||
|
||||
|
||||
def md5(str): |
||||
"""MD5 a string.""" |
||||
hl = hashlib.md5() |
||||
hl.update(str.encode(encoding="utf-8")) |
||||
return hl.hexdigest() |
||||
|
||||
|
||||
def get_user( |
||||
name="test-name", |
||||
password="test-password", |
||||
email="test-email@abc.com", |
||||
phone="17366637777", |
||||
tenant="test-tenant", |
||||
queue="test-queue", |
||||
status=1, |
||||
): |
||||
"""Get a test user.""" |
||||
user = User( |
||||
name=name, |
||||
password=password, |
||||
email=email, |
||||
phone=phone, |
||||
tenant=tenant, |
||||
queue=queue, |
||||
status=status, |
||||
) |
||||
user.create_if_not_exists() |
||||
return user |
||||
|
||||
|
||||
def test_create_user(): |
||||
"""Test weather client could connect java gate way or not.""" |
||||
user = User( |
||||
name="test-name", |
||||
password="test-password", |
||||
email="test-email@abc.com", |
||||
phone="17366637777", |
||||
tenant="test-tenant", |
||||
queue="test-queue", |
||||
status=1, |
||||
) |
||||
user.create_if_not_exists() |
||||
assert user.user_id is not None |
||||
|
||||
|
||||
def test_get_user(): |
||||
"""Test get user from java gateway.""" |
||||
user = get_user() |
||||
user_ = User.get_user(user.user_id) |
||||
assert user_.password == md5(user.password) |
||||
assert user_.email == user.email |
||||
assert user_.phone == user.phone |
||||
assert user_.status == user.status |
||||
|
||||
|
||||
def test_update_user(): |
||||
"""Test update user from java gateway.""" |
||||
user = get_user() |
||||
user.update( |
||||
password="test-password-", |
||||
email="test-email-updated@abc.com", |
||||
phone="17366637766", |
||||
tenant="test-tenant-updated", |
||||
queue="test-queue-updated", |
||||
status=2, |
||||
) |
||||
user_ = User.get_user(user.user_id) |
||||
assert user_.password == md5("test-password-") |
||||
assert user_.email == "test-email-updated@abc.com" |
||||
assert user_.phone == "17366637766" |
||||
assert user_.status == 2 |
||||
|
||||
|
||||
def test_delete_user(): |
||||
"""Test delete user from java gateway.""" |
||||
user = get_user() |
||||
user.delete() |
||||
with pytest.raises(AttributeError) as excinfo: |
||||
_ = user.user_id |
||||
|
||||
assert excinfo.type == AttributeError |
Loading…
Reference in new issue