We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Miscellaneous Design Tweaks to Registrar
- [ ] Style fine tuning on the form

- [ ] Fixing up some odd spacing and position

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/registrar/fixtures.py`
Content:
```
1 import logging
2 import random
3 from faker import Faker
4 
5 from registrar.models import (
6     User,
7     DomainApplication,
8     Domain,
9     Contact,
10     Website,
11 )
12 
13 fake = Faker()
14 logger = logging.getLogger(__name__)
15 
16 
17 class UserFixture:
18     """
19     Load users into the database.
20 
21     Make sure this class' `load` method is called from `handle`
22     in management/commands/load.py, then use `./manage.py load`
23     to run this code.
24     """
25 
26     ADMINS = [
27         {
28             "username": "c4a0e101-73b4-4d7d-9e5e-7f19a726a0fa",
29             "first_name": "Seamus",
30             "last_name": "Johnston",
31         },
32         {
33             "username": "d4c3bd84-dc3a-48bc-a3c3-f53111df2ec6",
34             "first_name": "Igor",
35             "last_name": "",
36         },
37         {
38             "username": "ee80bfe0-49ad-456d-8d82-e2b608a66517",
39             "first_name": "Logan",
40             "last_name": "",
41         },
42         {
43             "username": "2ffe71b0-cea4-4097-8fb6-7a35b901dd70",
44             "first_name": "Neil",
45             "last_name": "Martinsen-Burrell",
46         },
47     ]
48 
49     @classmethod
50     def load(cls):
51         logger.info("Going to load %s users" % str(len(cls.ADMINS)))
52         for admin in cls.ADMINS:
53             try:
54                 user, _ = User.objects.get_or_create(
55                     username=admin["username"],
56                 )
57                 user.is_superuser = True
58                 user.first_name = admin["first_name"]
59                 user.last_name = admin["last_name"]
60                 user.is_staff = True
61                 user.is_active = True
62                 user.save()
63                 logger.debug("User object created for %s" % admin["first_name"])
64             except Exception as e:
65                 logger.warning(e)
66         logger.debug("All users loaded.")
67 
68 
69 class DomainApplicationFixture:
70     """
71     Load domain applications into the database.
72 
73     Make sure this class' `load` method is called from `handle`
74     in management/commands/load.py, then use `./manage.py load`
75     to run this code.
76     """
77 
78     # any fields not specified here will be filled in with fake data or defaults
79     # NOTE BENE: each fixture must have `organization_name` for uniqueness!
80     # Here is a more complete example as a template:
81     # {
82     #     "status": "started",
83     #     "organization_name": "Example - Just started",
84     #     "organization_type": "federal",
85     #     "federal_agency": None,
86     #     "federal_type": None,
87     #     "address_line1": None,
88     #     "address_line2": None,
89     #     "city": None,
90     #     "state_territory": None,
91     #     "zipcode": None,
92     #     "urbanization": None,
93     #     "purpose": None,
94     #     "anything_else": None,
95     #     "is_policy_acknowledged": None,
96     #     "authorizing_official": None,
97     #     "submitter": None,
98     #     "other_contacts": [],
99     #     "current_websites": [],
100     #     "alternative_domains": [],
101     # },
102     DA = [
103         {
104             "status": "started",
105             "organization_name": "Example - Finished but not Submitted",
106         },
107         {
108             "status": "submitted",
109             "organization_name": "Example - Submitted but pending Investigation",
110         },
111         {
112             "status": "investigating",
113             "organization_name": "Example - In Investigation",
114         },
115         {
116             "status": "investigating",
117             "organization_name": "Example - Approved",
118         },
119     ]
120 
121     @classmethod
122     def fake_contact(cls):
123         return {
124             "first_name": fake.first_name(),
125             "middle_name": None,
126             "last_name": fake.last_name(),
127             "title": fake.job(),
128             "email": fake.ascii_safe_email(),
129             "phone": "201-555-5555",
130         }
131 
132     @classmethod
133     def fake_dot_gov(cls):
134         return f"{fake.slug()}.gov"
135 
136     @classmethod
137     def _set_non_foreign_key_fields(cls, da: DomainApplication, app: dict):
138         """Helper method used by `load`."""
139         da.status = app["status"] if "status" in app else "started"
140         da.organization_type = (
141             app["organization_type"] if "organization_type" in app else "federal"
142         )
143         da.federal_agency = app["federal_agency"] if "federal_agency" in app else ""
144         da.federal_type = (
145             app["federal_type"]
146             if "federal_type" in app
147             else random.choice(["executive", "judicial", "legislative"])  # nosec
148         )
149         da.address_line1 = (
150             app["address_line1"] if "address_line1" in app else fake.street_address()
151         )
152         da.address_line2 = app["address_line2"] if "address_line2" in app else None
153         da.city = app["city"] if "city" in app else fake.city()
154         da.state_territory = (
155             app["state_territory"] if "state_territory" in app else fake.state_abbr()
156         )
157         da.zipcode = app["zipcode"] if "zipcode" in app else fake.postalcode()
158         da.urbanization = app["urbanization"] if "urbanization" in app else None
159         da.purpose = app["purpose"] if "purpose" in app else fake.paragraph()
160         da.anything_else = app["anything_else"] if "anything_else" in app else None
161         da.is_policy_acknowledged = (
162             app["is_policy_acknowledged"] if "is_policy_acknowledged" in app else True
163         )
164 
165     @classmethod
166     def _set_foreign_key_fields(cls, da: DomainApplication, app: dict, user: User):
167         """Helper method used by `load`."""
168         if not da.investigator:
169             da.investigator = (
170                 User.objects.get(username=user.username)
171                 if "investigator" in app
172                 else None
173             )
174 
175         if not da.authorizing_official:
176             if (
177                 "authorizing_official" in app
178                 and app["authorizing_official"] is not None
179             ):
180                 da.authorizing_official, _ = Contact.objects.get_or_create(
181                     **app["authorizing_official"]
182                 )
183             else:
184                 da.authorizing_official = Contact.objects.create(**cls.fake_contact())
185 
186         if not da.submitter:
187             if "submitter" in app and app["submitter"] is not None:
188                 da.submitter, _ = Contact.objects.get_or_create(**app["submitter"])
189             else:
190                 da.submitter = Contact.objects.create(**cls.fake_contact())
191 
192         if not da.requested_domain:
193             if "requested_domain" in app and app["requested_domain"] is not None:
194                 da.requested_domain, _ = Domain.objects.get_or_create(
195                     name=app["requested_domain"]
196                 )
197             else:
198                 da.requested_domain = Domain.objects.create(name=cls.fake_dot_gov())
199 
200     @classmethod
201     def _set_many_to_many_relations(cls, da: DomainApplication, app: dict):
202         """Helper method used by `load`."""
203         if "other_contacts" in app:
204             for contact in app["other_contacts"]:
205                 da.other_contacts.add(Contact.objects.get_or_create(**contact)[0])
206         elif not da.other_contacts.exists():
207             other_contacts = [
208                 Contact.objects.create(**cls.fake_contact())
209                 for _ in range(random.randint(0, 3))  # nosec
210             ]
211             da.other_contacts.add(*other_contacts)
212 
213         if "current_websites" in app:
214             for website in app["current_websites"]:
215                 da.current_websites.add(
216                     Website.objects.get_or_create(website=website)[0]
217                 )
218         elif not da.current_websites.exists():
219             current_websites = [
220                 Website.objects.create(website=fake.uri())
221                 for _ in range(random.randint(0, 3))  # nosec
222             ]
223             da.current_websites.add(*current_websites)
224 
225         if "alternative_domains" in app:
226             for domain in app["alternative_domains"]:
227                 da.alternative_domains.add(
228                     Website.objects.get_or_create(website=domain)[0]
229                 )
230         elif not da.alternative_domains.exists():
231             alternative_domains = [
232                 Website.objects.create(website=cls.fake_dot_gov())
233                 for _ in range(random.randint(0, 3))  # nosec
234             ]
235             da.alternative_domains.add(*alternative_domains)
236 
237     @classmethod
238     def load(cls):
239         """Creates domain applications for each user in the database."""
240         logger.info("Going to load %s domain applications" % len(cls.DA))
241         try:
242             users = list(User.objects.all())  # force evaluation to catch db errors
243         except Exception as e:
244             logger.warning(e)
245             return
246 
247         for user in users:
248             logger.debug("Loading domain applications for %s" % user)
249             for app in cls.DA:
250                 try:
251                     da, _ = DomainApplication.objects.get_or_create(
252                         creator=user,
253                         organization_name=app["organization_name"],
254                     )
255                     cls._set_non_foreign_key_fields(da, app)
256                     cls._set_foreign_key_fields(da, app, user)
257                     da.save()
258                     cls._set_many_to_many_relations(da, app)
259                 except Exception as e:
260                     logger.warning(e)
261 
262 
263 class DomainFixture(DomainApplicationFixture):
264 
265     """Create one domain and permissions on it for each user."""
266 
267     @classmethod
268     def load(cls):
269         try:
270             users = list(User.objects.all())  # force evaluation to catch db errors
271         except Exception as e:
272             logger.warning(e)
273             return
274 
275         for user in users:
276             # approve one of each users investigating status domains
277             application = DomainApplication.objects.filter(
278                 creator=user, status=DomainApplication.INVESTIGATING
279             ).last()
280             logger.debug(f"Approving {application} for {user}")
281             application.approve()
282             application.save()
283
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/registrar/fixtures.py b/src/registrar/fixtures.py
--- a/src/registrar/fixtures.py
+++ b/src/registrar/fixtures.py
@@ -140,7 +140,13 @@
         da.organization_type = (
             app["organization_type"] if "organization_type" in app else "federal"
         )
