summaryrefslogtreecommitdiff
path: root/tests/mach2_test.py
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2016-02-07 15:28:56 +0000
committerMichaël Ball <michael.ball@gmail.com>2016-07-15 07:15:13 +0100
commitcaa1c3ccdf94ee20140b3964aab0ad3058e03699 (patch)
tree12de8657e4fe4533a62c8693cb8cdaa90a74e27f /tests/mach2_test.py
parentea4391ba43fab82b8f1fbf2f9ab939e60d5e0bc2 (diff)
Create test framework
Diffstat (limited to 'tests/mach2_test.py')
-rw-r--r--tests/mach2_test.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/mach2_test.py b/tests/mach2_test.py
new file mode 100644
index 0000000..c45ff2a
--- /dev/null
+++ b/tests/mach2_test.py
@@ -0,0 +1,52 @@
+import json
+import unittest
+
+import pytest
+
+from mach2 import create_app
+
+
+@pytest.mark.usefixtures("app")
+class Mach2TestCase(unittest.TestCase):
+
+ def setUp(self):
+ app = create_app(database=self.db, library=self.library_db)
+ app.config['TESTING'] = True
+ self.app = app.test_client()
+
+ def login(self, username, password):
+ return self.app.post('/login', data=dict(
+ username=username,
+ password=password
+ ), follow_redirects=True)
+
+ def logout(self):
+ return self.app.get('/logout', follow_redirects=True)
+
+ def test_login(self):
+ rv = self.login("admin", "testpass")
+ assert bytes("Log out", "utf-8") in rv.data
+ self.logout()
+ rv = self.login("wrong", "definitelywrong")
+ assert bytes("Log out", "utf-8") not in rv.data
+ self.logout()
+
+ def test_album(self):
+ self.login("admin", "testpass")
+
+ rv = self.app.get("/albums/1")
+ assert bytes("Album 1", "utf-8") in rv.data
+
+ self.logout()
+
+ def test_artists(self):
+ self.login("admin", "testpass")
+ rv = self.app.get("/artists")
+
+ assert bytes("Artist 1", "utf-8") in rv.data
+ assert bytes("Artist 2", "utf-8") in rv.data
+
+ artists = json.loads(rv.data.decode("utf-8"))
+ assert artists
+
+ self.logout()