-
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.
Merge pull request #106 from i-dot-ai/feature/dummy-data-take-3
Feature/dummy data take 3
- Loading branch information
Showing
16 changed files
with
246 additions
and
47 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
consultation_analyser/consultations/jinja2/all-consultations.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends "base.html" %} | ||
{%- from 'govuk_frontend_jinja/components/button/macro.html' import govukButton -%} | ||
|
||
{% set page_title = "Consultations" %} | ||
|
||
{% block content %} | ||
<h1 class="govuk-heading-l">{{ page_title }}</h1> | ||
<ul class="govuk-list"> | ||
{% for consultation in consultations %} | ||
<li> | ||
<a href="{{ url('consultation', kwargs={'consultation_slug': consultation.slug}) }}" class="govuk-body-l govuk-link govuk-link--no-visited-state"> | ||
{{ consultation.name }} | ||
</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% endblock %} |
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
14 changes: 11 additions & 3 deletions
14
consultation_analyser/consultations/views/consultations.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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from django.http import HttpRequest | ||
from django.http import HttpRequest, HttpResponse | ||
from django.shortcuts import render | ||
from waffle.decorators import waffle_switch | ||
|
||
from .. import models | ||
|
||
|
||
@waffle_switch("CONSULTATION_PROCESSING") | ||
def show_questions(request: HttpRequest): | ||
questions = models.Question.objects.all().order_by("id")[:10] | ||
def show_all(request: HttpRequest) -> HttpResponse: | ||
# TODO - in future, would restrict to all consultations for user | ||
consultations = models.Consultation.objects.all() | ||
context = {"consultations": consultations} | ||
return render(request, "all-consultations.html", context) | ||
|
||
|
||
@waffle_switch("CONSULTATION_PROCESSING") | ||
def show(request: HttpRequest, consultation_slug: str) -> HttpResponse: | ||
questions = models.Question.objects.filter(section__consultation__slug=consultation_slug) | ||
context = {"questions": questions} | ||
return render(request, "consultation.html", context) |
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
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
28 changes: 28 additions & 0 deletions
28
consultation_analyser/support_console/jinja2/support_console/all-consultations.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "base.html" %} | ||
{%- from 'govuk_frontend_jinja/components/button/macro.html' import govukButton -%} | ||
|
||
{% set page_title = "All consultations" %} | ||
|
||
{% block content %} | ||
<h1 class="govuk-heading-l">{{ page_title }}</h1> | ||
<form method="post" novalidate>{{ csrf_input }} | ||
<ul class="govuk-list"> | ||
{% for consultation in consultations %} | ||
<li> | ||
<a href="{{ url('support_consultation', kwargs={'consultation_slug': consultation.slug}) }}" class="govuk-body govuk-link govuk-link--no-visited-state"> | ||
{{ consultation.name }} | ||
</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% if development_env %} | ||
{{ govukButton({ | ||
'text': "Generate dummy consultation", | ||
'name': "generate_dummy_consultation" | ||
}) }} | ||
{% endif %} | ||
|
||
</form> | ||
|
||
{% endblock %} |
24 changes: 24 additions & 0 deletions
24
consultation_analyser/support_console/jinja2/support_console/consultation.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends "base.html" %} | ||
{%- from 'govuk_frontend_jinja/components/button/macro.html' import govukButton -%} | ||
|
||
{% set page_title = "Consultation" %} | ||
|
||
{% block content %} | ||
<h1 class="govuk-heading-l">{{ page_title }}</h1> | ||
<form method="post" novalidate>{{ csrf_input }} | ||
<div> | ||
<a href="{{ url('consultation', kwargs={'consultation_slug': consultation.slug}) }}" class="govuk-body govuk-link govuk-link--no-visited-state"> | ||
{{ consultation.name }} | ||
</a> | ||
</div> | ||
|
||
<br> | ||
|
||
{{ govukButton({ | ||
'text': "Generate themes", | ||
'name': "generate_themes" | ||
}) }} | ||
|
||
</form> | ||
|
||
{% endblock %} |
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
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
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
|
||
from consultation_analyser.consultations.dummy_data import DummyConsultation | ||
from consultation_analyser.consultations.models import Consultation, Theme | ||
from consultation_analyser.factories import UserFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_logging_in_to_support(django_app): | ||
# given I am an admin user | ||
UserFactory(email="[email protected]", password="admin", is_staff=True) # pragma: allowlist secret | ||
|
||
# when I visit support | ||
login_page = django_app.get("/support").follow().follow() # 2 redirects | ||
|
||
# and I sign in to support | ||
login_page.form["username"] = "[email protected]" # Django field is called "username" | ||
login_page.form["password"] = "admin" # pragma: allowlist secret | ||
support_home = login_page.form.submit().follow() | ||
|
||
# then I should see the support console page | ||
assert "Consultation analyser support console" in support_home | ||
|
||
logged_out_page = support_home.click("Sign out") | ||
|
||
assert "Consultation analyser support console" not in logged_out_page | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_generating_dummy_data(django_app): | ||
page_url = "/support/consultations/" | ||
UserFactory(email="[email protected]", password="admin", is_staff=True) # pragma: allowlist secret | ||
login_page = django_app.get(page_url).follow() | ||
login_page.form["username"] = "[email protected]" | ||
login_page.form["password"] = "admin" # pragma: allowlist secret | ||
consultations_page = login_page.form.submit().follow() | ||
assert "All consultations" in consultations_page | ||
|
||
# Check dummy data button does generate a new consultation | ||
initial_count = Consultation.objects.all().count() | ||
consultations_page = consultations_page.form.submit("generate_dummy_consultation") | ||
count_after_dummy_data = Consultation.objects.all().count() | ||
assert count_after_dummy_data > initial_count | ||
|
||
# Check redirected to individual consultation page in support | ||
latest_consultation = Consultation.objects.all().order_by("created_at").last() | ||
next_page = consultations_page.click(latest_consultation.name) | ||
assert "Generate themes" in next_page | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_generate_themes(django_app): | ||
DummyConsultation(name="Test consultation", slug="test-consultation", include_themes=False) | ||
UserFactory(email="[email protected]", password="admin", is_staff=True) # pragma: allowlist secret | ||
login_page = django_app.get("/support/consultations/test-consultation/").follow() | ||
login_page.form["username"] = "[email protected]" | ||
login_page.form["password"] = "admin" # pragma: allowlist secret | ||
consultation_page = login_page.form.submit().follow() | ||
assert "Test consultation" in consultation_page | ||
consultation_page = consultation_page.form.submit("generate_themes") | ||
generated_themes = Theme.objects.filter(answer__question__section__consultation__slug="test-consultation") | ||
assert generated_themes.exists() |
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,16 +1,20 @@ | ||
import pytest | ||
from waffle.testutils import override_switch | ||
|
||
from consultation_analyser.factories import ConsultationFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
@override_switch("CONSULTATION_PROCESSING", True) | ||
def test_accessing_when_flag_is_on(client): | ||
consultation = ConsultationFactory() | ||
assert client.get("/").status_code == 200 | ||
assert client.get("/consultations/").status_code == 200 | ||
assert client.get(f"/consultations/{consultation.slug}/").status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
@override_switch("CONSULTATION_PROCESSING", False) | ||
def test_accessing_when_flag_is_off(client): | ||
consultation = ConsultationFactory() | ||
assert client.get("/").status_code == 200 | ||
assert client.get("/consultations/").status_code == 404 | ||
assert client.get(f"/consultations/{consultation.slug}/").status_code == 404 |
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,19 @@ | ||
import pytest | ||
|
||
from consultation_analyser.factories import ConsultationFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_no_login_support_pages(client): | ||
ConsultationFactory(slug="consultation-slug") | ||
support_urls = [ | ||
"", | ||
"sign-out/", | ||
"consultations/", | ||
"consultations/consultation-slug/", | ||
] | ||
for url in support_urls: | ||
full_url = f"/support/{url}" | ||
response = client.get(full_url) | ||
print(full_url) | ||
assert response.status_code == 302 # No access, redirect to admin login |
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