Skip to content

Commit

Permalink
fix: black issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cakeinsauce committed May 17, 2024
1 parent 56546e0 commit cd10945
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 38 deletions.
1 change: 0 additions & 1 deletion assets/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ def test_file_processor_conversion_error(
assert converter.conversion_status == "conversion error"



@pytest.mark.skip(reason="tests refactoring")
def test_convert_pdf(file_converter_service):
with NamedTemporaryFile(suffix=".pdf", prefix="123") as tmp_file:
Expand Down
1 change: 1 addition & 0 deletions convert/convert/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
DEFAULT_PDF_FONT_WIDTH = 7
DEFAULT_PDF_LINE_SPACING = 2


def get_service_uri(prefix: str) -> str: # noqa
service_scheme = os.getenv(f"{prefix}SERVICE_SCHEME")
service_host = os.getenv(f"{prefix}SERVICE_HOST")
Expand Down
1 change: 0 additions & 1 deletion convert/convert/converters/base_format/models/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class PageSize(BaseModel):


class Page(BaseModel):

"""A model for the field with bboxes."""

page_num: int = Field(..., example=1)
Expand Down
14 changes: 8 additions & 6 deletions jobs/jobs/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ def create_boto3_config() -> Dict[str, Optional[str]]:
"aws_access_key_id": config.S3_ACCESS_KEY,
"aws_secret_access_key": config.S3_SECRET_KEY,
"endpoint_url": (
("https" if config.S3_SECURE else "http")
+ "://"
+ config.S3_ENDPOINT
)
if config.S3_ENDPOINT
else None,
(
("https" if config.S3_SECURE else "http")
+ "://"
+ config.S3_ENDPOINT
)
if config.S3_ENDPOINT
else None
),
}
)
elif config.S3_PROVIDER == S3Providers.AWS_IAM:
Expand Down
6 changes: 3 additions & 3 deletions jobs/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def testing_app(testing_engine, testing_session, setup_tenant):
),
):
main.app.dependency_overrides[main.tenant] = lambda: setup_tenant
main.app.dependency_overrides[
service.get_session
] = lambda: testing_session
main.app.dependency_overrides[service.get_session] = (
lambda: testing_session
)
client = TestClient(main.app)
yield client

