-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: George Lemon <georgelemon@protonmail.com>
- Loading branch information
1 parent
998c009
commit 43ccda1
Showing
3 changed files
with
58 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,52 @@ | ||
# This is just an example to get you started. You may wish to put all of your | ||
# tests into a single file, or separate them into multiple `test1`, `test2` | ||
# etc. files (better names are recommended, just make sure the name starts with | ||
# the letter 't'). | ||
# | ||
# To run these tests, simply execute `nimble test`. | ||
|
||
import unittest | ||
import db_connector/db_postgres | ||
|
||
import enimsql | ||
|
||
newModel Users: | ||
id {.pk, notnull.}: Serial | ||
name: Varchar(255) | ||
email {.unique, notnull.}: Text | ||
is_confirmed {.notnull.}: Boolean = false | ||
is_muted {.notnull.}: Boolean = false | ||
total_posts {.notnull, inc.}: Int = 0 | ||
total_replies {.notnull, inc.}: Int = 0 | ||
last_active: Date | ||
last_published_reply: Date | ||
last_published_topic: Date | ||
|
||
# newModel Sessions: | ||
# id {.pk, notnull.}: Serial | ||
# author_id: Users.id | ||
# user_ip: Int | ||
# user_agent: Text | ||
# payload: Text | ||
# last_activity: Date | ||
|
||
test "can init database": | ||
initdb("georgelemon", "georgelemon", "") | ||
assert DB.maindb.user == "georgelemon" | ||
assert DB.maindb.name == "georgelemon" | ||
assert DB.maindb.password.len == 0 | ||
|
||
test "runtime create table": | ||
let q = Models.create("sessions") do(schema: Schema): | ||
schema.add("id", Serial).primaryKey | ||
schema.add("user_ip", Int) | ||
schema.add("user_agent", Text) | ||
schema.add("payload", Text) | ||
schema.add("last_activity", Date) | ||
echo q | ||
|
||
test "runtime check tables": | ||
try: | ||
discard Models.create("sessions") do(schema: Schema): | ||
schema.add("id", Serial).primaryKey | ||
except EnimsqlModelDefect as e: | ||
assert e.msg == "Duplicate model `sessions`" | ||
|
||
import v2 | ||
test "can add": | ||
check add(5, 5) == 10 | ||
try: | ||
discard Models.create("users") do(schema: Schema): | ||
schema.add("id", Serial).primaryKey | ||
except EnimsqlModelDefect as e: | ||
assert e.msg == "Duplicate model `users`" |