Repository: cisagov/manage.get.gov

Issue:
Save a new domain application on form submission
_Outcome_: On "save" press, save any form changes to the Application model. 

Relies on #221 


Discussion:
11/8 - working on this today, touched base with Igor today

Resolving patch:
diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py
--- a/src/registrar/forms/application_wizard.py
+++ b/src/registrar/forms/application_wizard.py
@@ -3,11 +3,14 @@
 import logging
 
 from django import forms
+from django.shortcuts import redirect
 
 from django.contrib.auth.mixins import LoginRequiredMixin
 
 from formtools.wizard.views import NamedUrlSessionWizardView  # type: ignore
 
+from registrar.models import DomainApplication, Website
+
 
 logger = logging.getLogger(__name__)
 
@@ -113,5 +116,33 @@ def get_context_data(self, form, **kwargs):
         context["form_titles"] = TITLES
         return context
 
-    def done(self, form_list, **kwargs):
-        logger.info("Application form submitted.")
+    def forms_to_object(self, form_dict: dict) -> DomainApplication:
+        """Unpack the form responses onto the model object properties."""
+        application = DomainApplication.objects.create(creator=self.request.user)
+
+        # organization information
+        organization_data = form_dict["organization"].cleaned_data
+        application.organization_type = organization_data["organization_type"]
+        application.federal_branch = organization_data["federal_type"]
+        application.is_election_office = organization_data["is_election_board"]
+
+        # contact information
+        contact_data = form_dict["contact"].cleaned_data
+        application.organization_name = contact_data["organization_name"]
+        application.street_address = contact_data["street_address"]
+        # TODO: add the rest of these fields when they are created in the forms
+
+        # This isn't really the requested_domain field
+        # but we need something in this field to make the form submittable
+        requested_site, _ = Website.objects.get_or_create(
+            website=contact_data["organization_name"] + ".gov"
+        )
+        application.requested_domain = requested_site
+        return application
+
+    def done(self, form_list, form_dict, **kwargs):
+        application = self.forms_to_object(form_dict)
+        application.submit()  # change the status to submitted
+        application.save()
+        logger.debug("Application object saved:", application.id)
+        return redirect("home")


Test patch:
diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py
--- a/src/registrar/tests/test_views.py
+++ b/src/registrar/tests/test_views.py
@@ -94,3 +94,26 @@ def test_application_form_organization(self):
         result = page.form.submit().follow()
         # Got the next form page
         self.assertIn("contact information", result)
+
+    def test_application_form_submission(self):
+        """Can fill out the entire form and submit.
+
+        As we add additional form pages, we need to include them here to make
+        this test work.
+        """
+        page = self.app.get(reverse("application")).follow()
+        form = page.form
+        form["organization-organization_type"] = "Federal"
+        form["organization-federal_type"] = "Executive"
+        result = page.form.submit().follow()
+        # Got the next form page
+        contact_form = result.form
+        contact_form["contact-organization_name"] = "test"
+        contact_form["contact-street_address"] = "100 Main Street"
+        result = page.form.submit()
+        # final submission results in a redirect
+        self.assertEquals(result.status_code, 302)
+        page = result.follow()
+        self.assertContains(page, "registrar")
+        # TODO: when we have a page that lists applications, visit it and
+        # make sure that the new one exists