summary refs log tree commit diff
path: root/tests/storage/test_base.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2016-03-27 22:54:42 +0100
committerMatthew Hodgson <matthew@matrix.org>2016-03-27 22:54:42 +0100
commitd9d48aad2d58deb5db422a5373a4dac9334a0618 (patch)
tree63e51372ca9ace4971403928bd46440ff9e455e2 /tests/storage/test_base.py
parentinitial WIP of a tentative preview_url endpoint - incomplete, untested, exper... (diff)
parenttypo (diff)
downloadsynapse-d9d48aad2d58deb5db422a5373a4dac9334a0618.tar.xz
Merge branch 'develop' into matthew/preview_urls
Diffstat (limited to 'tests/storage/test_base.py')
-rw-r--r--tests/storage/test_base.py92
1 files changed, 45 insertions, 47 deletions
diff --git a/tests/storage/test_base.py b/tests/storage/test_base.py
index 152d027663..2e33beb07c 100644
--- a/tests/storage/test_base.py
+++ b/tests/storage/test_base.py
@@ -17,7 +17,7 @@
 from tests import unittest
 from twisted.internet import defer
 
-from mock import Mock, call
+from mock import Mock
 
 from collections import OrderedDict
 
@@ -48,11 +48,12 @@ class SQLBaseStoreTestCase(unittest.TestCase):
 
         config = Mock()
         config.event_cache_size = 1
+        config.database_config = {"name": "sqlite3"}
         hs = HomeServer(
             "test",
             db_pool=self.db_pool,
             config=config,
-            database_engine=create_engine("sqlite3"),
+            database_engine=create_engine(config),
         )
 
         self.datastore = SQLBaseStore(hs)
@@ -62,13 +63,12 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.rowcount = 1
 
         yield self.datastore._simple_insert(
-                table="tablename",
-                values={"columname": "Value"}
+            table="tablename",
+            values={"columname": "Value"}
         )
 
         self.mock_txn.execute.assert_called_with(
-                "INSERT INTO tablename (columname) VALUES(?)",
-                ("Value",)
+            "INSERT INTO tablename (columname) VALUES(?)", ("Value",)
         )
 
     @defer.inlineCallbacks
@@ -76,14 +76,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.rowcount = 1
 
         yield self.datastore._simple_insert(
-                table="tablename",
-                # Use OrderedDict() so we can assert on the SQL generated
-                values=OrderedDict([("colA", 1), ("colB", 2), ("colC", 3)])
+            table="tablename",
+            # Use OrderedDict() so we can assert on the SQL generated
+            values=OrderedDict([("colA", 1), ("colB", 2), ("colC", 3)])
         )
 
         self.mock_txn.execute.assert_called_with(
-                "INSERT INTO tablename (colA, colB, colC) VALUES(?, ?, ?)",
-                (1, 2, 3,)
+            "INSERT INTO tablename (colA, colB, colC) VALUES(?, ?, ?)",
+            (1, 2, 3,)
         )
 
     @defer.inlineCallbacks
@@ -92,15 +92,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.fetchall.return_value = [("Value",)]
 
         value = yield self.datastore._simple_select_one_onecol(
-                table="tablename",
-                keyvalues={"keycol": "TheKey"},
-                retcol="retcol"
+            table="tablename",
+            keyvalues={"keycol": "TheKey"},
+            retcol="retcol"
         )
 
         self.assertEquals("Value", value)
         self.mock_txn.execute.assert_called_with(
-                "SELECT retcol FROM tablename WHERE keycol = ?",
-                ["TheKey"]
+            "SELECT retcol FROM tablename WHERE keycol = ?", ["TheKey"]
         )
 
     @defer.inlineCallbacks
