Skip to content

Commit

Permalink
update get_initial to use current (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabelton authored Aug 5, 2022
1 parent 9e96ebd commit ca229fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions certificates/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from django.urls import reverse

from certificates import models
from certificates.views import CertificateDescriptionCreate
from certificates.views import CertificateList
from common.models.utils import override_current_transaction
from common.tests import factories
from common.tests.util import assert_model_view_renders
from common.tests.util import get_class_based_view_urls_matching_url
Expand All @@ -13,6 +15,8 @@
from common.views import TamatoListView
from common.views import TrackedModelDetailMixin

pytestmark = pytest.mark.django_db


@pytest.mark.parametrize(
"factory",
Expand Down Expand Up @@ -86,3 +90,21 @@ def test_certificate_list_view(view, url_pattern, valid_user_client):
"""Verify that certificate list view is under the url certificates/ and
doesn't return an error."""
assert_model_view_renders(view, url_pattern, valid_user_client)


# https://uktrade.atlassian.net/browse/TP2000-450 /PS-IGNORE
def test_description_create_get_initial():
"""Test that, where more than one version of a certificate exists,
get_initial returns only the current version."""
certificate = factories.CertificateFactory.create()
new_version = certificate.new_version(certificate.transaction.workbasket)
view = CertificateDescriptionCreate(
kwargs={
"certificate_type__sid": certificate.certificate_type.sid,
"sid": certificate.sid,
},
)
with override_current_transaction(new_version.transaction):
initial = view.get_initial()

assert initial["described_certificate"] == new_version
2 changes: 1 addition & 1 deletion certificates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CertificateDescriptionCreate(
):
def get_initial(self):
initial = super().get_initial()
initial["described_certificate"] = models.Certificate.objects.get(
initial["described_certificate"] = models.Certificate.objects.current().get(
certificate_type__sid=(self.kwargs.get("certificate_type__sid")),
sid=(self.kwargs.get("sid")),
)
Expand Down

0 comments on commit ca229fc

Please sign in to comment.