3
0
Fork 0

fix: format all code with black

and from now on should not deviate from that...
This commit is contained in:
Lance Edgar 2025-08-31 12:26:43 -05:00
parent 8a09fb1a3c
commit 4d0693862d
68 changed files with 6693 additions and 5659 deletions

View file

@ -25,17 +25,17 @@ class TestWuttaDateTime(TestCase):
result = typ.deserialize(node, colander.null)
self.assertIs(result, colander.null)
result = typ.deserialize(node, '2024-12-11T10:33 PM')
result = typ.deserialize(node, "2024-12-11T10:33 PM")
self.assertIsInstance(result, datetime.datetime)
self.assertEqual(result, datetime.datetime(2024, 12, 11, 22, 33))
self.assertIsNone(result.tzinfo)
result = typ.deserialize(node, '2024-12-11T22:33:00')
result = typ.deserialize(node, "2024-12-11T22:33:00")
self.assertIsInstance(result, datetime.datetime)
self.assertEqual(result, datetime.datetime(2024, 12, 11, 22, 33))
self.assertIsNone(result.tzinfo)
self.assertRaises(colander.Invalid, typ.deserialize, node, 'bogus')
self.assertRaises(colander.Invalid, typ.deserialize, node, "bogus")
class TestObjectNode(DataTestCase):
@ -84,20 +84,24 @@ class TestWuttaEnum(WebTestCase):
MOCK_STATUS_ONE = 1
MOCK_STATUS_TWO = 2
MOCK_STATUS = {
MOCK_STATUS_ONE: 'one',
MOCK_STATUS_TWO: 'two',
MOCK_STATUS_ONE: "one",
MOCK_STATUS_TWO: "two",
}
class TestWuttaDictEnum(WebTestCase):
def test_widget_maker(self):
typ = mod.WuttaDictEnum(self.request, MOCK_STATUS)
widget = typ.widget_maker()
self.assertIsInstance(widget, widgets.SelectWidget)
self.assertEqual(widget.values, [
(1, 'one'),
(2, 'two'),
])
self.assertEqual(
widget.values,
[
(1, "one"),
(2, "two"),
],
)
class TestWuttaMoney(WebTestCase):
@ -132,13 +136,13 @@ class TestWuttaQuantity(WebTestCase):
# quantity
result = typ.serialize(node, 42)
self.assertEqual(result, '42')
self.assertEqual(result, "42")
result = typ.serialize(node, 42.00)
self.assertEqual(result, '42')
result = typ.serialize(node, decimal.Decimal('42.00'))
self.assertEqual(result, '42')
self.assertEqual(result, "42")
result = typ.serialize(node, decimal.Decimal("42.00"))
self.assertEqual(result, "42")
result = typ.serialize(node, 42.13)
self.assertEqual(result, '42.13')
self.assertEqual(result, "42.13")
class TestObjectRef(DataTestCase):
@ -155,19 +159,19 @@ class TestObjectRef(DataTestCase):
# passing true yields default empty option
typ = mod.ObjectRef(self.request, empty_option=True)
self.assertEqual(typ.empty_option, ('', "(none)"))
self.assertEqual(typ.empty_option, ("", "(none)"))
# can set explicitly
typ = mod.ObjectRef(self.request, empty_option=('foo', 'bar'))
self.assertEqual(typ.empty_option, ('foo', 'bar'))
typ = mod.ObjectRef(self.request, empty_option=("foo", "bar"))
self.assertEqual(typ.empty_option, ("foo", "bar"))
# can set just a label
typ = mod.ObjectRef(self.request, empty_option="(empty)")
self.assertEqual(typ.empty_option, ('', "(empty)"))
self.assertEqual(typ.empty_option, ("", "(empty)"))
def test_model_class(self):
typ = mod.ObjectRef(self.request)
self.assertRaises(NotImplementedError, getattr, typ, 'model_class')
self.assertRaises(NotImplementedError, getattr, typ, "model_class")
def test_serialize(self):
model = self.app.model
@ -188,9 +192,9 @@ class TestObjectRef(DataTestCase):
self.assertEqual(value, person.uuid.hex)
# null w/ empty option
typ = mod.ObjectRef(self.request, empty_option=('bad', 'BAD'))
typ = mod.ObjectRef(self.request, empty_option=("bad", "BAD"))
value = typ.serialize(node, colander.null)
self.assertEqual(value, 'bad')
self.assertEqual(value, "bad")
def test_deserialize(self):
model = self.app.model
@ -206,8 +210,8 @@ class TestObjectRef(DataTestCase):
self.session.add(person)
self.session.commit()
self.assertIsNotNone(person.uuid)
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.ObjectRef(self.request)
value = typ.deserialize(node, person.uuid)
self.assertIs(value, person)
@ -234,14 +238,14 @@ class TestObjectRef(DataTestCase):
value = typ.objectify(None)
self.assertIsNone(value)
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
# model instance
person = model.Person(full_name="Betty Boop")
self.session.add(person)
self.session.commit()
self.assertIsNotNone(person.uuid)
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
# can specify as uuid
typ = mod.ObjectRef(self.request)
@ -254,22 +258,22 @@ class TestObjectRef(DataTestCase):
self.assertIs(value, person)
# error if not found
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
typ = mod.ObjectRef(self.request)
self.assertRaises(ValueError, typ.objectify, 'WRONG-UUID')
self.assertRaises(ValueError, typ.objectify, "WRONG-UUID")
def test_get_query(self):
model = self.app.model
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.ObjectRef(self.request)
query = typ.get_query()
self.assertIsInstance(query, orm.Query)
def test_sort_query(self):
model = self.app.model
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.ObjectRef(self.request)
query = typ.get_query()
sorted_query = typ.sort_query(query)
@ -282,16 +286,16 @@ class TestObjectRef(DataTestCase):
self.session.commit()
# basic
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.ObjectRef(self.request)
widget = typ.widget_maker()
self.assertEqual(len(widget.values), 1)
self.assertEqual(widget.values[0][1], "Betty Boop")
# empty option
with patch.object(mod.ObjectRef, 'model_class', new=model.Person):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod.ObjectRef, "model_class", new=model.Person):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.ObjectRef(self.request, empty_option=True)
widget = typ.widget_maker()
self.assertEqual(len(widget.values), 2)
@ -302,7 +306,7 @@ class TestObjectRef(DataTestCase):
class TestPersonRef(WebTestCase):
def test_sort_query(self):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.PersonRef(self.request)
query = typ.get_query()
self.assertIsInstance(query, orm.Query)
@ -311,9 +315,9 @@ class TestPersonRef(WebTestCase):
self.assertIsNot(sorted_query, query)
def test_get_object_url(self):
self.pyramid_config.add_route('people.view', '/people/{uuid}')
self.pyramid_config.add_route("people.view", "/people/{uuid}")
model = self.app.model
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.PersonRef(self.request)
person = model.Person(full_name="Barney Rubble")
@ -322,13 +326,13 @@ class TestPersonRef(WebTestCase):
url = typ.get_object_url(person)
self.assertIsNotNone(url)
self.assertIn(f'/people/{person.uuid}', url)
self.assertIn(f"/people/{person.uuid}", url)
class TestRoleRef(WebTestCase):
def test_sort_query(self):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.RoleRef(self.request)
query = typ.get_query()
self.assertIsInstance(query, orm.Query)
@ -337,24 +341,24 @@ class TestRoleRef(WebTestCase):
self.assertIsNot(sorted_query, query)
def test_get_object_url(self):
self.pyramid_config.add_route('roles.view', '/roles/{uuid}')
self.pyramid_config.add_route("roles.view", "/roles/{uuid}")
model = self.app.model
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.RoleRef(self.request)
role = model.Role(name='Manager')
role = model.Role(name="Manager")
self.session.add(role)
self.session.commit()
url = typ.get_object_url(role)
self.assertIsNotNone(url)
self.assertIn(f'/roles/{role.uuid}', url)
self.assertIn(f"/roles/{role.uuid}", url)
class TestUserRef(WebTestCase):
def test_sort_query(self):
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.UserRef(self.request)
query = typ.get_query()
self.assertIsInstance(query, orm.Query)
@ -363,18 +367,18 @@ class TestUserRef(WebTestCase):
self.assertIsNot(sorted_query, query)
def test_get_object_url(self):
self.pyramid_config.add_route('users.view', '/users/{uuid}')
self.pyramid_config.add_route("users.view", "/users/{uuid}")
model = self.app.model
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
typ = mod.UserRef(self.request)
user = model.User(username='barney')
user = model.User(username="barney")
self.session.add(user)
self.session.commit()
url = typ.get_object_url(user)
self.assertIsNotNone(url)
self.assertIn(f'/users/{user.uuid}', url)
self.assertIn(f"/users/{user.uuid}", url)
class TestRoleRefs(DataTestCase):
@ -393,7 +397,7 @@ class TestRoleRefs(DataTestCase):
self.session.add(blokes)
self.session.commit()
with patch.object(mod, 'Session', return_value=self.session):
with patch.object(mod, "Session", return_value=self.session):
# with root access, default values include: admin, blokes
self.request.is_root = True
@ -427,11 +431,11 @@ class TestPermissions(DataTestCase):
# supported permissions are morphed to values
permissions = {
'widgets': {
'label': "Widgets",
'perms': {
'widgets.polish': {
'label': "Polish the widgets",
"widgets": {
"label": "Widgets",
"perms": {
"widgets.polish": {
"label": "Polish the widgets",
},
},
},
@ -439,7 +443,7 @@ class TestPermissions(DataTestCase):
typ = mod.Permissions(self.request, permissions)
widget = typ.widget_maker()
self.assertEqual(len(widget.values), 1)
self.assertEqual(widget.values[0], ('widgets.polish', "Polish the widgets"))
self.assertEqual(widget.values[0], ("widgets.polish", "Polish the widgets"))
class TestFileDownload(DataTestCase):
@ -451,10 +455,10 @@ class TestFileDownload(DataTestCase):
def test_widget_maker(self):
# sanity / coverage check
typ = mod.FileDownload(self.request, url='/foo')
typ = mod.FileDownload(self.request, url="/foo")
widget = typ.widget_maker()
self.assertIsInstance(widget, widgets.FileDownloadWidget)
self.assertEqual(widget.url, '/foo')
self.assertEqual(widget.url, "/foo")
class TestEmailRecipients(TestCase):
@ -464,14 +468,14 @@ class TestEmailRecipients(TestCase):
node = colander.SchemaNode(typ)
recips = [
'alice@example.com',
'bob@example.com',
"alice@example.com",
"bob@example.com",
]
recips_str = ', '.join(recips)
recips_str = ", ".join(recips)
# values
result = typ.serialize(node, recips_str)
self.assertEqual(result, '\n'.join(recips))
self.assertEqual(result, "\n".join(recips))
# null
result = typ.serialize(node, colander.null)
@ -482,10 +486,10 @@ class TestEmailRecipients(TestCase):
node = colander.SchemaNode(typ)
recips = [
'alice@example.com',
'bob@example.com',
"alice@example.com",
"bob@example.com",
]
recips_str = ', '.join(recips)
recips_str = ", ".join(recips)
# values
result = typ.deserialize(node, recips_str)