Skip to content

Commit

Permalink
fix flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sadnub committed Sep 15, 2023
1 parent 441775c commit 804f486
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.apps import apps
from django.conf import settings as djangosettings
from django.core.management.base import BaseCommand
from typing import Dict, Tuple, List, Any, Type, TYPE_CHECKING
from typing import Dict, Tuple, List, Any, TYPE_CHECKING
from ...constants import REPORTING_MODELS

if TYPE_CHECKING:
Expand Down
8 changes: 4 additions & 4 deletions api/tacticalrmm/ee/reporting/tests/test_data_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@pytest.mark.django_db
class TestMakeVariablesInline:
def test_make_dataqueries_inline_valid_reference(self):
data_query = baker.make(
baker.make(
"reporting.ReportDataQuery", name="test_query", json_query={"test": "query"}
)
variables = yaml.dump({"data_sources": {"source1": "test_query"}})
Expand Down Expand Up @@ -57,7 +57,7 @@ class TestResolvingModels:
def test_all_reporting_models_valid(self):
for model_name, app_name in REPORTING_MODELS:
try:
model = apps.get_model(app_name, model_name)
apps.get_model(app_name, model_name)
except LookupError:
pytest.fail(f"Model: {model_name} does not exist in app: {app_name}")

Expand Down Expand Up @@ -425,7 +425,7 @@ class TestAddingCustomFields:
def test_add_custom_fields_with_list_of_dicts(self, model_name, custom_field_model):
custom_field = baker.make("core.CustomField", name="field1", model=model_name)
default_value = "Default Value"
custom_field2 = baker.make(
baker.make(
"core.CustomField",
name="field2",
model=model_name,
Expand Down Expand Up @@ -491,7 +491,7 @@ def test_add_custom_fields_to_dictionary(self, model_name, custom_field_model):
)
def test_add_custom_fields_with_default_value(self, model_name):
default_value = "default_value"
custom_field = baker.make(
baker.make(
"core.CustomField",
name="field1",
model=model_name,
Expand Down
4 changes: 2 additions & 2 deletions api/tacticalrmm/ee/reporting/tests/test_dataquery_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from model_bakery import baker
from rest_framework.test import APIClient
from rest_framework import status
from unittest.mock import patch, mock_open, MagicMock
from unittest.mock import patch, mock_open
from ..models import ReportDataQuery


Expand Down Expand Up @@ -180,5 +180,5 @@ def test_get_query_schema_file_missing(self, settings, authenticated_client):
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_unauthenticated_query_schema_view(self, unauthenticated_client):
response = unauthenticated_client.delete(f"/reporting/queryschema/")
response = unauthenticated_client.delete("/reporting/queryschema/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,5 @@ def test_import_with_assets_with_conflicting_paths(
assert asset.file.name != valid_assets_data[0]["name"]

def test_unauthenticated_import_report_template_view(self, unauthenticated_client):
response = unauthenticated_client.post(f"/reporting/templates/import/")
response = unauthenticated_client.post("/reporting/templates/import/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED
14 changes: 7 additions & 7 deletions api/tacticalrmm/ee/reporting/tests/test_report_asset_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def test_only_folders(self, mock_os_walk, authenticated_client):
[(".", ["subdir"], ["file1.txt"]), ("./subdir", [], ["subdirfile.txt"])]
)

asset1 = baker.make("reporting.ReportAsset", file="file1.txt")
asset2 = baker.make("reporting.ReportAsset", file="subdir/subdirfile.txt")
baker.make("reporting.ReportAsset", file="file1.txt")
baker.make("reporting.ReportAsset", file="subdir/subdirfile.txt")

response = authenticated_client.get("/reporting/assets/all/?onlyFolders=true")

Expand All @@ -186,9 +186,9 @@ def test_rename_file(self, authenticated_client):
return_value="path/to/newname.txt",
) as mock_rename, patch(
"ee.reporting.views.report_assets_fs.isfile", return_value=True
) as mock_isfile, patch(
), patch(
"ee.reporting.views.report_assets_fs.exists", return_value=True
) as mock_exists:
):
asset = baker.make("reporting.ReportAsset", file="path/to/file.txt")

response = authenticated_client.put(
Expand All @@ -211,9 +211,9 @@ def test_rename_folder(self, authenticated_client):
return_value="path/to/newfolder",
) as mock_rename, patch(
"ee.reporting.views.report_assets_fs.isfile", return_value=False
) as mock_isfile, patch(
), patch(
"ee.reporting.views.report_assets_fs.exists", return_value=True
) as mock_exists:
):
response = authenticated_client.put(
"/reporting/assets/rename/",
data={"path": "path/to/folder", "newName": "newfolder"},
Expand All @@ -229,7 +229,7 @@ def test_rename_non_existent_file(self, authenticated_client):
side_effect=OSError("File not found"),
) as mock_rename, patch(
"ee.reporting.views.report_assets_fs.exists", return_value=True
) as mock_exists:
):
response = authenticated_client.put(
"/reporting/assets/rename/",
data={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def test_delete_report_template(self, authenticated_client, report_template):

# test unauthorized access
def test_unauthorized_get_report_templates_view(self, unauthenticated_client):
url = f"/reporting/templates/"
url = "/reporting/templates/"
response = unauthenticated_client.get(url)

assert response.status_code == status.HTTP_401_UNAUTHORIZED

def test_unauthorized_add_report_template_view(self, unauthenticated_client):
url = f"/reporting/templates/"
url = "/reporting/templates/"
response = unauthenticated_client.post(url)

assert response.status_code == status.HTTP_401_UNAUTHORIZED
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_empty_variables(self, authenticated_client):
)

assert response.status_code == 200
assert response.data == None
assert response.data is None

def test_invalid_input(self, authenticated_client):
data = {"invalidKey": {}}
Expand Down
20 changes: 0 additions & 20 deletions api/tacticalrmm/ee/reporting/tests/test_template_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,6 @@ def test_process_data_sources_with_dict_data_sources(self):
# Assert that the "source2" data remains unchanged
assert result["data_sources"]["source2"] == "some_string_value"

def test_process_data_sources_with_non_dict_data_sources(self):
variables = {
"data_sources": {
"source1": {"model": "agent", "other_field": "value"},
"source2": "some_string_value",
}
}

mock_queryset = 5

# Mock build_queryset to return the mock_queryset
with patch("ee.reporting.utils.build_queryset", return_value=mock_queryset):
result = process_data_sources(variables=variables)

# Assert that the data_sources for "source1" is replaced with mock_queryset
assert result["data_sources"]["source1"] == mock_queryset

# Assert that the "source2" data remains unchanged
assert result["data_sources"]["source2"] == "some_string_value"


class TestProcessChartVariables:
def test_process_chart_no_replace_data_frame(self):
Expand Down
4 changes: 1 addition & 3 deletions api/tacticalrmm/ee/reporting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tacticalrmm.utils import get_db_value
from weasyprint import CSS, HTML
from weasyprint.text.fonts import FontConfiguration
from enum import Enum

from .constants import REPORTING_MODELS
from .markdown.config import Markdown
Expand Down Expand Up @@ -184,9 +185,6 @@ def resolve_model(*, data_source: Dict[str, Any]) -> Dict[str, Any]:
raise ResolveModelException("Model key must be present on data_source")


from enum import Enum


class AllowedOperations(Enum):
# filtering
ONLY = "only"
Expand Down
3 changes: 0 additions & 3 deletions api/tacticalrmm/tacticalrmm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
)

if TYPE_CHECKING:
from agents.models import Agent
from clients.models import Site, Client


Expand Down Expand Up @@ -307,8 +306,6 @@ def get_db_value(
# get properties into an array
props = string.strip().split(".")

model = props[0]

# value is in the global keystore and replace value
if props[0] == "global" and len(props) == 2:
try:
Expand Down

0 comments on commit 804f486

Please sign in to comment.