Verified Commit 7b96cc34 authored by Власов Иван Юрьевич's avatar Власов Иван Юрьевич :rabbit2:
Browse files

Created tests for new methods

parent 4defc556
No related merge requests found
Pipeline #98614 passed with stage
in 55 seconds
Showing with 63 additions and 22 deletions
+63 -22
import asyncio
import os
import pytest
from requests import get
from models import IndicatorGroup
from parsers.text_parser import CollectedData
from tests.fixtures.tortoise import user
@pytest.fixture
def mts_report():
pdf_url = "https://storage.yandexcloud.net/ivanprogramming/Network_Report.pdf"
pdf_path = "Network_Report.pdf"
with open(pdf_path, "wb") as f:
f.write(get(pdf_url).content)
yield pdf_path
try:
os.remove(pdf_path)
except FileNotFoundError:
pass
@pytest.fixture
def group(user):
async def _create_group():
collected_data = CollectedData(
hashes={"5d41402abc4b2a76b9719d911017c592"},
ips={"101.100.100.100"},
urls={"https://www.google.com/"}
)
group = await IndicatorGroup.from_reports_collected_data(collected_data, user)
return group
loop = asyncio.get_event_loop()
return loop.run_until_complete(_create_group())
......@@ -3,9 +3,11 @@ from requests import get
from models.indicator import IndicatorGroup, Indicator, IndicatorType
from parsers.text_parser import CollectedData
from responses.errors import ReportNotPresented
from responses.errors import ReportNotPresented, IndicatorGroupDoesNotExist
from tests.fixtures.tortoise import user
from tests.fixtures.client import sti_auth
from tests.fixtures.indicators import mts_report
from tests.fixtures.indicators import group
@pytest.mark.asyncio
......@@ -30,13 +32,8 @@ async def test_indicator_group_from_reports_collected_data(user):
@pytest.mark.asyncio
async def test_load_pdf_endpoint(user, sti_auth):
pdf_url = "https://storage.yandexcloud.net/ivanprogramming/Network_Report.pdf"
pdf_path = "Network_Report.pdf"
with open(pdf_path, "wb") as f:
f.write(get(pdf_url).content)
resp = sti_auth.post("/api/loadReport", files={"file": open(pdf_path, "rb")})
async def test_load_pdf_endpoint(user, sti_auth, mts_report):
resp = sti_auth.post("/api/loadReport", files={"file": open(mts_report, "rb")})
assert resp.status_code == 200
data = resp.json()["data"]
......@@ -53,3 +50,19 @@ def test_load_pdf_endpoint_no_file(sti_auth):
assert resp.status_code == 422
assert not resp.json()["ok"]
assert resp.json()["data"]["error_code"] == ReportNotPresented.code
def test_indicator_endpoint_not_found(sti_auth, group):
resp = sti_auth.get("/api/getIndicatorsFromGroup?group_id=not-exists")
assert resp.status_code == 404
assert not resp.json()["ok"]
assert resp.json()["data"]["error_code"] == IndicatorGroupDoesNotExist.code
def test_indicator_endpoint(sti_auth, group):
resp = sti_auth.get(f"/api/getIndicatorsFromGroup?group_id={group.id}")
assert resp.status_code == 200
assert len(resp.json()["data"]["indicators"]) == 3
......@@ -4,29 +4,21 @@ from requests import get
from integrations.s3 import save_report_to_s3, remove_report_from_s3, generate_report_url
from settings import S3_BASE_URL
from tests.fixtures.indicators import mts_report
def test_s3_file_load_public():
pdf_url = "https://storage.yandexcloud.net/ivanprogramming/Network_Report.pdf"
pdf_path = "Network_Report.pdf"
with open(pdf_path, "wb") as f:
f.write(get(pdf_url).content)
save_report_to_s3(pdf_path, "test", is_public=True)
def test_s3_file_load_public(mts_report):
save_report_to_s3(mts_report, "test", is_public=True)
url = S3_BASE_URL + "test.pdf"
response = get(url)
assert response.status_code == 200
remove_report_from_s3("test")
os.remove(pdf_path)
def test_s3_file_load_private():
pdf_url = "https://storage.yandexcloud.net/ivanprogramming/Network_Report.pdf"
pdf_path = "Network_Report.pdf"
with open(pdf_path, "wb") as f:
f.write(get(pdf_url).content)
save_report_to_s3(pdf_path, "test-private", is_public=False)
def test_s3_file_load_private(mts_report):
save_report_to_s3(mts_report, "test-private", is_public=False)
url = S3_BASE_URL + "test.pdf"
response = get(url)
......@@ -36,4 +28,3 @@ def test_s3_file_load_private():
assert response.status_code == 200
remove_report_from_s3("test-private")
os.remove(pdf_path)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment