Skip to content

Commit

Permalink
further ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
anikaweinmann committed Dec 12, 2024
1 parent 8598fc0 commit 601eedf
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/actinia_example_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Check failure on line 2 in src/actinia_example_plugin/__init__.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (UP009)

src/actinia_example_plugin/__init__.py:2:1: UP009 UTF-8 encoding declaration is unnecessary
"""Copyright (c) 2018-present mundialis GmbH & Co. KG
"""Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
14 changes: 6 additions & 8 deletions src/actinia_example_plugin/api/helloworld.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Check failure on line 2 in src/actinia_example_plugin/api/helloworld.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (UP009)

src/actinia_example_plugin/api/helloworld.py:2:1: UP009 UTF-8 encoding declaration is unnecessary
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -25,22 +25,21 @@
__maintainer__ = "mundialis GmbH & Co. KG"


from flask import request, make_response
from flask_restful_swagger_2 import swagger
from flask_restful_swagger_2 import Resource
from flask import make_response, request
from flask_restful_swagger_2 import Resource, swagger

from actinia_example_plugin.apidocs import helloworld
from actinia_example_plugin.core.example import transform_input
from actinia_example_plugin.model.response_models import (
SimpleStatusCodeResponseModel,
)
from actinia_example_plugin.core.example import transform_input


class HelloWorld(Resource):
"""Returns 'Hello world!'"""
"""Returns 'Hello world!'."""

def __init__(self) -> None:
"""Hello world class initialisation"""
"""Hello world class initialisation."""
self.msg = "Hello world!"

@swagger.doc(helloworld.describeHelloWorld_get_docs)
Expand All @@ -51,7 +50,6 @@ def get(self) -> SimpleStatusCodeResponseModel:
@swagger.doc(helloworld.describeHelloWorld_post_docs)
def post(self) -> SimpleStatusCodeResponseModel:
"""Hello World post method with name from postbody."""

req_data = request.get_json(force=True)
if isinstance(req_data, dict) is False or "name" not in req_data:
return make_response("Missing name in JSON content", 400)
Expand Down
14 changes: 6 additions & 8 deletions src/actinia_example_plugin/api/project_helloworld.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Check failure on line 2 in src/actinia_example_plugin/api/project_helloworld.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (UP009)

src/actinia_example_plugin/api/project_helloworld.py:2:1: UP009 UTF-8 encoding declaration is unnecessary
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -25,9 +25,8 @@
__maintainer__ = "mundialis GmbH & Co. KG"


from flask import request, make_response
from flask_restful_swagger_2 import swagger
from flask_restful_swagger_2 import Resource
from flask import make_response, request
from flask_restful_swagger_2 import Resource, swagger

from actinia_example_plugin.apidocs import project_helloworld
from actinia_example_plugin.model.response_models import (
Expand All @@ -37,22 +36,21 @@


class ProjectHelloWorld(Resource):

Check failure on line 38 in src/actinia_example_plugin/api/project_helloworld.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (I001)

src/actinia_example_plugin/api/project_helloworld.py:28:1: I001 Import block is un-sorted or un-formatted
"""Returns 'Hello world with project/location!'"""
"""Returns 'Hello world with project/location!'."""

def __init__(self) -> None:
"""Project hello world class initialisation"""
"""Project hello world class initialisation."""
self.msg = "Project: Hello world!"

@swagger.doc(project_helloworld.describeProjectHelloWorld_get_docs)
def get(self, project_name) -> SimpleStatusCodeResponseModel:

Check failure on line 46 in src/actinia_example_plugin/api/project_helloworld.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (ANN001)

src/actinia_example_plugin/api/project_helloworld.py:46:19: ANN001 Missing type annotation for function argument `project_name`
"""Get 'Hello world!' as answer string."""
msg += f"{self.msg} {project_name}"
msg = f"{self.msg} {project_name}"
return SimpleStatusCodeResponseModel(status=200, message=msg)

@swagger.doc(project_helloworld.describeProjectHelloWorld_post_docs)
def post(self, project_name) -> SimpleStatusCodeResponseModel:
"""Hello World post method with name from postbody."""

req_data = request.get_json(force=True)
if isinstance(req_data, dict) is False or "name" not in req_data:
return make_response("Missing name in JSON content", 400)
Expand Down
6 changes: 3 additions & 3 deletions src/actinia_example_plugin/apidocs/helloworld.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +38,7 @@
"200": {
"description": "This response returns the string 'Hello World!'",
"schema": SimpleStatusCodeResponseModel,
}
},
},
}

Expand All @@ -61,7 +61,7 @@
"type": "string",
"description": "detailed message",
"example": "Missing name in JSON content",
}
},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/actinia_example_plugin/apidocs/project_helloworld.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,7 +49,7 @@
"200": {
"description": "This response returns the string 'Hello World!'",
"schema": SimpleStatusCodeResponseModel,
}
},
},
}

Expand Down Expand Up @@ -83,7 +83,7 @@
"type": "string",
"description": "detailed message",
"example": "Missing name in JSON content",
}
},
},
},
},
Expand Down
9 changes: 4 additions & 5 deletions src/actinia_example_plugin/core/example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -25,7 +25,6 @@
__maintainer__ = "mundialis GmbH & Co. KG"


def transform_input(inp):
"""Example core function"""
out = f"Hello world {inp.upper()}!"
return out
def transform_input(inp) -> str:
"""Example core function."""
return f"Hello world {inp.upper()}!"
8 changes: 4 additions & 4 deletions src/actinia_example_plugin/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,7 @@
from actinia_example_plugin.api.project_helloworld import ProjectHelloWorld


def create_project_endpoints(apidoc, projects_url_part="projects"):
def create_project_endpoints(apidoc, projects_url_part="projects") -> None:
"""
Function to add resources with "project" inside the endpoint url.
Expand All @@ -49,8 +49,8 @@ def create_project_endpoints(apidoc, projects_url_part="projects"):


# endpoints loaded if run as actinia-core plugin as well as standalone app
def create_endpoints(flask_api):
"""Create plugin endpoints"""
def create_endpoints(flask_api) -> None:
"""Create plugin endpoints."""
apidoc = flask_api

apidoc.add_resource(HelloWorld, "/helloworld")
Expand Down
4 changes: 2 additions & 2 deletions src/actinia_example_plugin/model/response_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -46,6 +46,6 @@ class SimpleStatusCodeResponseModel(Schema):


simpleResponseExample = SimpleStatusCodeResponseModel(
status=200, message="success"
status=200, message="success",
)
SimpleStatusCodeResponseModel.example = simpleResponseExample
2 changes: 1 addition & 1 deletion src/actinia_example_plugin/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
35 changes: 17 additions & 18 deletions tests/integrationtests/test_helloworld.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -27,36 +27,35 @@

import json
import pytest
from flask import Response

from actinia_api import URL_PREFIX
from flask import Response

from ..testsuite import ActiniaTestCase
from tests.testsuite import ActiniaTestCase


class ActiniaHelloWorldTest(ActiniaTestCase):
"""Actinia hello world test class for hello world endpoint"""
"""Actinia hello world test class for hello world endpoint."""

@pytest.mark.integrationtest
def test_get_helloworld(self):
"""Test the get method of the /helloworld endpoint"""
def test_get_helloworld(self) -> None:
"""Test the get method of the /helloworld endpoint."""
resp = self.app.get(f"{URL_PREFIX}/helloworld")

assert isinstance(
resp, Response
resp, Response,
), "The response is not of type Response"
assert resp.status_code == 200, "The status code is not 200"
assert hasattr(resp, "json"), "The response has no attribute 'json'"
assert "message" in resp.json, (
"There is no 'message' inside the " "response"
"There is no 'message' inside the response"
)
assert resp.json["message"] == "Hello world!", (
"The response message" " is wrong"
"The response message is wrong"
)

@pytest.mark.integrationtest
def test_post_helloworld(self):
"""Test the post method of the /helloworld endpoint"""
def test_post_helloworld(self) -> None:
"""Test the post method of the /helloworld endpoint."""
postbody = {"name": "test"}
resp = self.app.post(
f"{URL_PREFIX}/helloworld",
Expand All @@ -65,20 +64,20 @@ def test_post_helloworld(self):
content_type="application/json",
)
assert isinstance(
resp, Response
resp, Response,
), "The response is not of type Response"
assert resp.status_code == 200, "The status code is not 200"
assert hasattr(resp, "json"), "The response has no attribute 'json'"
assert "message" in resp.json, (
"There is no 'message' inside the " "response"
"There is no 'message' inside the response"
)
assert resp.json["message"] == "Hello world TEST!", (
"The response " "message is wrong"
"The response message is wrong"
)

@pytest.mark.integrationtest
def test_post_helloworld_error(self):
"""Test the post method of the /helloworld endpoint"""
def test_post_helloworld_error(self) -> None:
"""Test the post method of the /helloworld endpoint."""
postbody = {"namee": "test"}
resp = self.app.post(
f"{URL_PREFIX}/helloworld",
Expand All @@ -87,7 +86,7 @@ def test_post_helloworld_error(self):
content_type="application/json",
)
assert isinstance(
resp, Response
resp, Response,
), "The response is not of type Response"
assert resp.status_code == 400, "The status code is not 400"
assert resp.data == b"Missing name in JSON content"
2 changes: 1 addition & 1 deletion tests/testsuite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_transformation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-present mundialis GmbH & Co. KG
Copyright (c) 2018-present mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 601eedf

Please sign in to comment.