-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add a slug field to the Question so we can look it up in the url - add factoryboy so we can declare database state in tests
- Loading branch information
1 parent
1ad5cc4
commit fc25dff
Showing
10 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
consultation_analyser/consultations/migrations/0002_question_slug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
consultation_analyser/consultations/templates/show_question.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
How should funding be allocated? | ||
{{ question.text }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/<str:slug>", show_question)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |