diff --git a/consultation_analyser/consultations/migrations/0002_question_slug.py b/consultation_analyser/consultations/migrations/0002_question_slug.py new file mode 100644 index 000000000..abef11e61 --- /dev/null +++ b/consultation_analyser/consultations/migrations/0002_question_slug.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-03-01 17:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("consultations", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="question", + name="slug", + field=models.CharField(default=None, max_length=256), + preserve_default=False, + ), + ] diff --git a/consultation_analyser/consultations/models.py b/consultation_analyser/consultations/models.py index 02369cb9e..f4ba538da 100644 --- a/consultation_analyser/consultations/models.py +++ b/consultation_analyser/consultations/models.py @@ -4,3 +4,4 @@ class Question(models.Model): text = models.CharField(max_length=None) # no idea what's a sensible value for max_length + slug = models.CharField(max_length=256) diff --git a/consultation_analyser/consultations/templates/show_question.html b/consultation_analyser/consultations/templates/show_question.html index 735fc822c..2063a4443 100644 --- a/consultation_analyser/consultations/templates/show_question.html +++ b/consultation_analyser/consultations/templates/show_question.html @@ -1 +1 @@ -How should funding be allocated? +{{ question.text }} diff --git a/consultation_analyser/consultations/urls.py b/consultation_analyser/consultations/urls.py index 4f7145091..6b943f8c6 100644 --- a/consultation_analyser/consultations/urls.py +++ b/consultation_analyser/consultations/urls.py @@ -1,4 +1,4 @@ from django.urls import path from .views import show_question -urlpatterns = [path("questions/how-should-funding-be-allocated", show_question)] +urlpatterns = [path("questions/", show_question)] diff --git a/consultation_analyser/consultations/views.py b/consultation_analyser/consultations/views.py index 86d434674..78a6a1001 100644 --- a/consultation_analyser/consultations/views.py +++ b/consultation_analyser/consultations/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render from django.http import HttpRequest +from .models import Question -def show_question(request: HttpRequest): - return render(request, "show_question.html") +def show_question(request: HttpRequest, slug: str): + context = {"question": Question.objects.filter(slug=slug).first()} + return render(request, "show_question.html", context) diff --git a/poetry.lock b/poetry.lock index b35d21ded..82b99496a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -83,6 +83,38 @@ develop = ["coverage[toml] (>=5.0a4)", "furo (>=2021.8.17b43,<2021.9.dev0)", "py docs = ["furo (>=2021.8.17b43,<2021.9.dev0)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] testing = ["coverage[toml] (>=5.0a4)", "pytest (>=4.6.11)"] +[[package]] +name = "factory-boy" +version = "3.3.0" +description = "A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby." +optional = false +python-versions = ">=3.7" +files = [ + {file = "factory_boy-3.3.0-py2.py3-none-any.whl", hash = "sha256:a2cdbdb63228177aa4f1c52f4b6d83fab2b8623bf602c7dedd7eb83c0f69c04c"}, + {file = "factory_boy-3.3.0.tar.gz", hash = "sha256:bc76d97d1a65bbd9842a6d722882098eb549ec8ee1081f9fb2e8ff29f0c300f1"}, +] + +[package.dependencies] +Faker = ">=0.7.0" + +[package.extras] +dev = ["Django", "Pillow", "SQLAlchemy", "coverage", "flake8", "isort", "mongoengine", "sqlalchemy-utils", "tox", "wheel (>=0.32.0)", "zest.releaser[recommended]"] +doc = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-spelling"] + +[[package]] +name = "faker" +version = "23.3.0" +description = "Faker is a Python package that generates fake data for you." +optional = false +python-versions = ">=3.8" +files = [ + {file = "Faker-23.3.0-py3-none-any.whl", hash = "sha256:117ce1a2805c1bc5ca753b3dc6f9d567732893b2294b827d3164261ee8f20267"}, + {file = "Faker-23.3.0.tar.gz", hash = "sha256:458d93580de34403a8dec1e8d5e6be2fee96c4deca63b95d71df7a6a80a690de"}, +] + +[package.dependencies] +python-dateutil = ">=2.4" + [[package]] name = "filelock" version = "3.13.1" @@ -258,6 +290,20 @@ pytest = ">=7.0.0" docs = ["sphinx", "sphinx-rtd-theme"] testing = ["Django", "django-configurations (>=2.0)"] +[[package]] +name = "python-dateutil" +version = "2.9.0" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.9.0.tar.gz", hash = "sha256:78e73e19c63f5b20ffa567001531680d939dc042bf7850431877645523c66709"}, + {file = "python_dateutil-2.9.0-py2.py3-none-any.whl", hash = "sha256:cbf2f1da5e6083ac2fbfd4da39a25f34312230110440f424a14c7558bb85d82e"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "pyyaml" version = "6.0.1" @@ -360,6 +406,17 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + [[package]] name = "sqlparse" version = "0.4.4" @@ -421,4 +478,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "a631c7164447942be61064ea5ad7fdcea955198479e747a30dabd012975bf47b" +content-hash = "2e1d33d634cb3eb65631a6006296bc55e729e081fce14fc562b845081c154c23" diff --git a/pyproject.toml b/pyproject.toml index b4c33b302..741725926 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ pre-commit = "^3.6.2" files = '**/*.py' exclude= ['^consultation_analyser/consultations/migrations/'] + [tool.poetry.group.test.dependencies] pytest-django = "^4.8.0" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/factories.py b/tests/factories.py new file mode 100644 index 000000000..2a75abd6b --- /dev/null +++ b/tests/factories.py @@ -0,0 +1,10 @@ +import factory +from consultation_analyser.consultations import models + + +class QuestionFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.Question + + text = "Example question text?" + slug = "test-question" diff --git a/tests/integration/test_question_page.py b/tests/integration/test_question_page.py index b34cce87a..bb9611600 100644 --- a/tests/integration/test_question_page.py +++ b/tests/integration/test_question_page.py @@ -1,3 +1,10 @@ +import pytest +from tests.factories import QuestionFactory + + +@pytest.mark.django_db def test_get_question_page(client): - response = client.get("/questions/how-should-funding-be-allocated") + question = QuestionFactory(text="How should funding be allocated?", slug="how-should-funding-be-allocated") + + response = client.get(f"/questions/{question.slug}") assert "How should funding be allocated?" in str(response.content)