Skip to content

Commit

Permalink
Merge pull request lsst-sqre#2590 from lsst-sqre/tickets/DM-40947
Browse files Browse the repository at this point in the history
DM-40947: Add test for application descriptions
  • Loading branch information
rra authored Sep 28, 2023
2 parents ef5052f + f376463 commit 6acc350
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/applications/kubernetes-replicator/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. px-app:: kubernetes-replicator

#################################################
kubernetes-replicator - Cross-namespace resources
kubernetes-replicator Cross-namespace resources
#################################################

kubernetes-replicator is a Kubernetes operator that replicates resources across namespaces.
Expand Down
6 changes: 3 additions & 3 deletions docs/applications/linters/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.. px-app:: linters

######################################
linters - automated chechking of DNS
######################################
####################################
linters — Automated chechking of DNS
####################################

Linters provides a way to automatically and repeatedly check things in ops, such as if DNS entries
are pointing to IP addresses that we are using, or are they dangling. We use the route53 API
Expand Down
5 changes: 2 additions & 3 deletions docs/applications/obsloctap/index.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
.. px-app:: obsloctap

####################################
obsloctap — serve observing schedule
obsloctap — Serve observing schedule
####################################

Lookup and reformat ``lsst.sal.Scheduler.logevent_predictedSchedule``.
Return a json file of the future observations.
Return a JSON file of the future observations.
Todo: Also track which observations were made implement ObsLocTAP_ IVOA standard.

.. _ObsLocTAP: https://www.ivoa.net/documents/ObsLocTAP/


.. jinja:: obsloctap
:file: applications/_summary.rst.jinja

Expand Down
2 changes: 1 addition & 1 deletion docs/applications/onepassword-connect-dev/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. px-app:: onepassword-connect-dev

####################################################
onepassword-connect-dev - 1Password API server (dev)
onepassword-connect-dev 1Password API server (dev)
####################################################

1Password Connect provides API access to a 1Password vault.
Expand Down
10 changes: 9 additions & 1 deletion src/phalanx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import re
import sys
from pathlib import Path

Expand Down Expand Up @@ -121,7 +122,10 @@ def application() -> None:
"-d",
"--description",
prompt="Short description",
help="Short description of the new application.",
help=(
"Short description of the new application. Must start with capital"
" letter and, with the application name, be less than 80 characters."
),
)
@click.option(
"-s",
Expand All @@ -142,6 +146,10 @@ def application_create(
"""
if not config:
config = _find_config()
if len(name) + 3 + len(description) > 80:
raise click.UsageError("Name plus description is too long")
if not re.match("[A-Z0-9]", description):
raise click.UsageError("Description must start with capital letter")
factory = Factory(config)
application_service = factory.create_application_service()
application_service.create_application(
Expand Down
29 changes: 29 additions & 0 deletions tests/cli/application_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ def test_create(tmp_path: Path) -> None:
assert environment.applications["hips"].chart["sources"][0] == expected


def test_create_errors(tmp_path: Path) -> None:
config_path = tmp_path / "phalanx"
shutil.copytree(str(phalanx_test_path()), str(config_path))
result = run_cli(
"application",
"create",
"some-really-long-app-name-please-do-not-do-this",
"--description",
"Some really long description on top of the app name",
"--config",
str(config_path),
needs_config=False,
)
assert "Name plus description is too long" in result.output
assert result.exit_code == 2
result = run_cli(
"application",
"create",
"app",
"--description",
"lowercase description",
"--config",
str(config_path),
needs_config=False,
)
assert "Description must start with capital letter" in result.output
assert result.exit_code == 2


def test_create_prompt(tmp_path: Path) -> None:
config_path = tmp_path / "phalanx"
shutil.copytree(str(phalanx_test_path()), str(config_path))
Expand Down
25 changes: 25 additions & 0 deletions tests/docs/applications_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Tests for the application documentation pages."""

from __future__ import annotations

import re
from pathlib import Path


def test_descriptions() -> None:
"""Ensure all application pages have proper short descriptions."""
doc_root = Path(__file__).parent.parent.parent / "docs" / "applications"
for application in doc_root.iterdir():
if not application.is_dir():
continue
index_path = application / "index.rst"
index_rst = index_path.read_text()
m = re.search(r"\n(#+)\n([^\n]+)\n\1\n", index_rst)
assert m, f"No title found in {index_path}"
title = m.group(2)
assert len(title) <= 80, f"Title too long in {index_path}"
m = re.match(r"\S+ — (\S.*$)", title)
assert m, f"Invalid title format in {index_path}"
description = m.group(1)
m = re.match("[A-Z0-9]", description)
assert m, f"Description must start with capital letter in {index_path}"

0 comments on commit 6acc350

Please sign in to comment.