Skip to content

Commit

Permalink
update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
b3n4kh committed Sep 26, 2024
1 parent 0cc5d87 commit cdee746
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[project.optional-dependencies]
dev = ["ruff", "pytest", "pytest-flask", "build", "wheel", "setuptools_scm"]
dev = ["ruff", "pytest", "pytest-flask", "build", "wheel", "setuptools_scm", "requests-mock"]

[project.urls]
"Source Code" = "https://github.com/taranis-ai/taranis-scheduler"
Expand Down
2 changes: 1 addition & 1 deletion scheduler/core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_headers(self) -> dict:
def get_jwt_from_request(self):
return request.cookies.get(Config.JWT_ACCESS_COOKIE_NAME)

def check_response(self, response, url):
def check_response(self, response: requests.Response, url: str):
try:
if response.ok:
return response.json()
Expand Down
4 changes: 1 addition & 3 deletions scheduler/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from scheduler.core_api import CoreApi
from scheduler.config import Config
from scheduler.log import logger


def is_htmx_request() -> bool:
Expand All @@ -27,9 +26,8 @@ def get(self):
page_size = int(request.args.get("page_size", 10))

result = CoreApi().get_schedule({"page": page, "page_size": page_size, "search": search_term})
logger.debug(result)

if not result:
if result is None:
return "Failed to fetch jobs", 500

if is_htmx_request():
Expand Down
2 changes: 1 addition & 1 deletion scheduler/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="text-3xl font-bold mb-4">Scheduled Jobs</h1>
<tr>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Job ID</th>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Name</th>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Args</th>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Interval</th>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Next Run Time</th>
<th class="px-6 py-3 border-b-2 border-gray-300 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase">Actions</th>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion scheduler/templates/jobs_partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<tr hx-get="{{ url_for('jobs.jobdetails', job_id=job.id) }}" hx-target="#details-{{ job.id }}" hx-swap="innerHTML" data-expanded="false" onclick="toggleDetails('{{ job.id }}')" id="job-row-{{ job.id }}">
<td class="px-6 py-4 border-b border-gray-300 text-sm">{{ job.id }}</td>
<td class="px-6 py-4 border-b border-gray-300 text-sm">{{ job.name }}</td>
<td class="px-6 py-4 border-b border-gray-300 text-sm">{{ job.args }}</td>
<td class="px-6 py-4 border-b border-gray-300 text-sm">{{ job.trigger }}</td>
<td class="px-6 py-4 border-b border-gray-300 text-sm">{{ job.next_run_time }}</td>
<td class="px-6 py-4 border-b border-gray-300 text-sm">
<!-- Conditionally show the delete button only in debug mode -->
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def app():
@pytest.fixture(scope="session")
def client(app):
yield app.test_client()


@pytest.fixture
def schedule_get_mock(requests_mock):
from scheduler.config import Config

yield requests_mock.get(f"{Config.TARANIS_CORE_URL}/config/schedule", json={"items": [], "total_count": 0})
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from scheduler.config import Config


def test_jobindex(client):
def test_jobindex(schedule_get_mock, client):
response = client.get(f"{Config.APPLICATION_ROOT}/")
print(response.text)
assert response.status_code == 200
4 changes: 2 additions & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_flask_secret_key(app):
with app.app_context():
secret_key = app.config.get("SECRET_KEY", None)
assert secret_key == "test_key"
secret_key = app.config.get("JWT_ACCESS_COOKIE_NAME", None)
assert secret_key == "access_token_cookie"

0 comments on commit cdee746

Please sign in to comment.