Skip to content

Commit

Permalink
Fixed and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
circulon committed Dec 1, 2024
1 parent 11743db commit e9008ae
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
22 changes: 20 additions & 2 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ModelTestForced(Model):
__force_update__ = True

class BaseModel(Model):
__dry__ = True
def get_selects(self):
return [f"{self.get_table_name()}.*"]

Expand Down Expand Up @@ -267,9 +268,26 @@ def test_model_can_provide_default_select(self):
"""SELECT `users`.* FROM `users`""",
)

def test_model_can_add_to_default_select(self):
def test_model_can_override_to_default_select(self):
sql = ModelWithBaseModel.select(["products.name", "products.id", "store.name"]).to_sql()
self.assertEqual(
sql,
"""SELECT `users`.*, `products`.`name`, `products`.`id`, `store`.`name` FROM `users`""",
"""SELECT `products`.`name`, `products`.`id`, `store`.`name` FROM `users`""",
)

def test_model_can_use_aggregate_funcs_with_default_selects(self):
sql = ModelWithBaseModel.count().to_sql()
self.assertEqual(
sql,
"""SELECT COUNT(*) AS m_count_reserved FROM `users`""",
)
sql = ModelWithBaseModel.max("id").to_sql()
self.assertEqual(
sql,
"""SELECT MAX(`users`.`id`) AS id FROM `users`""",
)
sql = ModelWithBaseModel.min("id").to_sql()
self.assertEqual(
sql,
"""SELECT MIN(`users`.`id`) AS id FROM `users`""",
)
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_builder(self, table="users"):
connection_class=connection,
connection="mssql",
table=table,
model=User,
model=User(),
)

def test_has(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/mysql/builder/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestTransactions(unittest.TestCase):
pass
# def get_builder(self, table="users"):
# connection = ConnectionFactory().make("default")
# return QueryBuilder(MySQLGrammar, connection, table=table, model=User)
# return QueryBuilder(MySQLGrammar, connection, table=table, model=User())

# def test_can_start_transaction(self, table="users"):
# builder = self.get_builder()
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite/builder/test_sqlite_builder_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class User(Model):
class BaseTestQueryRelationships(unittest.TestCase):
maxDiff = None

def get_builder(self, table="users", model=User):
def get_builder(self, table="users", model=User()):
connection = ConnectionFactory().make("sqlite")
return QueryBuilder(
grammar=SQLiteGrammar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def profile(self):
class BaseTestQueryRelationships(unittest.TestCase):
maxDiff = None

def get_builder(self, table="users", model=User):
def get_builder(self, table="users", model=User()):
connection = ConnectionFactory().make("sqlite")
return QueryBuilder(
grammar=SQLiteGrammar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BaseTestQueryRelationships(unittest.TestCase):
def get_builder(self, table="users"):
connection = MockConnectionFactory().make("sqlite")
return QueryBuilder(
grammar=SQLiteGrammar, connection_class=connection, table=table, model=User
grammar=SQLiteGrammar, connection_class=connection, table=table, model=User()
)

def test_has(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite/builder/test_sqlite_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_builder(self, table="users"):
grammar=SQLiteGrammar,
connection="dev",
table=table,
model=User,
model=User(),
connection_details=DATABASES,
).on("dev")

Expand Down

0 comments on commit e9008ae

Please sign in to comment.