|
| 1 | +import unittest |
| 2 | + |
| 3 | +from appwrite.query import Query |
| 4 | + |
| 5 | + |
| 6 | +class BasicFilterQueryTest: |
| 7 | + def __init__(self, description: str, value, expected_values: str): |
| 8 | + self.description = description |
| 9 | + self.value = value |
| 10 | + self.expected_values = expected_values |
| 11 | + |
| 12 | + |
| 13 | +tests = [ |
| 14 | + BasicFilterQueryTest('with a string', 's', '["s"]'), |
| 15 | + BasicFilterQueryTest('with an integer', 1, '[1]'), |
| 16 | + BasicFilterQueryTest('with a double', 1.2, '[1.2]'), |
| 17 | + BasicFilterQueryTest('with a whole number double', 1.0, '[1.0]'), |
| 18 | + BasicFilterQueryTest('with a bool', False, '[false]'), |
| 19 | + BasicFilterQueryTest('with a list', ['a', 'b', 'c'], '["a","b","c"]'), |
| 20 | +] |
| 21 | + |
| 22 | + |
| 23 | +class TestQueryMethods(unittest.TestCase): |
| 24 | + |
| 25 | + def test_equal(self): |
| 26 | + for t in tests: |
| 27 | + self.assertEqual( |
| 28 | + Query.equal('attr', t.value), |
| 29 | + f'equal("attr", {t.expected_values})', |
| 30 | + t.description |
| 31 | + ) |
| 32 | + |
| 33 | + def test_not_equal(self): |
| 34 | + for t in tests: |
| 35 | + self.assertEqual( |
| 36 | + Query.not_equal('attr', t.value), |
| 37 | + f'notEqual("attr", {t.expected_values})', |
| 38 | + t.description |
| 39 | + ) |
| 40 | + |
| 41 | + def test_less_than(self): |
| 42 | + for t in tests: |
| 43 | + self.assertEqual( |
| 44 | + Query.less_than('attr', t.value), |
| 45 | + f'lessThan("attr", {t.expected_values})', |
| 46 | + t.description |
| 47 | + ) |
| 48 | + |
| 49 | + def test_less_than_equal(self): |
| 50 | + for t in tests: |
| 51 | + self.assertEqual( |
| 52 | + Query.less_than_equal('attr', t.value), |
| 53 | + f'lessThanEqual("attr", {t.expected_values})', |
| 54 | + t.description |
| 55 | + ) |
| 56 | + |
| 57 | + def test_greater_than(self): |
| 58 | + for t in tests: |
| 59 | + self.assertEqual( |
| 60 | + Query.greater_than('attr', t.value), |
| 61 | + f'greaterThan("attr", {t.expected_values})', |
| 62 | + t.description |
| 63 | + ) |
| 64 | + |
| 65 | + def test_greater_than_equal(self): |
| 66 | + for t in tests: |
| 67 | + self.assertEqual( |
| 68 | + Query.greater_than_equal('attr', t.value), |
| 69 | + f'greaterThanEqual("attr", {t.expected_values})', |
| 70 | + t.description |
| 71 | + ) |
| 72 | + |
| 73 | + def test_search(self): |
| 74 | + self.assertEqual(Query.search('attr', 'keyword1 keyword2'), 'search("attr", ["keyword1 keyword2"])') |
| 75 | + |
| 76 | + def test_is_null(self): |
| 77 | + self.assertEqual(Query.is_null('attr'), 'isNull("attr")') |
| 78 | + |
| 79 | + def test_is_not_null(self): |
| 80 | + self.assertEqual(Query.is_not_null('attr'), 'isNotNull("attr")') |
| 81 | + |
| 82 | + def test_between_with_integers(self): |
| 83 | + self.assertEqual(Query.between('attr', 1, 2), 'between("attr", [1,2])') |
| 84 | + |
| 85 | + def test_between_with_doubles(self): |
| 86 | + self.assertEqual(Query.between('attr', 1.0, 2.0), 'between("attr", [1.0,2.0])') |
| 87 | + |
| 88 | + def test_between_with_strings(self): |
| 89 | + self.assertEqual(Query.between('attr', 'a', 'z'), 'between("attr", ["a","z"])') |
| 90 | + |
| 91 | + def test_select(self): |
| 92 | + self.assertEqual(Query.select(['attr1', 'attr2']), 'select(["attr1","attr2"])') |
| 93 | + |
| 94 | + def test_order_asc(self): |
| 95 | + self.assertEqual(Query.order_asc('attr'), 'orderAsc("attr")') |
| 96 | + |
| 97 | + def test_order_desc(self): |
| 98 | + self.assertEqual(Query.order_desc('attr'), 'orderDesc("attr")') |
| 99 | + |
| 100 | + def test_cursor_before(self): |
| 101 | + self.assertEqual(Query.cursor_before('custom'), 'cursorBefore("custom")') |
| 102 | + |
| 103 | + def test_cursor_after(self): |
| 104 | + self.assertEqual(Query.cursor_after('custom'), 'cursorAfter("custom")') |
| 105 | + |
| 106 | + def test_limit(self): |
| 107 | + self.assertEqual(Query.limit(1), 'limit(1)') |
| 108 | + |
| 109 | + def test_offset(self): |
| 110 | + self.assertEqual(Query.offset(1), 'offset(1)') |
0 commit comments