Skip to content

Commit 27cee27

Browse files
committed
WIP
1 parent 5a1da20 commit 27cee27

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

orm.sqlite3

0 Bytes
Binary file not shown.

src/masoniteorm/schema/Schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def on(self, connection_key):
8989
"""
9090
DB = load_config(config_path=self.config_path).DB
9191

92+
if not self.connection_details:
93+
self.connection_details = DB.get_connection_details()
94+
9295
if connection_key == "default":
9396
self.connection = self.connection_details.get("default")
9497

tests/collection/test_collection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ def __init__(self, code):
575575
self.code = code
576576

577577
def __eq__(self, other):
578+
if isinstance(other, dict):
579+
return self.code == other["code"]
578580
return self.code == other.code
579581

580582
def to_dict(self):

tests/postgres/builder/test_postgres_query_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from src.masoniteorm.models import Model
44
from src.masoniteorm.query import QueryBuilder
55
from src.masoniteorm.query.grammars import PostgresGrammar
6+
from tests.utils import MockConnectionFactory
67

78

89
class MockConnection:

tests/sqlite/relationships/test_sqlite_relationships.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Articles(Model):
2121
__timestamps__ = None
2222
__dates__ = ["published_date"]
2323

24-
@belongs_to("id", "article_id")
24+
@has_one("id", "article_id")
2525
def logo(self):
2626
return Logo
2727

@@ -104,12 +104,27 @@ def test_can_access_has_many_relationship(self):
104104
self.assertEqual(len(user.articles), 1)
105105

106106
def test_can_access_relationship_multiple_times(self):
107+
User.create(
108+
{"name": "Joe", "is_admin": True, "email": "[email protected]"}
109+
)
107110
user = User.hydrate(User.where("id", 1).first())
108-
self.assertEqual(len(user.articles), 1)
109-
self.assertEqual(len(user.articles), 1)
111+
Articles.create({"title": "test", "user_id": user.id})
112+
self.assertEqual(len(user.articles), 2)
113+
self.assertEqual(len(user.articles), 2)
110114

111115
def test_can_access_relationship_date(self):
116+
User.create(
117+
{"name": "Joe", "is_admin": True, "email": "[email protected]"}
118+
)
119+
article = Articles.create({"title": "test", "user_id": 1})
112120
user = User.with_("articles").where("id", 1).first()
121+
Logo.create(
122+
{
123+
"name": "https://masonite.com",
124+
"article_id": article.id,
125+
"user_id": user.id,
126+
}
127+
)
113128
for article in user.articles:
114129
print(article.logo.published_date.is_past())
115130

@@ -128,7 +143,7 @@ def test_loading_with_nested_with(self):
128143
for user in users:
129144
for article in user.articles:
130145
if article.logo:
131-
print("aa", article.logo.url)
146+
print("aa", article.logo.name)
132147

133148
def test_casting(self):
134149
users = User.with_("articles").where("is_admin", True).get()
@@ -143,6 +158,9 @@ def test_setting(self):
143158
user.save()
144159

145160
def test_related(self):
161+
User.create(
162+
{"name": "Joe", "is_admin": True, "email": "[email protected]"}
163+
)
146164
user = User.first()
147165
related_query = user.related("profile").where("active", 1).to_sql()
148166
self.assertEqual(

tests/sqlite/schema/test_sqlite_schema_builder_alter.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
import unittest
22

3-
from src.masoniteorm.schema import Schema
3+
from src.masoniteorm.schema import Schema, Table
44
from src.masoniteorm.schema.platforms import SQLitePlatform
5+
from tests.integrations.config.database import DATABASES
56

67

78
class TestSQLiteSchemaBuilderAlter(unittest.TestCase):
89
maxDiff = None
910

1011
def setUp(self):
1112
self.schema = Schema(
12-
connection="sqlite",
13+
connection="dev",
1314
platform=SQLitePlatform,
1415
dry=True,
15-
).on("sqlite")
16+
).on("dev")
1617

1718
def test_can_add_columns(self):
18-
with self.schema.alter("users") as blueprint:
19+
with self.schema.table("users") as blueprint:
1920
blueprint.string("name")
21+
blueprint.string("external_type").default("external")
2022
blueprint.integer("age")
2123

22-
self.assertEqual(len(blueprint.table.added_columns), 2)
24+
self.assertEqual(len(blueprint.table.added_columns), 3)
25+
print(blueprint.to_sql())
2326
self.assertEqual(
2427
blueprint.to_sql(),
2528
[
26-
"ALTER TABLE `users` ADD COLUMN `name` VARCHAR(255) NOT NULL",
27-
"ALTER TABLE `users` ADD COLUMN `age` INT(11) NOT NULL",
29+
'ALTER TABLE "users" ADD COLUMN "name" VARCHAR NOT NULL',
30+
'ALTER TABLE "users" ADD COLUMN "external_type" VARCHAR NOT NULL DEFAULT \'external\'',
31+
'ALTER TABLE "users" ADD COLUMN "age" INTEGER NOT NULL',
2832
],
2933
)
3034

@@ -116,7 +120,7 @@ def test_drop_add_and_change(self):
116120
self.assertEqual(
117121
blueprint.to_sql(),
118122
[
119-
'ALTER TABLE "users" ADD COLUMN "name" VARCHAR',
123+
'ALTER TABLE "users" ADD COLUMN "name" VARCHAR NOT NULL',
120124
"CREATE TEMPORARY TABLE __temp__users AS SELECT age FROM users",
121125
'DROP TABLE "users"',
122126
'CREATE TABLE "users" ("age" INTEGER NOT NULL, "name" VARCHAR(255) NOT NULL)',
@@ -246,9 +250,8 @@ def test_can_add_column_after(self):
246250
blueprint.string("name").after("age")
247251

248252
self.assertEqual(len(blueprint.table.added_columns), 1)
253+
print(blueprint.to_sql())
249254
self.assertEqual(
250255
blueprint.to_sql(),
251-
[
252-
"ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL AFTER `age`"
253-
],
256+
['ALTER TABLE "users" ADD COLUMN "name" VARCHAR NOT NULL'],
254257
)

0 commit comments

Comments
 (0)