From 43a80e5378cbf6a0d1c478641203537aac6d72f2 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:43:07 +0800 Subject: [PATCH] moved find scope tests in with other tests --- tests/mysql/model/test_model_scopes.py | 25 ------------------------ tests/mysql/scopes/test_soft_delete.py | 27 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 tests/mysql/model/test_model_scopes.py diff --git a/tests/mysql/model/test_model_scopes.py b/tests/mysql/model/test_model_scopes.py deleted file mode 100644 index 28d37a6b..00000000 --- a/tests/mysql/model/test_model_scopes.py +++ /dev/null @@ -1,25 +0,0 @@ -import unittest - -from src.masoniteorm.models import Model -from src.masoniteorm.scopes import SoftDeletesMixin - - -class User(Model, SoftDeletesMixin): - pass - - -class TestModelScopes(unittest.TestCase): - def test_find_with_global_scope(self): - find_sql = User.find("1", query=True).to_sql() - raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1' AND `users`.`deleted_at` IS NULL""" - self.assertEqual(find_sql, raw_sql) - - def test_find_with_trashed_scope(self): - find_sql = User.with_trashed().find("1", query=True).to_sql() - raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1'""" - self.assertEqual(find_sql, raw_sql) - - def test_find_with_only_trashed_scope(self): - find_sql = User.only_trashed().find("1", query=True).to_sql() - raw_sql = """SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL AND `users`.`id` = '1'""" - self.assertEqual(find_sql, raw_sql) diff --git a/tests/mysql/scopes/test_soft_delete.py b/tests/mysql/scopes/test_soft_delete.py index b48f829e..1a0c6c43 100644 --- a/tests/mysql/scopes/test_soft_delete.py +++ b/tests/mysql/scopes/test_soft_delete.py @@ -1,8 +1,8 @@ -import inspect import unittest +import pendulum + from tests.integrations.config.database import DATABASES -from src.masoniteorm.models import Model from src.masoniteorm.query import QueryBuilder from src.masoniteorm.query.grammars import MySQLGrammar from src.masoniteorm.scopes import SoftDeleteScope @@ -10,16 +10,14 @@ from src.masoniteorm.models import Model from src.masoniteorm.scopes import SoftDeletesMixin -from tests.User import User class UserSoft(Model, SoftDeletesMixin): __dry__ = True - + __table__ = "users" class UserSoftArchived(Model, SoftDeletesMixin): __dry__ = True - __deleted_at__ = "archived_at" __table__ = "users" @@ -52,7 +50,7 @@ def test_restore(self): self.assertEqual(sql, builder.restore().to_sql()) def test_force_delete_with_wheres(self): - sql = "DELETE FROM `user_softs` WHERE `user_softs`.`active` = '1'" + sql = "DELETE FROM `users` WHERE `users`.`active` = '1'" builder = self.get_builder().set_global_scope(SoftDeleteScope()) self.assertEqual( sql, UserSoft.where("active", 1).force_delete(query=True).to_sql() @@ -69,9 +67,24 @@ def test_only_trashed(self): self.assertEqual(sql, builder.only_trashed().to_sql()) def test_only_trashed_on_model(self): - sql = "SELECT * FROM `user_softs` WHERE `user_softs`.`deleted_at` IS NOT NULL" + sql = "SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL" self.assertEqual(sql, UserSoft.only_trashed().to_sql()) def test_can_change_column(self): sql = "SELECT * FROM `users` WHERE `users`.`archived_at` IS NOT NULL" self.assertEqual(sql, UserSoftArchived.only_trashed().to_sql()) + + def test_find_with_global_scope(self): + find_sql = UserSoft.find("1", query=True).to_sql() + raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1' AND `users`.`deleted_at` IS NULL""" + self.assertEqual(find_sql, raw_sql) + + def test_find_with_trashed_scope(self): + find_sql = UserSoft.with_trashed().find("1", query=True).to_sql() + raw_sql = """SELECT * FROM `users` WHERE `users`.`id` = '1'""" + self.assertEqual(find_sql, raw_sql) + + def test_find_with_only_trashed_scope(self): + find_sql = UserSoft.only_trashed().find("1", query=True).to_sql() + raw_sql = """SELECT * FROM `users` WHERE `users`.`deleted_at` IS NOT NULL AND `users`.`id` = '1'""" + self.assertEqual(find_sql, raw_sql)