-        da.federal_agency = app["federal_agency"] if "federal_agency" in app else ""
+        da.federal_agency = (
+            app["federal_agency"]
+            if "federal_agency" in app
+            # Random choice of agency for selects, used as placeholders for testing.
+            else random.choice(DomainApplication.AGENCIES)  # nosec
+        )
+
         da.federal_type = (
             app["federal_type"]
             if "federal_type" in app

{"golden_diff": "diff --git a/src/registrar/fixtures.py b/src/registrar/fixtures.py\n--- a/src/registrar/fixtures.py\n+++ b/src/registrar/fixtures.py\n@@ -140,7 +140,13 @@\n         da.organization_type = (\n             app[\"organization_type\"] if \"organization_type\" in app else \"federal\"\n         )\n-        da.federal_agency = app[\"federal_agency\"] if \"federal_agency\" in app else \"\"\n+        da.federal_agency = (\n+            app[\"federal_agency\"]\n+            if \"federal_agency\" in app\n+            # Random choice of agency for selects, used as placeholders for testing.\n+            else random.choice(DomainApplication.AGENCIES)  # nosec\n+        )\n+\n         da.federal_type = (\n             app[\"federal_type\"]\n             if \"federal_type\" in app\n", "issue": "Miscellaneous Design Tweaks to Registrar\n- [ ] Style fine tuning on the form\n\n- [ ] Fixing up some odd spacing and position\n", "before_files": [{"content": "import logging\nimport random\nfrom faker import Faker\n\nfrom registrar.models import (\n    User,\n    DomainApplication,\n    Domain,\n    Contact,\n    Website,\n)\n\nfake = Faker()\nlogger = logging.getLogger(__name__)\n\n\nclass UserFixture:\n    \"\"\"\n    Load users into the database.\n\n    Make sure this class' `load` method is called from `handle`\n    in management/commands/load.py, then use `./manage.py load`\n    to run this code.\n    \"\"\"\n\n    ADMINS = [\n        {\n            \"username\": \"c4a0e101-73b4-4d7d-9e5e-7f19a726a0fa\",\n            \"first_name\": \"Seamus\",\n            \"last_name\": \"Johnston\",\n        },\n        {\n            \"username\": \"d4c3bd84-dc3a-48bc-a3c3-f53111df2ec6\",\n            \"first_name\": \"Igor\",\n            \"last_name\": \"\",\n        },\n        {\n            \"username\": \"ee80bfe0-49ad-456d-8d82-e2b608a66517\",\n            \"first_name\": \"Logan\",\n            \"last_name\": \"\",\n        },\n        {\n            \"username\": \"2ffe71b0-cea4-4097-8fb6-7a35b901dd70\",\n            \"first_name\": \"Neil\",\n            \"last_name\": \"Martinsen-Burrell\",\n        },\n    ]\n\n    @classmethod\n    def load(cls):\n        logger.info(\"Going to load %s users\" % str(len(cls.ADMINS)))\n        for admin in cls.ADMINS:\n            try:\n                user, _ = User.objects.get_or_create(\n                    username=admin[\"username\"],\n                )\n                user.is_superuser = True\n                user.first_name = admin[\"first_name\"]\n                user.last_name = admin[\"last_name\"]\n                user.is_staff = True\n                user.is_active = True\n                user.save()\n                logger.debug(\"User object created for %s\" % admin[\"first_name\"])\n            except Exception as e:\n                logger.warning(e)\n        logger.debug(\"All users loaded.\")\n\n\nclass DomainApplicationFixture:\n    \"\"\"\n    Load domain applications into the database.\n\n    Make sure this class' `load` method is called from `handle`\n    in management/commands/load.py, then use `./manage.py load`\n    to run this code.\n    \"\"\"\n\n    # any fields not specified here will be filled in with fake data or defaults\n    # NOTE BENE: each fixture must have `organization_name` for uniqueness!\n    # Here is a more complete example as a template:\n    # {\n    #     \"status\": \"started\",\n    #     \"organization_name\": \"Example - Just started\",\n    #     \"organization_type\": \"federal\",\n    #     \"federal_agency\": None,\n    #     \"federal_type\": None,\n    #     \"address_line1\": None,\n    #     \"address_line2\": None,\n    #     \"city\": None,\n    #     \"state_territory\": None,\n    #     \"zipcode\": None,\n    #     \"urbanization\": None,\n    #     \"purpose\": None,\n    #     \"anything_else\": None,\n    #     \"is_policy_acknowledged\": None,\n    #     \"authorizing_official\": None,\n    #     \"submitter\": None,\n    #     \"other_contacts\": [],\n    #     \"current_websites\": [],\n    #     \"alternative_domains\": [],\n    # },\n    DA = [\n        {\n            \"status\": \"started\",\n            \"organization_name\": \"Example - Finished but not Submitted\",\n        },\n        {\n            \"status\": \"submitted\",\n            \"organization_name\": \"Example - Submitted but pending Investigation\",\n        },\n        {\n            \"status\": \"investigating\",\n            \"organization_name\": \"Example - In Investigation\",\n        },\n        {\n            \"status\": \"investigating\",\n            \"organization_name\": \"Example - Approved\",\n        },\n    ]\n\n    @classmethod\n    def fake_contact(cls):\n        return {\n            \"first_name\": fake.first_name(),\n            \"middle_name\": None,\n            \"last_name\": fake.last_name(),\n            \"title\": fake.job(),\n            \"email\": fake.ascii_safe_email(),\n            \"phone\": \"201-555-5555\",\n        }\n\n    @classmethod\n    def fake_dot_gov(cls):\n        return f\"{fake.slug()}.gov\"\n\n    @classmethod\n    def _set_non_foreign_key_fields(cls, da: DomainApplication, app: dict):\n        \"\"\"Helper method used by `load`.\"\"\"\n        da.status = app[\"status\"] if \"status\" in app else \"started\"\n        da.organization_type = (\n            app[\"organization_type\"] if \"organization_type\" in app else \"federal\"\n        )\n        da.federal_agency = app[\"federal_agency\"] if \"federal_agency\" in app else \"\"\n        da.federal_type = (\n            app[\"federal_type\"]\n            if \"federal_type\" in app\n            else random.choice([\"executive\", \"judicial\", \"legislative\"])  # nosec\n        )\n        da.address_line1 = (\n            app[\"address_line1\"] if \"address_line1\" in app else fake.street_address()\n        )\n        da.address_line2 = app[\"address_line2\"] if \"address_line2\" in app else None\n        da.city = app[\"city\"] if \"city\" in app else fake.city()\n        da.state_territory = (\n            app[\"state_territory\"] if \"state_territory\" in app else fake.state_abbr()\n        )\n        da.zipcode = app[\"zipcode\"] if \"zipcode\" in app else fake.postalcode()\n        da.urbanization = app[\"urbanization\"] if \"urbanization\" in app else None\n        da.purpose = app[\"purpose\"] if \"purpose\" in app else fake.paragraph()\n        da.anything_else = app[\"anything_else\"] if \"anything_else\" in app else None\n        da.is_policy_acknowledged = (\n            app[\"is_policy_acknowledged\"] if \"is_policy_acknowledged\" in app else True\n        )\n\n    @classmethod\n    def _set_foreign_key_fields(cls, da: DomainApplication, app: dict, user: User):\n        \"\"\"Helper method used by `load`.\"\"\"\n        if not da.investigator:\n            da.investigator = (\n                User.objects.get(username=user.username)\n                if \"investigator\" in app\n                else None\n            )\n\n        if not da.authorizing_official:\n            if (\n                \"authorizing_official\" in app\n                and app[\"authorizing_official\"] is not None\n            ):\n                da.authorizing_official, _ = Contact.objects.get_or_create(\n                    **app[\"authorizing_official\"]\n                )\n            else:\n                da.authorizing_official = Contact.objects.create(**cls.fake_contact())\n\n        if not da.submitter:\n            if \"submitter\" in app and app[\"submitter\"] is not None:\n                da.submitter, _ = Contact.objects.get_or_create(**app[\"submitter\"])\n            else:\n                da.submitter = Contact.objects.create(**cls.fake_contact())\n\n        if not da.requested_domain:\n            if \"requested_domain\" in app and app[\"requested_domain\"] is not None:\n                da.requested_domain, _ = Domain.objects.get_or_create(\n                    name=app[\"requested_domain\"]\n                )\n            else:\n                da.requested_domain = Domain.objects.create(name=cls.fake_dot_gov())\n\n    @classmethod\n    def _set_many_to_many_relations(cls, da: DomainApplication, app: dict):\n        \"\"\"Helper method used by `load`.\"\"\"\n        if \"other_contacts\" in app:\n            for contact in app[\"other_contacts\"]:\n                da.other_contacts.add(Contact.objects.get_or_create(**contact)[0])\n        elif not da.other_contacts.exists():\n            other_contacts = [\n                Contact.objects.create(**cls.fake_contact())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.other_contacts.add(*other_contacts)\n\n        if \"current_websites\" in app:\n            for website in app[\"current_websites\"]:\n                da.current_websites.add(\n                    Website.objects.get_or_create(website=website)[0]\n                )\n        elif not da.current_websites.exists():\n            current_websites = [\n                Website.objects.create(website=fake.uri())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.current_websites.add(*current_websites)\n\n        if \"alternative_domains\" in app:\n            for domain in app[\"alternative_domains\"]:\n                da.alternative_domains.add(\n                    Website.objects.get_or_create(website=domain)[0]\n                )\n        elif not da.alternative_domains.exists():\n            alternative_domains = [\n                Website.objects.create(website=cls.fake_dot_gov())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.alternative_domains.add(*alternative_domains)\n\n    @classmethod\n    def load(cls):\n        \"\"\"Creates domain applications for each user in the database.\"\"\"\n        logger.info(\"Going to load %s domain applications\" % len(cls.DA))\n        try:\n            users = list(User.objects.all())  # force evaluation to catch db errors\n        except Exception as e:\n            logger.warning(e)\n            return\n\n        for user in users:\n            logger.debug(\"Loading domain applications for %s\" % user)\n            for app in cls.DA:\n                try:\n                    da, _ = DomainApplication.objects.get_or_create(\n                        creator=user,\n                        organization_name=app[\"organization_name\"],\n                    )\n                    cls._set_non_foreign_key_fields(da, app)\n                    cls._set_foreign_key_fields(da, app, user)\n                    da.save()\n                    cls._set_many_to_many_relations(da, app)\n                except Exception as e:\n                    logger.warning(e)\n\n\nclass DomainFixture(DomainApplicationFixture):\n\n    \"\"\"Create one domain and permissions on it for each user.\"\"\"\n\n    @classmethod\n    def load(cls):\n        try:\n            users = list(User.objects.all())  # force evaluation to catch db errors\n        except Exception as e:\n            logger.warning(e)\n            return\n\n        for user in users:\n            # approve one of each users investigating status domains\n            application = DomainApplication.objects.filter(\n                creator=user, status=DomainApplication.INVESTIGATING\n            ).last()\n            logger.debug(f\"Approving {application} for {user}\")\n            application.approve()\n            application.save()\n", "path": "src/registrar/fixtures.py"}], "after_files": [{"content": "import logging\nimport random\nfrom faker import Faker\n\nfrom registrar.models import (\n    User,\n    DomainApplication,\n    Domain,\n    Contact,\n    Website,\n)\n\nfake = Faker()\nlogger = logging.getLogger(__name__)\n\n\nclass UserFixture:\n    \"\"\"\n    Load users into the database.\n\n    Make sure this class' `load` method is called from `handle`\n    in management/commands/load.py, then use `./manage.py load`\n    to run this code.\n    \"\"\"\n\n    ADMINS = [\n        {\n            \"username\": \"c4a0e101-73b4-4d7d-9e5e-7f19a726a0fa\",\n            \"first_name\": \"Seamus\",\n            \"last_name\": \"Johnston\",\n        },\n        {\n            \"username\": \"d4c3bd84-dc3a-48bc-a3c3-f53111df2ec6\",\n            \"first_name\": \"Igor\",\n            \"last_name\": \"\",\n        },\n        {\n            \"username\": \"ee80bfe0-49ad-456d-8d82-e2b608a66517\",\n            \"first_name\": \"Logan\",\n            \"last_name\": \"\",\n        },\n        {\n            \"username\": \"2ffe71b0-cea4-4097-8fb6-7a35b901dd70\",\n            \"first_name\": \"Neil\",\n            \"last_name\": \"Martinsen-Burrell\",\n        },\n    ]\n\n    @classmethod\n    def load(cls):\n        logger.info(\"Going to load %s users\" % str(len(cls.ADMINS)))\n        for admin in cls.ADMINS:\n            try:\n                user, _ = User.objects.get_or_create(\n                    username=admin[\"username\"],\n                )\n                user.is_superuser = True\n                user.first_name = admin[\"first_name\"]\n                user.last_name = admin[\"last_name\"]\n                user.is_staff = True\n                user.is_active = True\n                user.save()\n                logger.debug(\"User object created for %s\" % admin[\"first_name\"])\n            except Exception as e:\n                logger.warning(e)\n        logger.debug(\"All users loaded.\")\n\n\nclass DomainApplicationFixture:\n    \"\"\"\n    Load domain applications into the database.\n\n    Make sure this class' `load` method is called from `handle`\n    in management/commands/load.py, then use `./manage.py load`\n    to run this code.\n    \"\"\"\n\n    # any fields not specified here will be filled in with fake data or defaults\n    # NOTE BENE: each fixture must have `organization_name` for uniqueness!\n    # Here is a more complete example as a template:\n    # {\n    #     \"status\": \"started\",\n    #     \"organization_name\": \"Example - Just started\",\n    #     \"organization_type\": \"federal\",\n    #     \"federal_agency\": None,\n    #     \"federal_type\": None,\n    #     \"address_line1\": None,\n    #     \"address_line2\": None,\n    #     \"city\": None,\n    #     \"state_territory\": None,\n    #     \"zipcode\": None,\n    #     \"urbanization\": None,\n    #     \"purpose\": None,\n    #     \"anything_else\": None,\n    #     \"is_policy_acknowledged\": None,\n    #     \"authorizing_official\": None,\n    #     \"submitter\": None,\n    #     \"other_contacts\": [],\n    #     \"current_websites\": [],\n    #     \"alternative_domains\": [],\n    # },\n    DA = [\n        {\n            \"status\": \"started\",\n            \"organization_name\": \"Example - Finished but not Submitted\",\n        },\n        {\n            \"status\": \"submitted\",\n            \"organization_name\": \"Example - Submitted but pending Investigation\",\n        },\n        {\n            \"status\": \"investigating\",\n            \"organization_name\": \"Example - In Investigation\",\n        },\n        {\n            \"status\": \"investigating\",\n            \"organization_name\": \"Example - Approved\",\n        },\n    ]\n\n    @classmethod\n    def fake_contact(cls):\n        return {\n            \"first_name\": fake.first_name(),\n            \"middle_name\": None,\n            \"last_name\": fake.last_name(),\n            \"title\": fake.job(),\n            \"email\": fake.ascii_safe_email(),\n            \"phone\": \"201-555-5555\",\n        }\n\n    @classmethod\n    def fake_dot_gov(cls):\n        return f\"{fake.slug()}.gov\"\n\n    @classmethod\n    def _set_non_foreign_key_fields(cls, da: DomainApplication, app: dict):\n        \"\"\"Helper method used by `load`.\"\"\"\n        da.status = app[\"status\"] if \"status\" in app else \"started\"\n        da.organization_type = (\n            app[\"organization_type\"] if \"organization_type\" in app else \"federal\"\n        )\n        da.federal_agency = (\n            app[\"federal_agency\"]\n            if \"federal_agency\" in app\n            # Random choice of agency for selects, used as placeholders for testing.\n            else random.choice(DomainApplication.AGENCIES)  # nosec\n        )\n\n        da.federal_type = (\n            app[\"federal_type\"]\n            if \"federal_type\" in app\n            else random.choice([\"executive\", \"judicial\", \"legislative\"])  # nosec\n        )\n        da.address_line1 = (\n            app[\"address_line1\"] if \"address_line1\" in app else fake.street_address()\n        )\n        da.address_line2 = app[\"address_line2\"] if \"address_line2\" in app else None\n        da.city = app[\"city\"] if \"city\" in app else fake.city()\n        da.state_territory = (\n            app[\"state_territory\"] if \"state_territory\" in app else fake.state_abbr()\n        )\n        da.zipcode = app[\"zipcode\"] if \"zipcode\" in app else fake.postalcode()\n        da.urbanization = app[\"urbanization\"] if \"urbanization\" in app else None\n        da.purpose = app[\"purpose\"] if \"purpose\" in app else fake.paragraph()\n        da.anything_else = app[\"anything_else\"] if \"anything_else\" in app else None\n        da.is_policy_acknowledged = (\n            app[\"is_policy_acknowledged\"] if \"is_policy_acknowledged\" in app else True\n        )\n\n    @classmethod\n    def _set_foreign_key_fields(cls, da: DomainApplication, app: dict, user: User):\n        \"\"\"Helper method used by `load`.\"\"\"\n        if not da.investigator:\n            da.investigator = (\n                User.objects.get(username=user.username)\n                if \"investigator\" in app\n                else None\n            )\n\n        if not da.authorizing_official:\n            if (\n                \"authorizing_official\" in app\n                and app[\"authorizing_official\"] is not None\n            ):\n                da.authorizing_official, _ = Contact.objects.get_or_create(\n                    **app[\"authorizing_official\"]\n                )\n            else:\n                da.authorizing_official = Contact.objects.create(**cls.fake_contact())\n\n        if not da.submitter:\n            if \"submitter\" in app and app[\"submitter\"] is not None:\n                da.submitter, _ = Contact.objects.get_or_create(**app[\"submitter\"])\n            else:\n                da.submitter = Contact.objects.create(**cls.fake_contact())\n\n        if not da.requested_domain:\n            if \"requested_domain\" in app and app[\"requested_domain\"] is not None:\n                da.requested_domain, _ = Domain.objects.get_or_create(\n                    name=app[\"requested_domain\"]\n                )\n            else:\n                da.requested_domain = Domain.objects.create(name=cls.fake_dot_gov())\n\n    @classmethod\n    def _set_many_to_many_relations(cls, da: DomainApplication, app: dict):\n        \"\"\"Helper method used by `load`.\"\"\"\n        if \"other_contacts\" in app:\n            for contact in app[\"other_contacts\"]:\n                da.other_contacts.add(Contact.objects.get_or_create(**contact)[0])\n        elif not da.other_contacts.exists():\n            other_contacts = [\n                Contact.objects.create(**cls.fake_contact())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.other_contacts.add(*other_contacts)\n\n        if \"current_websites\" in app:\n            for website in app[\"current_websites\"]:\n                da.current_websites.add(\n                    Website.objects.get_or_create(website=website)[0]\n                )\n        elif not da.current_websites.exists():\n            current_websites = [\n                Website.objects.create(website=fake.uri())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.current_websites.add(*current_websites)\n\n        if \"alternative_domains\" in app:\n            for domain in app[\"alternative_domains\"]:\n                da.alternative_domains.add(\n                    Website.objects.get_or_create(website=domain)[0]\n                )\n        elif not da.alternative_domains.exists():\n            alternative_domains = [\n                Website.objects.create(website=cls.fake_dot_gov())\n                for _ in range(random.randint(0, 3))  # nosec\n            ]\n            da.alternative_domains.add(*alternative_domains)\n\n    @classmethod\n    def load(cls):\n        \"\"\"Creates domain applications for each user in the database.\"\"\"\n        logger.info(\"Going to load %s domain applications\" % len(cls.DA))\n        try:\n            users = list(User.objects.all())  # force evaluation to catch db errors\n        except Exception as e:\n            logger.warning(e)\n            return\n\n        for user in users:\n            logger.debug(\"Loading domain applications for %s\" % user)\n            for app in cls.DA:\n                try:\n                    da, _ = DomainApplication.objects.get_or_create(\n                        creator=user,\n                        organization_name=app[\"organization_name\"],\n                    )\n                    cls._set_non_foreign_key_fields(da, app)\n                    cls._set_foreign_key_fields(da, app, user)\n                    da.save()\n                    cls._set_many_to_many_relations(da, app)\n                except Exception as e:\n                    logger.warning(e)\n\n\nclass DomainFixture(DomainApplicationFixture):\n\n    \"\"\"Create one domain and permissions on it for each user.\"\"\"\n\n    @classmethod\n    def load(cls):\n        try:\n            users = list(User.objects.all())  # force evaluation to catch db errors\n        except Exception as e:\n            logger.warning(e)\n            return\n\n        for user in users:\n            # approve one of each users investigating status domains\n            application = DomainApplication.objects.filter(\n                creator=user, status=DomainApplication.INVESTIGATING\n            ).last()\n            logger.debug(f\"Approving {application} for {user}\")\n            application.approve()\n            application.save()\n", "path": "src/registrar/fixtures.py"}]}