def test_queryfilter_by_name(item): qry = QueryFilter(model=Table) qry.add('name', 'test') sql_expected = SQL + 'WHERE "table".name LIKE ?' assert qry.sql == sql_expected
def test_queryfilter_by_like(item): qry = QueryFilter(model=Table) qry.add('created_date[like]', '1999-09-09') sql_expected = SQL + \ "WHERE \"table\".created_date LIKE ?" assert qry.sql == sql_expected
def test_queryfilter_by_year(item): qry = QueryFilter(model=Table) qry.add('created_date[year]', '1') sql_expected = SQL + \ "WHERE CAST(STRFTIME('%Y', \"table\".created_date) AS INTEGER) = ?" assert qry.sql == sql_expected
def test_queryfilter_order_by_defalt_asc(item): qry = QueryFilter(model=Table) qry.add('sort_field', 'name') sql_expected = SQL[:-1] + \ "ORDER BY \"table\".name ASC" assert qry.sql == sql_expected
def test_queryfilter_by_is_null(item): qry = QueryFilter(model=Table) qry.add('name', 'null') sql_expected = SQL + \ "WHERE \"table\".name IS NULL" assert qry.sql == sql_expected
def test_queryfilter_by_notin_(item): qry = QueryFilter(model=Table) qry.add('name[notin_]', 'ab') sql_expected = SQL + \ "WHERE \"table\".name NOT IN (?, ?)" assert qry.sql == sql_expected
def test_queryfilter_by_isnot(item): qry = QueryFilter(model=Table) qry.add('name[isnot]', None) sql_expected = SQL + \ "WHERE \"table\".name IS NOT NULL" assert qry.sql == sql_expected
def test_queryfilter_by_equal(item): qry = QueryFilter(model=Table) qry.add('name[equal]', '1999-09-09') sql_expected = SQL + \ "WHERE \"table\".name = ?" assert qry.sql == sql_expected
def test_queryfilter_by_ilike(item): qry = QueryFilter(model=Table) qry.add('name[ilike]', '1999-09-09') sql_expected = SQL + \ "WHERE lower(\"table\".name) LIKE lower(?)" assert qry.sql == sql_expected
def test_queryfilter_by_name_or_description(item): qry = QueryFilter(model=Table) qry.add('name[orlike]', 'test') qry.add('description[orlike]', 'test') sql_expected = SQL + \ 'WHERE ("table".name LIKE ? OR "table".description LIKE ?)' assert qry.sql == sql_expected
def test_queryfilter_by_name_and_desciption(item): qry = QueryFilter(model=Table) qry.add('name', 'test') qry.add('description', 'test') sql_expected = SQL + \ 'WHERE "table".name LIKE ? AND "table".description LIKE ?' assert qry.sql == sql_expected
def test_error_get_invalid_field(item): qry = QueryFilter(model=Table) with pytest.raises(InvalidField): qry.add('not_in_table', 'test')
def test_error_get_invalid_field_in_order_by(item): qry = QueryFilter(model=Table) with pytest.raises(InvalidField): qry.add('sort_field', 'invalidField')
def test_error_get_invalid_operator(item): qry = QueryFilter(model=Table) qry.OPERATOR_KEYWORDS += ['notin'] qry.add('name[notin]', 'test') with pytest.raises(InvalidDialectField): qry.query()