Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
思寒
hogwarts-testing-platform-bjzm3
Commits
17ce20e8
Commit
17ce20e8
authored
6 months ago
by
seveniruby
Browse files
Options
Download
Email Patches
Plain Diff
通用模型的增删改查
parent
a3b77112
No related merge requests found
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
src/hogwarts_testing_platform/model/bug.py
+10
-0
src/hogwarts_testing_platform/model/bug.py
src/hogwarts_testing_platform/model/report.py
+10
-0
src/hogwarts_testing_platform/model/report.py
src/hogwarts_testing_platform/model/testcase.py
+3
-1
src/hogwarts_testing_platform/model/testcase.py
src/hogwarts_testing_platform/router/item_router.py
+48
-0
src/hogwarts_testing_platform/router/item_router.py
src/hogwarts_testing_platform/router/testcase_router.py
+0
-27
src/hogwarts_testing_platform/router/testcase_router.py
src/hogwarts_testing_platform/site/app.py
+0
-3
src/hogwarts_testing_platform/site/app.py
src/hogwarts_testing_platform/site/main.py
+3
-9
src/hogwarts_testing_platform/site/main.py
src/hogwarts_testing_platform/site/server.py
+36
-0
src/hogwarts_testing_platform/site/server.py
tests/it/conftest.py
+3
-3
tests/it/conftest.py
tests/it/test_testcase.py
+35
-2
tests/it/test_testcase.py
tests/ut/test_testcase.py
+1
-1
tests/ut/test_testcase.py
with
149 additions
and
46 deletions
+149
-46
src/hogwarts_testing_platform/model/bug.py
0 → 100644
+
10
-
0
View file @
17ce20e8
from
uuid
import
uuid4
from
pydantic
import
BaseModel
class
Bug
(
BaseModel
):
id
:
int
=
uuid4
().
int
name
:
str
=
None
description
:
str
=
None
weight
:
int
=
5
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/model/report.py
0 → 100644
+
10
-
0
View file @
17ce20e8
from
uuid
import
uuid4
from
pydantic
import
BaseModel
class
Report
(
BaseModel
):
id
:
int
=
uuid4
().
int
name
:
str
=
None
description
:
str
=
None
path
:
str
=
None
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/model/testcase.py
+
3
-
1
View file @
17ce20e8
from
dataclasses
import
dataclass
from
typing
import
Optional
from
uuid
import
uuid4
from
pydantic
import
BaseModel
,
Field
...
...
@@ -10,6 +11,7 @@ class Step(BaseModel):
class
TestCase
(
BaseModel
):
id
:
int
=
uuid4
().
int
name
:
str
=
None
description
:
str
=
None
steps
:
list
[
Step
]
=
None
steps
:
list
[
Step
]
=
Field
(
default
=
[])
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/router/item_router.py
0 → 100644
+
48
-
0
View file @
17ce20e8
from
dataclasses
import
asdict
from
flask
import
request
from
flask.sansio.blueprints
import
Blueprint
from
flask.views
import
MethodView
from
pydantic
import
BaseModel
from
hogwarts_testing_platform.model.testcase
import
TestCase
,
Step
fake_db
:
dict
[
int
,
BaseModel
]
=
{
1
:
TestCase
(
name
=
'demo'
)
}
class
ItemAPI
(
MethodView
):
def
__init__
(
self
,
model
:
BaseModel
):
# 任意BaseModel的模型
self
.
model
=
model
def
_get_item
(
self
,
id
):
return
fake_db
[
id
]
def
get
(
self
,
id
=
None
):
# 获取case
if
id
is
not
None
:
# 根据id获取case
print
(
id
)
case
=
fake_db
.
get
(
id
)
return
case
.
model_dump
()
else
:
# 列出所有case
return
[{
k
:
v
.
model_dump
()}
for
k
,
v
in
fake_db
.
items
()]
def
post
(
self
,
id
=
None
):
# 新增case
case
=
self
.
model
.
model_validate
(
request
.
json
)
if
id
is
None
:
# CREATE 新增case
fake_db
[
case
.
id
]
=
case
return
case
.
model_dump
()
else
:
# 根据id更新case Update
fake_db
[
id
]
=
case
def
delete
(
self
,
id
):
fake_db
.
pop
(
id
)
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/router/testcase_router.py
deleted
100644 → 0
+
0
-
27
View file @
a3b77112
from
dataclasses
import
asdict
from
flask.sansio.blueprints
import
Blueprint
from
flask.views
import
MethodView
from
hogwarts_testing_platform.model.testcase
import
TestCase
,
Step
fake_db
=
{
'1'
:
TestCase
(
name
=
'case1'
)
}
class
TestCaseAPI
(
MethodView
):
def
get
(
self
,
id
):
print
(
id
)
case
=
fake_db
.
get
(
str
(
id
))
return
case
.
model_dump
()
def
post
(
self
):
case
=
TestCase
()
case
.
name
=
'demo'
case
.
description
=
'description xxxx'
case
.
steps
=
[
Step
(
name
=
'step1'
,
description
=
'step1'
,
expect
=
'expect1'
),
Step
(
name
=
'step2'
,
description
=
'step2'
,
expect
=
'expect2'
)
]
return
case
.
model_dump
()
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/site/app.py
deleted
100644 → 0
+
0
-
3
View file @
a3b77112
from
flask
import
Flask
app
=
Flask
(
__name__
)
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/site/main.py
+
3
-
9
View file @
17ce20e8
from
hogwarts_testing_platform.model.testcase
import
TestCase
from
hogwarts_testing_platform.router.testcase_router
import
TestCaseAPI
from
hogwarts_testing_platform.site.app
import
app
def
init_app
():
app
.
add_url_rule
(
rule
=
'/testcase/<int:id>'
,
view_func
=
TestCaseAPI
.
as_view
(
'testcase'
))
from
hogwarts_testing_platform.site.server
import
Server
def
main
(
port
=
5000
):
init_app
()
app
.
run
(
debug
=
True
,
port
=
port
)
server
=
Server
()
server
.
run
(
port
=
port
)
if
__name__
==
'__main__'
:
...
...
This diff is collapsed.
Click to expand it.
src/hogwarts_testing_platform/site/server.py
0 → 100644
+
36
-
0
View file @
17ce20e8
from
__future__
import
annotations
from
flask
import
Flask
from
hogwarts_testing_platform.model.bug
import
Bug
from
hogwarts_testing_platform.model.report
import
Report
from
hogwarts_testing_platform.model.testcase
import
TestCase
from
hogwarts_testing_platform.router.item_router
import
ItemAPI
class
Server
:
def
__init__
(
self
):
self
.
app
:
Flask
|
None
=
None
def
get_app
(
self
):
if
self
.
app
is
None
:
self
.
app
=
Flask
(
__name__
)
self
.
app
.
debug
=
True
self
.
include_routes
()
return
self
.
app
def
include_routes
(
self
):
for
path
,
model
in
{
'/bug'
:
Bug
,
'/testcase'
:
TestCase
,
'/report'
:
Report
,
}.
items
():
name
=
path
[
1
:]
bug_view_func
=
ItemAPI
.
as_view
(
name
,
model
)
self
.
get_app
().
add_url_rule
(
rule
=
f
'
{
path
}
/<int:id>'
,
view_func
=
bug_view_func
,
methods
=
[
'GET'
])
self
.
get_app
().
add_url_rule
(
rule
=
f
'
{
path
}
/'
,
view_func
=
bug_view_func
,
methods
=
[
'GET'
])
self
.
get_app
().
add_url_rule
(
rule
=
f
'
{
path
}
'
,
view_func
=
bug_view_func
,
methods
=
[
'POST'
])
def
run
(
self
,
port
=
None
):
self
.
get_app
().
run
(
port
=
port
,
debug
=
True
)
This diff is collapsed.
Click to expand it.
tests/it/conftest.py
+
3
-
3
View file @
17ce20e8
from
_pytest.fixtures
import
fixture
from
hogwarts_testing_platform.site.app
import
app
from
hogwarts_testing_platform.site.main
import
main
,
init_app
from
hogwarts_testing_platform.site.server
import
Server
@
fixture
(
scope
=
"session"
)
def
client
():
init_app
()
server
=
Server
()
app
=
server
.
get_app
()
return
app
.
test_client
()
This diff is collapsed.
Click to expand it.
tests/it/test_testcase.py
+
35
-
2
View file @
17ce20e8
from
hogwarts_testing_platform.model.testcase
import
TestCase
def
test_post
(
client
):
data
=
client
.
post
(
'/testcase'
,
data
=
dict
()).
json
response
=
client
.
post
(
'/testcase'
,
json
=
{
'name'
:
'test'
,
'description'
:
'test'
})
print
(
response
)
print
(
response
.
data
)
data
=
response
.
json
assert
data
[
'name'
]
==
'demo'
print
(
data
)
assert
data
[
'name'
]
==
'test'
testcase_id
=
data
[
'id'
]
case2
=
TestCase
.
model_validate
(
client
.
get
(
f
'/testcase/
{
testcase_id
}
'
).
json
)
assert
case2
.
name
==
'test'
assert
case2
.
id
==
testcase_id
data
=
client
.
get
(
'/testcase/'
).
json
case_list
=
[]
if
isinstance
(
data
,
list
):
for
item
in
data
:
case
=
TestCase
.
model_validate
(
item
)
case_list
.
append
(
case
)
print
(
data
)
assert
len
(
case_list
)
>=
1
def
test_get
(
client
):
data
=
client
.
get
(
'/testcase/1'
).
json
assert
data
[
'name'
]
==
'demo'
def
test_get_all
(
client
):
data
=
client
.
get
(
'/testcase/'
).
json
case_list
=
[]
if
isinstance
(
data
,
list
):
for
item
in
data
:
case
=
TestCase
.
model_validate
(
item
)
case_list
.
append
(
case
)
print
(
data
)
assert
len
(
case_list
)
>=
1
This diff is collapsed.
Click to expand it.
tests/ut/test_testcase.py
+
1
-
1
View file @
17ce20e8
from
hogwarts_testing_platform.router.te
stcase
_router
import
testcase_get
from
hogwarts_testing_platform.router.
i
te
m
_router
import
testcase_get
def
test_case
():
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets