Skip to content

Commit

Permalink
black formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Dec 6, 2023
1 parent b9dd047 commit 22a5c01
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 59 deletions.
12 changes: 10 additions & 2 deletions src/masoniteorm/commands/MigrateStatusCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ def handle(self):
batch = migration_data["batch"]

migrations.append(
["<info>Y</info>", f"<comment>{migration_file}</comment>", f"<info>{batch}</info>"]
[
"<info>Y</info>",
f"<comment>{migration_file}</comment>",
f"<info>{batch}</info>",
]
)

for migration_file in migration.get_unran_migrations():
migrations.append(
["<error>N</error>", f"<comment>{migration_file}</comment>", "<info>-</info>"]
[
"<error>N</error>",
f"<comment>{migration_file}</comment>",
"<info>-</info>",
]
)

table.set_rows(migrations)
Expand Down
5 changes: 3 additions & 2 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
HTTP404,
ConnectionNotRegistered,
ModelNotFound,
MultipleRecordsFound, InvalidArgument,
MultipleRecordsFound,
InvalidArgument,
)
from ..expressions.expressions import (
AggregateExpression,
Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(
scopes=None,
schema=None,
dry=False,
config_path=None
config_path=None,
):
"""QueryBuilder initializer
Expand Down
8 changes: 2 additions & 6 deletions src/masoniteorm/schema/Schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
grammar=None,
connection_details=None,
schema=None,
config_path=None
config_path=None,
):
self._dry = dry
self.connection = connection
Expand Down Expand Up @@ -306,11 +306,7 @@ def get_all_tables(self):

result = self.new_connection().query(sql, ())

return (
list(map(lambda t: list(t.values())[0], result))
if result
else []
)
return list(map(lambda t: list(t.values())[0], result)) if result else []

def has_table(self, table, query_only=False):
"""Checks if the a database has a specific table
Expand Down
27 changes: 6 additions & 21 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,17 @@ class ModelTest(Model):


class FillableModelTest(Model):
__fillable__ = [
"due_date",
"is_vip",
]
__fillable__ = ["due_date", "is_vip"]


class InvalidFillableGuardedModelTest(Model):
__fillable__ = [
"due_date",
]
__guarded__ = [
"is_vip",
"payload",
]
__fillable__ = ["due_date"]
__guarded__ = ["is_vip", "payload"]


class InvalidFillableGuardedChildModelTest(ModelTest):
__fillable__ = [
"due_date",
]
__guarded__ = [
"is_vip",
"payload",
]
__fillable__ = ["due_date"]
__guarded__ = ["is_vip", "payload"]


class ModelTestForced(Model):
Expand Down Expand Up @@ -147,9 +134,7 @@ def test_model_can_cast_dict_attributes(self):

def test_valid_json_cast(self):
model = ModelTest.hydrate(
{
"payload": {"this": "dict", "is": "usable", "as": "json"},
}
{"payload": {"this": "dict", "is": "usable", "as": "json"}}
)

self.assertEqual(type(model.payload), dict)
Expand Down
27 changes: 5 additions & 22 deletions tests/mysql/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def test_create_can_use_guarded_asterisk(self):

# An asterisk guarded attribute excludes all fields from mass-assignment.
# This would raise a DB error if there are any required fields.
self.assertEqual(
sql,
"INSERT INTO `profiles` (*) VALUES ()",
)
self.assertEqual(sql, "INSERT INTO `profiles` (*) VALUES ()")

def test_bulk_create_can_use_fillable(self):
query_builder = ProfileFillable.bulk_create(
Expand Down Expand Up @@ -173,8 +170,7 @@ def test_bulk_create_can_use_guarded_asterisk(self):
# This would obviously raise an invalid SQL syntax error.
# TODO: Raise a clearer error?
self.assertEqual(
query_builder.to_sql(),
"INSERT INTO `profiles` () VALUES (), ()",
query_builder.to_sql(), "INSERT INTO `profiles` () VALUES (), ()"
)

def test_update_can_use_fillable(self):
Expand Down Expand Up @@ -214,10 +210,7 @@ def test_update_can_use_guarded_asterisk(self):

# An asterisk guarded attribute excludes all fields from mass-assignment.
# The query builder's sql should not have been altered in any way.
self.assertEqual(
query_builder.to_sql(),
initial_sql,
)
self.assertEqual(query_builder.to_sql(), initial_sql)

def test_table_name(self):
table_name = Profile.get_table_name()
Expand Down Expand Up @@ -250,25 +243,15 @@ def test_serialize_with_hidden(self):

def test_serialize_with_visible(self):
profile = ProfileSerializeWithVisible.hydrate(
{
"name": "Joe",
"id": 1,
"password": "secret",
"email": "[email protected]",
}
{"name": "Joe", "id": 1, "password": "secret", "email": "[email protected]"}
)
self.assertTrue(
{"name": "Joe", "email": "[email protected]"}, profile.serialize()
)

def test_serialize_with_visible_and_hidden_raise_error(self):
profile = ProfileSerializeWithVisibleAndHidden.hydrate(
{
"name": "Joe",
"id": 1,
"password": "secret",
"email": "[email protected]",
}
{"name": "Joe", "id": 1, "password": "secret", "email": "[email protected]"}
)
with self.assertRaises(AttributeError):
profile.serialize()
Expand Down
8 changes: 2 additions & 6 deletions tests/sqlite/models/test_sqlite_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ def test_find_or_if_record_not_found(self):
record_id = 1_000_000_000_000_000

result = User.find_or(record_id, lambda: "Record not found.")
self.assertEqual(
result, "Record not found."
)
self.assertEqual(result, "Record not found.")

def test_find_or_if_record_found(self):
record_id = 1
result_id = User.find_or(record_id, lambda: "Record not found.").id

self.assertEqual(
result_id, record_id
)
self.assertEqual(result_id, record_id)

def test_can_set_and_retreive_attribute(self):
user = User.hydrate({"id": 1, "name": "joe", "customer_id": 1})
Expand Down

0 comments on commit 22a5c01

Please sign in to comment.