Format code

This commit is contained in:
Christopher C. Wells 2023-02-07 20:29:15 -08:00 committed by Christopher Charbonneau Wells
parent 94bc12973a
commit 90e16431b8
8 changed files with 47 additions and 16 deletions

View File

@ -227,7 +227,10 @@ class TimerSerializer(CoreModelSerializer):
required=False, required=False,
) )
user = serializers.PrimaryKeyRelatedField( user = serializers.PrimaryKeyRelatedField(
allow_null=True, allow_empty=True, queryset=get_user_model().objects.all(), required=False allow_null=True,
allow_empty=True,
queryset=get_user_model().objects.all(),
required=False,
) )
class Meta: class Meta:

View File

@ -11,7 +11,9 @@ class Command(migrate.Command):
superusers = get_user_model().objects.filter(is_superuser=True) superusers = get_user_model().objects.filter(is_superuser=True)
if len(superusers) == 0: if len(superusers) == 0:
default_user = get_user_model().objects.create_user("admin", password="admin") default_user = get_user_model().objects.create_user(
"admin", password="admin"
)
default_user.is_superuser = True default_user.is_superuser = True
default_user.is_staff = True default_user.is_staff = True
default_user.save() default_user.save()

View File

@ -9,7 +9,9 @@ from core.models import Child
class CommandsTestCase(TransactionTestCase): class CommandsTestCase(TransactionTestCase):
def test_migrate(self): def test_migrate(self):
call_command("migrate", verbosity=0) call_command("migrate", verbosity=0)
self.assertIsInstance(get_user_model().objects.get(username="admin"), get_user_model()) self.assertIsInstance(
get_user_model().objects.get(username="admin"), get_user_model()
)
def test_fake(self): def test_fake(self):
call_command("migrate", verbosity=0) call_command("migrate", verbosity=0)
@ -20,7 +22,9 @@ class CommandsTestCase(TransactionTestCase):
def test_reset(self): def test_reset(self):
call_command("reset", verbosity=0, interactive=False) call_command("reset", verbosity=0, interactive=False)
self.assertIsInstance(get_user_model().objects.get(username="admin"), get_user_model()) self.assertIsInstance(
get_user_model().objects.get(username="admin"), get_user_model()
)
self.assertEqual(Child.objects.count(), 1) self.assertEqual(Child.objects.count(), 1)
def test_createuser(self): def test_createuser(self):
@ -31,9 +35,13 @@ class CommandsTestCase(TransactionTestCase):
password="test", password="test",
verbosity=0, verbosity=0,
) )
self.assertIsInstance(get_user_model().objects.get(username="test"), get_user_model()) self.assertIsInstance(
get_user_model().objects.get(username="test"), get_user_model()
)
self.assertFalse( self.assertFalse(
get_user_model().objects.filter(username="test", is_staff=True, is_superuser=True) get_user_model().objects.filter(
username="test", is_staff=True, is_superuser=True
)
) )
call_command( call_command(
"createuser", "createuser",
@ -43,7 +51,11 @@ class CommandsTestCase(TransactionTestCase):
password="test", password="test",
verbosity=0, verbosity=0,
) )
self.assertIsInstance(get_user_model().objects.get(username="testadmin"), get_user_model()) self.assertIsInstance(
self.assertTrue( get_user_model().objects.get(username="testadmin"), get_user_model()
get_user_model().objects.filter(username="testadmin", is_staff=True, is_superuser=True) )
self.assertTrue(
get_user_model().objects.filter(
username="testadmin", is_staff=True, is_superuser=True
)
) )

View File

@ -24,7 +24,9 @@ class FormsTestCase(TestCase):
"username": fake_user["username"], "username": fake_user["username"],
"password": fake.password(), "password": fake.password(),
} }
cls.user = get_user_model().objects.create_user(is_superuser=True, **cls.credentials) cls.user = get_user_model().objects.create_user(
is_superuser=True, **cls.credentials
)
cls.settings_template = { cls.settings_template = {
"first_name": "User", "first_name": "User",
@ -95,7 +97,9 @@ class FormsTestCase(TestCase):
page = self.c.post("/users/{}/delete/".format(new_user.id)) page = self.c.post("/users/{}/delete/".format(new_user.id))
self.assertEqual(page.status_code, 302) self.assertEqual(page.status_code, 302)
self.assertQuerysetEqual(get_user_model().objects.filter(username="username"), []) self.assertQuerysetEqual(
get_user_model().objects.filter(username="username"), []
)
def test_user_settings(self): def test_user_settings(self):
self.c.login(**self.credentials) self.c.login(**self.credentials)
@ -110,7 +114,9 @@ class FormsTestCase(TestCase):
def test_user_regenerate_api_key(self): def test_user_regenerate_api_key(self):
self.c.login(**self.credentials) self.c.login(**self.credentials)
api_key_before = get_user_model().objects.get(pk=self.user.id).settings.api_key() api_key_before = (
get_user_model().objects.get(pk=self.user.id).settings.api_key()
)
params = self.settings_template.copy() params = self.settings_template.copy()
params["api_key_regenerate"] = "Regenerate" params["api_key_regenerate"] = "Regenerate"

View File

@ -26,7 +26,9 @@ class FormsTestCaseBase(TestCase):
fake_user = fake.simple_profile() fake_user = fake.simple_profile()
credentials = {"username": fake_user["username"], "password": fake.password()} credentials = {"username": fake_user["username"], "password": fake.password()}
cls.user = get_user_model().objects.create_user(is_superuser=True, **credentials) cls.user = get_user_model().objects.create_user(
is_superuser=True, **credentials
)
cls.c.login(**credentials) cls.c.login(**credentials)
cls.child = models.Child.objects.create( cls.child = models.Child.objects.create(

View File

@ -25,7 +25,9 @@ class ViewsTestCase(TestCase):
"username": fake_user["username"], "username": fake_user["username"],
"password": fake.password(), "password": fake.password(),
} }
cls.user = get_user_model().objects.create_user(is_superuser=True, **cls.credentials) cls.user = get_user_model().objects.create_user(
is_superuser=True, **cls.credentials
)
cls.c.login(**cls.credentials) cls.c.login(**cls.credentials)

View File

@ -23,7 +23,9 @@ class ViewsTestCase(TestCase):
"username": fake_user["username"], "username": fake_user["username"],
"password": fake.password(), "password": fake.password(),
} }
cls.user = get_user_model().objects.create_user(is_superuser=True, **cls.credentials) cls.user = get_user_model().objects.create_user(
is_superuser=True, **cls.credentials
)
cls.c.login(**cls.credentials) cls.c.login(**cls.credentials)

View File

@ -24,7 +24,9 @@ class ViewsTestCase(TestCase):
"username": fake_user["username"], "username": fake_user["username"],
"password": fake.password(), "password": fake.password(),
} }
cls.user = get_user_model().objects.create_user(is_superuser=True, **cls.credentials) cls.user = get_user_model().objects.create_user(
is_superuser=True, **cls.credentials
)
cls.c.login(**cls.credentials) cls.c.login(**cls.credentials)