Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
indicators-parser-saas
backend
Commits
463b50e8
Verified
Commit
463b50e8
authored
2 years ago
by
Власов Иван Юрьевич
Browse files
Options
Download
Patches
Plain Diff
Added /getReports endpoint and tests
parent
a8106c53
master
No related merge requests found
Pipeline
#98837
passed with stage
in 1 minute and 1 second
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
endpoints/__init__.py
+1
-0
endpoints/__init__.py
endpoints/parser.py
+11
-0
endpoints/parser.py
endpoints/routes.py
+2
-1
endpoints/routes.py
tests/test_indicator.py
+12
-0
tests/test_indicator.py
with
26 additions
and
1 deletion
+26
-1
endpoints/__init__.py
+
1
−
0
View file @
463b50e8
...
...
@@ -4,3 +4,4 @@ from .user import get_me, create_bot_token, get_bot_tokens, delete_bot_token
from
.parser
import
load_report
from
.indicators
import
get_indicators_from_group
,
get_indicator_groups
from
.watcher
import
create_watcher
from
.parser
import
get_reports
This diff is collapsed.
Click to expand it.
endpoints/parser.py
+
11
−
0
View file @
463b50e8
...
...
@@ -9,6 +9,7 @@ from starlette.requests import Request
from
integrations.s3
import
save_report_to_s3
from
models
import
Report
,
IndicatorGroup
from
models.indicator
import
IndicatorGroupPD
from
models.report
import
ReportPD
from
parsers.pdf_parser
import
process_pdf
from
parsers.text_parser
import
CollectedData
from
responses.errors
import
ReportNotPresented
...
...
@@ -39,3 +40,13 @@ async def load_report(request: Request):
background
.
add_task
(
save_report_to_s3
,
temp
.
name
,
report_id
)
background
.
add_task
(
os
.
remove
,
temp
.
name
)
return
OkResponse
({
"report_id"
:
report_id
,
"indicator_group"
:
group_pd
},
background
=
background
)
async
def
get_reports
(
request
:
Request
):
""" Returns user's reports """
reports
=
await
Report
.
filter
(
owner
=
request
.
state
.
user
).
all
()
as_pd
=
[]
for
report
in
reports
:
report
.
owner
=
request
.
state
.
user
as_pd
.
append
(
ReportPD
.
from_orm
(
report
))
return
OkResponse
(
as_pd
)
This diff is collapsed.
Click to expand it.
endpoints/routes.py
+
2
−
1
View file @
463b50e8
...
...
@@ -18,7 +18,8 @@ api_routes = [
Route
(
"/getBotTokens"
,
get_bot_tokens
,
methods
=
[
"GET"
]),
Route
(
"/deleteBotToken"
,
delete_bot_token
,
methods
=
[
"GET"
]),
Route
(
"/createWatcher"
,
create_watcher
,
methods
=
[
"POST"
]),
Route
(
"/getIndicatorGroups"
,
get_indicator_groups
,
methods
=
[
"GET"
])
Route
(
"/getIndicatorGroups"
,
get_indicator_groups
,
methods
=
[
"GET"
]),
Route
(
"/getReports"
,
get_reports
,
methods
=
[
"GET"
])
]
admin_routes
=
[]
...
...
This diff is collapsed.
Click to expand it.
tests/test_indicator.py
+
12
−
0
View file @
463b50e8
...
...
@@ -95,3 +95,15 @@ async def test_indicator_groups_endpoint(sti_auth, user):
assert
resp
.
status_code
==
200
assert
len
(
resp
.
json
()[
"data"
])
==
len
(
groups
)
def
test_reports_endpoint
(
sti_auth
,
user
,
mts_report
):
resp
=
sti_auth
.
post
(
"/api/loadReport"
,
files
=
{
"file"
:
open
(
mts_report
,
"rb"
)})
assert
resp
.
status_code
==
200
report_id
=
resp
.
json
()[
"data"
][
"report_id"
]
resp_reports
=
sti_auth
.
get
(
"/api/getReports"
)
assert
1
==
len
(
resp_reports
.
json
()[
"data"
])
print
(
resp_reports
.
json
())
assert
resp_reports
.
json
()[
"data"
][
0
][
"id"
]
==
report_id
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!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets