Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
eadpearce committed Nov 30, 2022
2 parents 3e9faec + 45d41f6 commit 6042d51
Show file tree
Hide file tree
Showing 82 changed files with 2,185 additions and 1,701 deletions.
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.3
rev: v2.3.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/myint/autoflake.git
rev: v1.4
rev: v1.7.7
hooks:
- id: autoflake
args:
Expand All @@ -19,7 +19,7 @@ repos:
- id: isort
args: [--force-single-line-imports]
- repo: https://github.com/myint/docformatter.git
rev: v1.4
rev: v1.5.0
hooks:
- id: docformatter
args:
Expand All @@ -30,7 +30,7 @@ repos:
"--pre-summary-newline",
]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/ikamensh/flynt/
Expand All @@ -52,13 +52,6 @@ repos:
language_version: python3.9
pass_filenames: true
require_serial: true
- id: pii_secret_file_content_ner
files: ''
language: python
language_version: python3.9
args: [--ner_output_file=ner_output_file.txt] # uncomment to output NER entities
pass_filenames: true
require_serial: true
- id: hooks_version_check
name: Checking local hooks against latest release
verbose: true
Expand Down
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ Installing
$ npm install
$ npm run build
Those using Mac m1 laptops may have problems installing certain packages (e.g.
psycopg2 and lxml) via requirements-dev.txt. In this scenario you should run the
following from a rosetta terminal (see `this article
<https://www.courier.com/blog/tips-and-tricks-to-setup-your-apple-m1-for-development/>`_ ),
substituting your own python version as appropriate:

.. code:: sh
$ pip uninstall psycopg2
$ brew install postgresql
$ export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
$ export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L${HOME}/.pyenv/versions/3.8.10/lib"
$ arch -arm64 pip install psycopg2 --no-binary :all:
Credit due to armenzg and his `answer here
<https://github.com/psycopg/psycopg2/issues/1286#issuecomment-914286206>`_ .

Running
~~~~~~~

Expand Down Expand Up @@ -221,6 +238,14 @@ Open another terminal and start a Celery worker:
celery -A common.celery worker --loglevel=info
To monitor celery workers or individual tasks run:

.. code:: sh
celery flower
See `flower docs <https://flower.readthedocs.io/en/latest/>`_ for more details


Manually trigger the upload to s3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
42 changes: 33 additions & 9 deletions additional_codes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Meta:
fields = ("type", "valid_between")


class AdditionalCodeCreateForm(ValidityPeriodForm):
class AdditionalCodeCreateBaseForm(ValidityPeriodForm):
class Meta:
model = models.AdditionalCode
fields = ("type", "code", "valid_between")
Expand All @@ -101,14 +101,6 @@ class Meta:
"the additional code type"
),
)
description = forms.CharField(
label="Additional code description",
help_text=(
"You may enter HTML formatting if required. See the guide below "
"for more information."
),
widget=forms.Textarea,
)

def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
Expand All @@ -121,6 +113,21 @@ def __init__(self, *args, **kwargs):
self.helper = FormHelper(self)
self.helper.label_size = Size.SMALL
self.helper.legend_size = Size.SMALL


class AdditionalCodeCreateForm(AdditionalCodeCreateBaseForm):
description = forms.CharField(
label="Additional code description",
help_text=(
"You may enter HTML formatting if required. See the guide below "
"for more information."
),
widget=forms.Textarea,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.helper.layout = Layout(
"type",
Field.text("code", field_width=Fluid.ONE_QUARTER, maxlength="3"),
Expand Down Expand Up @@ -160,6 +167,23 @@ def save(self, commit=True):
return instance


class AdditionalCodeEditCreateForm(AdditionalCodeCreateBaseForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.helper.layout = Layout(
"type",
Field.text("code", field_width=Fluid.ONE_QUARTER, maxlength="3"),
"start_date",
Submit(
"submit",
"Save",
data_module="govuk-button",
data_prevent_double_click="true",
),
)


class AdditionalCodeDescriptionForm(DescriptionForm):
class Meta:
model = models.AdditionalCodeDescription
Expand Down
78 changes: 78 additions & 0 deletions additional_codes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from additional_codes.views import AdditionalCodeList
from common.tests import factories
from common.tests.util import assert_model_view_renders
from common.tests.util import assert_read_only_model_view_returns_list
from common.tests.util import date_post_data
from common.tests.util import get_class_based_view_urls_matching_url
from common.tests.util import raises_if
from common.tests.util import validity_period_post_data
from common.tests.util import view_is_subclass
from common.tests.util import view_urlpattern_ids
from common.validators import UpdateType
from common.views import TamatoListView
from common.views import TrackedModelDetailMixin

Expand Down Expand Up @@ -49,6 +51,48 @@ def test_additional_code_create_form(use_create_form, new_data, expected_valid):
use_create_form(AdditionalCode, new_data)


@pytest.mark.parametrize(
("data_changes", "expected_valid"),
(
({**date_post_data("start_date", datetime.date.today())}, True),
(
{
"start_date_0": "",
"start_date_1": "",
"start_date_2": "",
},
False,
),
),
)
@pytest.mark.parametrize(
"update_type",
(
UpdateType.CREATE,
UpdateType.UPDATE,
),
)
def test_additional_code_edit_views(
data_changes,
expected_valid,
update_type,
use_edit_view,
workbasket,
published_additional_code_type,
):
"""Tests that additional code edit views (for update types CREATE and
UPDATE) allows saving a valid form from an existing instance and that an
invalid form fails validation as expected."""

additional_code = factories.AdditionalCodeFactory.create(
update_type=update_type,
type=published_additional_code_type,
transaction=workbasket.new_transaction(),
)
with raises_if(ValidationError, not expected_valid):
use_edit_view(additional_code, data_changes)


@pytest.mark.parametrize(
"factory",
(factories.AdditionalCodeFactory, factories.AdditionalCodeDescriptionFactory),
Expand Down Expand Up @@ -93,3 +137,37 @@ def test_additional_codes_list_view(view, url_pattern, valid_user_client):
"""Verify that additional code list view is under the url additional_codes/
and doesn't return an error."""
assert_model_view_renders(view, url_pattern, valid_user_client)


def test_additional_codes_api_list_view(valid_user_client, date_ranges):
selected_type = factories.AdditionalCodeTypeFactory.create()
expected_results = [
factories.AdditionalCodeFactory.create(
valid_between=date_ranges.normal,
type=selected_type,
),
factories.AdditionalCodeFactory.create(
valid_between=date_ranges.earlier,
type=selected_type,
),
]
assert_read_only_model_view_returns_list(
"additionalcode",
"value",
"pk",
expected_results,
valid_user_client,
)


def test_additional_code_type_api_list_view(valid_user_client):
expected_results = [
factories.AdditionalCodeTypeFactory.create(),
]
assert_read_only_model_view_returns_list(
"additionalcodetype",
"sid",
"sid",
expected_results,
valid_user_client,
)
5 changes: 4 additions & 1 deletion additional_codes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
views.AdditionalCodeViewSet,
basename="additionalcode",
)
api_router.register(r"additional_code_types", views.AdditionalCodeTypeViewSet)
api_router.register(
r"additional_code_types",
views.AdditionalCodeTypeViewSet,
)

detail = "<sid:sid>"
description_detail = "<sid:described_additionalcode__sid>/description/<sid:sid>"
Expand Down
Loading

0 comments on commit 6042d51

Please sign in to comment.