From fe0d42db3748400fccecbec2bb32d34c711b688d Mon Sep 17 00:00:00 2001 From: Justin Duch Date: Mon, 26 Apr 2021 22:17:48 +1000 Subject: [PATCH] add union test --- README.md | 3 +-- tests/test_query.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b5de99b..e2fe0dc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![PyPI](https://img.shields.io/pypi/v/estoult)](https://pypi.org/project/estoult/) [![PyPI - License](https://img.shields.io/pypi/l/estoult)](https://pypi.org/project/estoult/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/estoult)](https://pypi.org/project/estoult/) -[![PyPI - Downloads](https://img.shields.io/pypi/dm/estoult)](https://pypi.org/project/estoult/) [![Documentation Status](https://readthedocs.org/projects/estoult/badge/?version=latest)](https://estoult.readthedocs.io/en/latest/?badge=latest) Estoult is a Python toolkit for data mapping with an integrated query builder for SQL databases. It currently supports MySQL, PostgreSQL, and SQLite. @@ -17,7 +16,7 @@ Features: - Easy debugging by displaying any generated SQL in a readable format. - Performant as raw SQL. Estoult is **NOT** an ORM. -Estoult only works with Python 3.6+ and is primarily tested on Python 3.8+. +Estoult only works with Python 3.6+ and is primarily tested on Python 3.9+. ## Installation diff --git a/tests/test_query.py b/tests/test_query.py index 7160c32..45b69f9 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -1,5 +1,5 @@ import pytest -from estoult import Query, QueryError +from estoult import Query, QueryError, fn from .base import assertSQL, User, Organisation, Data @@ -28,8 +28,23 @@ def test_left_join(): assertSQL(q, s) +def test_query_union(): + s = ( + "select * from users union select users.* from organisations " + "left join users on users.organisation_id = organisations.id" + ) + q = ( + Query(User) + .select() + .union(Organisation) + .select(fn.wild(User)) + .left_join(User, on=[User.organisation_id, Organisation.id]) + ) + assertSQL(q, s) + + def test_order_by(): - s = "select * from users order by users.name desc, users.id " "limit 10 offset 2" + s = "select * from users order by users.name desc, users.id limit 10 offset 2" q = Query(User).select().order_by({User.name: "desc"}, User.id).limit(10, 2) assertSQL(q, s)