Skip to content

Commit

Permalink
Merge branch 'main' into messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cc-a committed Sep 24, 2024
2 parents 10f05e9 + 169648f commit c60ddab
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 68 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ jobs:
run: poetry install

- name: Run tests
run: poetry run pytest
run: poetry run pytest --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@v3.0.1
- uses: pre-commit-ci/lite-action@v1.0.2
- uses: pre-commit-ci/lite-action@v1.0.3
if: always()
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ repos:
- id: pretty-format-yaml
args: [--autofix, --indent, '2', --offset, '2']
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
rev: 0.29.2
hooks:
- id: check-github-workflows
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
88
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--no-cov"
]
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# dune_processes
<!-- markdownlint-disable MD041 -->
[![GitHub](https://img.shields.io/github/license/ImperialCollegeLondon/dune_processes)](https://raw.githubusercontent.com/ImperialCollegeLondon/dune_processes/main/LICENSE)
[![Test and build](https://github.com/ImperialCollegeLondon/dune_processes/actions/workflows/ci.yml/badge.svg)](https://github.com/ImperialCollegeLondon/dune_processes/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/ImperialCollegeLondon/dune_processes/graph/badge.svg?token=PG0WTYF8EY)](https://codecov.io/gh/ImperialCollegeLondon/dune_processes)

This repo defines the web app for the Dune Process Manager web interface.
# DUNE processes web interface

This repo defines the web interface for the DUNE Process Manager.

## For developers

Expand Down
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't fail CI if coverage drops
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true

ignore:
- dune_processes/settings/_production.py
7 changes: 7 additions & 0 deletions dune_processes/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@

AUTH_USER_MODEL = "main.User"

LOGIN_URL = "main:login"
LOGIN_REDIRECT_URL = "main:index"

INSTALLED_APPS += ["django_bootstrap5"]
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html"

PROCESS_MANAGER_URL = os.getenv("PROCESS_MANAGER_URL", "localhost:10054")

INSTALLED_APPS += ["crispy_forms", "crispy_bootstrap5"]
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
6 changes: 4 additions & 2 deletions main/templates/main/boot_process.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{% extends "main/base.html" %}
{% load crispy_forms_tags %}
{% load django_bootstrap5 %}

{% block title %}Boot Process{% endblock title %}

{% block content %}

<form action="{% url 'main:boot_process' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
{{ form|crispy }}
{% bootstrap_button button_type="submit" content="Submit" %}
</form>

{% endblock content %}
37 changes: 37 additions & 0 deletions main/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "../main/base.html" %}

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}

<form method="post" action="{% url 'main:login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>

{# Assumes you set up the password_reset view in your URLconf #}
<p><a href="{% url 'main:password_reset' %}">Lost password?</a></p>

{% endblock %}
3 changes: 2 additions & 1 deletion main/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Urls module for the main app."""

from django.urls import path
from django.urls import include, path

from . import views

app_name = "main"
urlpatterns = [
path("", views.index, name="index"),
path("accounts/", include("django.contrib.auth.urls")),
path("restart/<uuid:uuid>", views.restart_process, name="restart"),
path("kill/<uuid:uuid>", views.kill_process, name="kill"),
path("flush/<uuid:uuid>", views.flush_process, name="flush"),
Expand Down
9 changes: 8 additions & 1 deletion main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import django_tables2
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse, reverse_lazy
Expand Down Expand Up @@ -47,6 +49,7 @@ async def get_session_info() -> ProcessInstanceList:
return await pmd.ps(query)


@login_required
def index(request: HttpRequest) -> HttpResponse:
"""View that renders the index/home page."""
val = asyncio.run(get_session_info())
Expand Down Expand Up @@ -109,6 +112,7 @@ async def _process_call(uuid: str, action: ProcessAction) -> None:
await pmd.flush(query)


@login_required
def restart_process(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
"""Restart the process associated to the given UUID.
Expand All @@ -124,6 +128,7 @@ def restart_process(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
return HttpResponseRedirect(reverse("main:index"))


@login_required
def kill_process(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
"""Kill the process associated to the given UUID.
Expand All @@ -138,6 +143,7 @@ def kill_process(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
return HttpResponseRedirect(reverse("main:index"))


@login_required
def flush_process(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
"""Flush the process associated to the given UUID.
Expand Down Expand Up @@ -167,6 +173,7 @@ async def _get_process_logs(uuid: str) -> list[DecodedResponse]:
return [item async for item in pmd.logs(request)]


@login_required
def logs(request: HttpRequest, uuid: uuid.UUID) -> HttpResponse:
"""Display the logs of a process.
Expand Down Expand Up @@ -194,7 +201,7 @@ async def _boot_process(user: str, data: dict[str, str | int]) -> None:
pass


class BootProcessView(FormView): # type: ignore [type-arg]
class BootProcessView(LoginRequiredMixin, FormView): # type: ignore [type-arg]
"""View for the BootProcess form."""

template_name = "main/boot_process.html"
Expand Down
78 changes: 55 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ druncschema = { git = "https://github.com/DUNE-DAQ/druncschema.git" }
django-tables2 = "^2.7.0"
django-bootstrap5 = "^24.2"
pytest-asyncio = "^0.24.0"
django-crispy-forms = "^2.3"
crispy-bootstrap5 = "^2024.2"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2"
pytest = "^8.3"
pytest-cov = "^5.0.0"
pytest-mypy = "^0.10.0"
pytest-mock = "^3.7.0"
pre-commit = "^3.0.4"
ruff = "^0.6.4"
ruff = "^0.6.5"
django-stubs = { extras = ["compatible-mypy"], version = "^5.0.4" }
pytest-django = "^4.9.0"

Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
"""Configuration for pytest."""

import pytest
from django.test import Client


@pytest.fixture
def auth_client(django_user_model) -> Client:
"""Return an authenticated client."""
user = django_user_model.objects.create(username="testuser")
client = Client()
client.force_login(user)
return client


@pytest.fixture
Expand Down
Loading

0 comments on commit c60ddab

Please sign in to comment.