summaryrefslogtreecommitdiff
path: root/qvisqve/file_store_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'qvisqve/file_store_tests.py')
-rw-r--r--qvisqve/file_store_tests.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/qvisqve/file_store_tests.py b/qvisqve/file_store_tests.py
new file mode 100644
index 0000000..6d27afc
--- /dev/null
+++ b/qvisqve/file_store_tests.py
@@ -0,0 +1,97 @@
+# Copyright (C) 2018 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import shutil
+import tempfile
+import unittest
+
+import qvisqve
+
+
+class FileStoreTests(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+ self.fs = qvisqve.FileStore(self.tempdir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def test_has_no_clients_initially(self):
+ self.assertEqual(self.fs.list('client'), [])
+
+ def test_has_no_users_initially(self):
+ self.assertEqual(self.fs.list('user'), [])
+
+ def test_raises_error_getting_nonexistent_resource(self):
+ with self.assertRaises(qvisqve.ResourceDoesNotExist):
+ self.fs.get('client', 'does-not-exist')
+
+ def test_creates_client(self):
+ client = {
+ 'id': 'test-client',
+ }
+ self.fs.create('client', client['id'], client)
+ self.assertEqual(self.fs.list('client'), [client['id']])
+
+ gotten = self.fs.get('client', client['id'])
+ self.assertEqual(client, gotten)
+
+ def test_updates_client(self):
+ client = {
+ 'id': 'test-client',
+ }
+ self.fs.create('client', client['id'], client)
+
+ updated = dict(client)
+ updated['foo'] = 'bar'
+ self.fs.create('client', client['id'], updated)
+ self.assertEqual(self.fs.get('client', client['id']), updated)
+
+ def test_two_clients(self):
+ one = {
+ 'id': 'first-client',
+ }
+ self.fs.create('client', one['id'], one)
+ self.assertEqual(self.fs.list('client'), [one['id']])
+
+ two = {
+ 'id': 'second-client',
+ }
+ self.fs.create('client', two['id'], two)
+ self.assertEqual(self.fs.list('client'), [one['id'], two['id']])
+
+ gotten = self.fs.get('client', two['id'])
+ self.assertEqual(two, gotten)
+
+ def test_creates_client_and_user(self):
+ client = {
+ 'id': 'test',
+ 'type': 'client',
+ }
+
+ user = {
+ 'id': 'test',
+ 'type': 'user',
+ }
+
+ self.fs.create('client', client['id'], client)
+ self.fs.create('user', user['id'], user)
+ self.assertEqual(self.fs.list('client'), [client['id']])
+ self.assertEqual(self.fs.list('user'), [user['id']])
+
+ self.assertEqual(client, self.fs.get('client', client['id']))
+ self.assertEqual(user, self.fs.get('user', user['id']))