test_database.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from synapse.storage.database import make_tuple_comparison_clause
  15. from synapse.storage.engines import BaseDatabaseEngine
  16. from tests import unittest
  17. def _stub_db_engine(**kwargs) -> BaseDatabaseEngine:
  18. # returns a DatabaseEngine, circumventing the abc mechanism
  19. # any kwargs are set as attributes on the class before instantiating it
  20. t = type(
  21. "TestBaseDatabaseEngine",
  22. (BaseDatabaseEngine,),
  23. dict(BaseDatabaseEngine.__dict__),
  24. )
  25. # defeat the abc mechanism
  26. t.__abstractmethods__ = set()
  27. for k, v in kwargs.items():
  28. setattr(t, k, v)
  29. return t(None, None)
  30. class TupleComparisonClauseTestCase(unittest.TestCase):
  31. def test_native_tuple_comparison(self):
  32. clause, args = make_tuple_comparison_clause([("a", 1), ("b", 2)])
  33. self.assertEqual(clause, "(a,b) > (?,?)")
  34. self.assertEqual(args, [1, 2])