@@ -109,15 +108,15 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.fetchone.return_value = (1, 2, 3)
 
         ret = yield self.datastore._simple_select_one(
-                table="tablename",
-                keyvalues={"keycol": "TheKey"},
-                retcols=["colA", "colB", "colC"]
+            table="tablename",
+            keyvalues={"keycol": "TheKey"},
+            retcols=["colA", "colB", "colC"]
         )
 
         self.assertEquals({"colA": 1, "colB": 2, "colC": 3}, ret)
         self.mock_txn.execute.assert_called_with(
-                "SELECT colA, colB, colC FROM tablename WHERE keycol = ?",
-                ["TheKey"]
+            "SELECT colA, colB, colC FROM tablename WHERE keycol = ?",
+            ["TheKey"]
         )
 
     @defer.inlineCallbacks
@@ -126,32 +125,32 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.fetchone.return_value = None
 
         ret = yield self.datastore._simple_select_one(
-                table="tablename",
-                keyvalues={"keycol": "Not here"},
-                retcols=["colA"],
-                allow_none=True
+            table="tablename",
+            keyvalues={"keycol": "Not here"},
+            retcols=["colA"],
+            allow_none=True
         )
 
         self.assertFalse(ret)
 
     @defer.inlineCallbacks
     def test_select_list(self):
-        self.mock_txn.rowcount = 3;
+        self.mock_txn.rowcount = 3
         self.mock_txn.fetchall.return_value = ((1,), (2,), (3,))
         self.mock_txn.description = (
-                ("colA", None, None, None, None, None, None),
+            ("colA", None, None, None, None, None, None),
         )
 
         ret = yield self.datastore._simple_select_list(
-                table="tablename",
-                keyvalues={"keycol": "A set"},
-                retcols=["colA"],
+            table="tablename",
+            keyvalues={"keycol": "A set"},
+            retcols=["colA"],
         )
 
         self.assertEquals([{"colA": 1}, {"colA": 2}, {"colA": 3}], ret)
         self.mock_txn.execute.assert_called_with(
-                "SELECT colA FROM tablename WHERE keycol = ?",
-                ["A set"]
+            "SELECT colA FROM tablename WHERE keycol = ?",
+            ["A set"]
         )
 
     @defer.inlineCallbacks
@@ -159,14 +158,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.rowcount = 1
 
         yield self.datastore._simple_update_one(
-                table="tablename",
-                keyvalues={"keycol": "TheKey"},
-                updatevalues={"columnname": "New Value"}
+            table="tablename",
+            keyvalues={"keycol": "TheKey"},
+            updatevalues={"columnname": "New Value"}
         )
 
         self.mock_txn.execute.assert_called_with(
-                "UPDATE tablename SET columnname = ? WHERE keycol = ?",
-                ["New Value", "TheKey"]
+            "UPDATE tablename SET columnname = ? WHERE keycol = ?",
+            ["New Value", "TheKey"]
         )
 
     @defer.inlineCallbacks
@@ -174,15 +173,15 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.rowcount = 1
 
         yield self.datastore._simple_update_one(
-                table="tablename",
-                keyvalues=OrderedDict([("colA", 1), ("colB", 2)]),
-                updatevalues=OrderedDict([("colC", 3), ("colD", 4)])
+            table="tablename",
+            keyvalues=OrderedDict([("colA", 1), ("colB", 2)]),
+            updatevalues=OrderedDict([("colC", 3), ("colD", 4)])
         )
 
         self.mock_txn.execute.assert_called_with(
-                "UPDATE tablename SET colC = ?, colD = ? WHERE " +
-                    "colA = ? AND colB = ?",
-                [3, 4, 1, 2]
+            "UPDATE tablename SET colC = ?, colD = ? WHERE"
+            " colA = ? AND colB = ?",
+            [3, 4, 1, 2]
         )
 
     @defer.inlineCallbacks
@@ -190,11 +189,10 @@ class SQLBaseStoreTestCase(unittest.TestCase):
         self.mock_txn.rowcount = 1
 
         yield self.datastore._simple_delete_one(
-                table="tablename",
-                keyvalues={"keycol": "Go away"},
+            table="tablename",
+            keyvalues={"keycol": "Go away"},
         )
 
         self.mock_txn.execute.assert_called_with(
-                "DELETE FROM tablename WHERE keycol = ?",
-                ["Go away"]
+            "DELETE FROM tablename WHERE keycol = ?", ["Go away"]
         )