Expand Down
8 changes: 5 additions & 3 deletions lib/filter_lib/src/query_modificator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ def splint_to_distinct_and_not(
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
distinct_filters, non_distinct_filters = [], []
for fil in filters:
distinct_filters.append(fil) if _op_is_distinct(
fil
) else non_distinct_filters.append(fil)
(
distinct_filters.append(fil)
if _op_is_distinct(fil)
else non_distinct_filters.append(fil)
)

return distinct_filters, non_distinct_filters

Expand Down
8 changes: 5 additions & 3 deletions lib/python3.12/filter_lib/src/query_modificator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ def splint_to_distinct_and_not(
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
distinct_filters, non_distinct_filters = [], []
for fil in filters:
distinct_filters.append(fil) if _op_is_distinct(
fil
) else non_distinct_filters.append(fil)
(
distinct_filters.append(fil)
if _op_is_distinct(fil)
else non_distinct_filters.append(fil)
)

return distinct_filters, non_distinct_filters

Expand Down
3 changes: 1 addition & 2 deletions search/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ def __init__(self):
async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
...
async def __aexit__(self, exc_type, exc_val, exc_tb): ...

def __aiter__(self):
return self
Expand Down
1 change: 0 additions & 1 deletion search/tests/override_app_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
there are necessary tenants in token.
"""


from tenant_dependency import TenantData

from search.main import TOKEN, app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-12-02 15:04:55.726594
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions taxonomy/alembic/versions/bdea8a93cafe_first_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-11-24 16:36:12.022247
"""

import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-12-26 04:40:50.608253
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions taxonomy/taxonomy/token_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Dependency, that will validate X-Current-Tenant
and Authorization token
"""

import os

from tenant_dependency import TenantData, get_tenant_info
Expand Down
1 change: 1 addition & 0 deletions taxonomy/tests/override_app_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
that given token is valid, not expired and
there are necessary tenants in token.
"""

from tenant_dependency import TenantData

HEADER_TENANT = "X-Current-Tenant"
Expand Down
5 changes: 4 additions & 1 deletion taxonomy/tests/test_taxonomy_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ def test_should_delete_latest_taxonomy_from_db(
db_session,
):
# given
new_latest_taxonomy, taxonomy_to_delete, = sorted(
(
new_latest_taxonomy,
taxonomy_to_delete,
) = sorted(
prepare_two_taxonomy_records_with_same_id_in_db,
key=lambda x: x.version,
)
Expand Down
9 changes: 7 additions & 2 deletions users/tests/keycloak/test_query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing src/keycloak/query.py."""

from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -31,7 +32,9 @@ async def test_get_token_v2(request_mock):


@pytest.mark.asyncio
async def test_introspect_token_test(request_mock, mocked_token1, mocked_token1_data):
async def test_introspect_token_test(
request_mock, mocked_token1, mocked_token1_data
):
request_mock.return_value.__aenter__.return_value.json.return_value = (
mocked_token1_data
)
Expand All @@ -40,7 +43,9 @@ async def test_introspect_token_test(request_mock, mocked_token1, mocked_token1_


@pytest.mark.asyncio
async def test_get_master_realm_auth_data(request_mock, mocked_admin_auth_data):
async def test_get_master_realm_auth_data(
request_mock, mocked_admin_auth_data
):
request_mock.return_value.__aenter__.return_value.json.return_value = (
mocked_admin_auth_data
)
Expand Down
72 changes: 57 additions & 15 deletions users/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def does_not_raise():
roles=["admin"],
tenants=["tenant"],
),
TenantData(token="token", user_id="user_id", roles=[], tenants=["tenant"]),
TenantData(
token="token", user_id="user_id", roles=[], tenants=["tenant"]
),
],
)
def test_check_authorization_role_is_missing(mock_tenant_data):
Expand Down Expand Up @@ -210,7 +212,9 @@ def test_login_status_code(token_schema, request_body, status_code):
class TestGetUserGWT:
def test_get_user_jwt_body(self, mock_user, user_representation):
response = client.get("/users/current")
assert response.json() == user_representation(user_id="1", user_name="user")
assert response.json() == user_representation(
user_id="1", user_name="user"
)

def test_get_user_jwt_status_code(self, mock_user):
response = client.get("/users/current")
Expand All @@ -222,15 +226,19 @@ class TestGetUser:
@pytest.mark.skip(reason="tests refactoring")
def test_get_user_body(self, mock_user, user_representation):
response = client.get("/users/user-id")
assert response.json() == user_representation(user_id="1", user_name="user")
assert response.json() == user_representation(
user_id="1", user_name="user"
)

@pytest.mark.skip(reason="tests refactoring")
def test_get_user_status_code(self, mock_user):
response = client.get("/users/user-id")
assert response.status_code == 200


def test_get_user_info_from_token_introspection(mocked_token1, mocked_token1_data):
def test_get_user_info_from_token_introspection(
mocked_token1, mocked_token1_data
):
with patch(
"users.keycloak.query.introspect_token",
return_value=mocked_token1_data,
Expand Down Expand Up @@ -338,7 +346,9 @@ def test_add_user_to_tenant2(
("group_1", {"detail": "User has been removed from the tenant"}),
],
)
def test_remove_user_from_tenant_body(mock_user, update_user, tenant, expected_result):
def test_remove_user_from_tenant_body(
mock_user, update_user, tenant, expected_result
):
response = client.delete(f"/tenants/{tenant}/users/user_1")
assert response.json() == expected_result

Expand All @@ -359,7 +369,9 @@ def test_remove_user_from_tenant_status_code(


@patch("users.keycloak.query.get_users_v2", return_value=mock_all_users)
@patch("users.keycloak.query.get_users_by_role", return_value=mock_users_with_role)
@patch(
"users.keycloak.query.get_users_by_role", return_value=mock_users_with_role
)
class TestUsersSearch:
@pytest.mark.parametrize("request_body", [{}, {"filters": []}])
def test_get_all_users_body(
Expand Down Expand Up @@ -388,7 +400,11 @@ def test_filter_users_by_name_body(
):
response = client.post(
"/users/search",
json={"filters": [{"field": "name", "operator": "like", "value": "r"}]},
json={
"filters": [
{"field": "name", "operator": "like", "value": "r"}
]
},
)
assert response.json() == [
user_representation(user_id="1", user_name="user"),
Expand All @@ -400,7 +416,11 @@ def test_filter_users_by_name_status_code(
):
response = client.post(
"/users/search",
json={"filters": [{"field": "name", "operator": "like", "value": "r"}]},
json={
"filters": [
{"field": "name", "operator": "like", "value": "r"}
]
},
)
assert response.status_code == 200

Expand Down Expand Up @@ -443,14 +463,20 @@ def test_filter_users_by_empty_name_status_code(
):
response = client.post(
"/users/search",
json={"filters": [{"field": "name", "operator": "like", "value": ""}]},
json={
"filters": [{"field": "name", "operator": "like", "value": ""}]
},
)
assert response.status_code == 422

@pytest.mark.parametrize(
"request_body",
[
{"filters": [{"field": "id", "operator": "in", "value": ["1", "2"]}]},
{
"filters": [
{"field": "id", "operator": "in", "value": ["1", "2"]}
]
},
{
"filters": [
{
Expand Down Expand Up @@ -482,7 +508,11 @@ def test_filter_users_by_id_body(
@pytest.mark.parametrize(
"request_body",
[
{"filters": [{"field": "id", "operator": "in", "value": ["1", "2"]}]},
{
"filters": [
{"field": "id", "operator": "in", "value": ["1", "2"]}
]
},
{
"filters": [
{
Expand Down Expand Up @@ -511,7 +541,11 @@ def test_filter_users_by_id_status_code(
"request_body",
[
{"filters": [{"field": "id", "operator": "in", "value": []}]},
{"filters": [{"field": "id", "operator": "in", "value": ["wrong_id"]}]},
{
"filters": [
{"field": "id", "operator": "in", "value": ["wrong_id"]}
]
},
],
)
def test_filter_users_by_wrong_or_empty_id_body(
Expand All @@ -531,7 +565,11 @@ def test_filter_users_by_wrong_or_empty_id_body(
"request_body",
[
{"filters": [{"field": "id", "operator": "in", "value": []}]},
{"filters": [{"field": "id", "operator": "in", "value": ["wrong_id"]}]},
{
"filters": [
{"field": "id", "operator": "in", "value": ["wrong_id"]}
]
},
],
)
def test_filter_users_by_wrong_or_empty_id_status_code(
Expand All @@ -544,7 +582,9 @@ def test_filter_users_by_wrong_or_empty_id_status_code(
response = client.post(
"/users/search",
json={
"filters": [{"field": "id", "operator": "in", "value": ["wrong_id"]}]
"filters": [
{"field": "id", "operator": "in", "value": ["wrong_id"]}
]
},
)
assert response.status_code == 200
Expand Down Expand Up @@ -592,7 +632,9 @@ def test_filter_users_by_wrong_role_body(
response = client.post(
"/users/search",
json={
"filters": [{"field": "role", "operator": "eq", "value": "wrong_role"}]
"filters": [
{"field": "role", "operator": "eq", "value": "wrong_role"}
]
},
)
assert response.status_code == 422
Expand Down

0 comments on commit cd10945

Please sign in to comment.