From 3296708955e111579f00da8054ed2a4a86834766 Mon Sep 17 00:00:00 2001
From: Michaƫl Ball <michael.ball@gmail.com>
Date: Sat, 17 Jun 2017 09:52:17 +0100
Subject: Support setting transcode command.

---
 tests/mach2_test.py |  43 ++++++++++++++++++++++++++++++++++++++++---
 tests/testapp.db    | Bin 2048 -> 2048 bytes
 2 files changed, 40 insertions(+), 3 deletions(-)

(limited to 'tests')

diff --git a/tests/mach2_test.py b/tests/mach2_test.py
index c33fd92..adee00d 100644
--- a/tests/mach2_test.py
+++ b/tests/mach2_test.py
@@ -1,4 +1,7 @@
+"""Tests for the mach2 app."""
 import json
+import random
+import string
 import unittest
 
 import pytest
@@ -9,22 +12,33 @@ from mach2 import create_app
 
 @pytest.mark.usefixtures("app")
 class Mach2TestCase(unittest.TestCase):
+    """Provides tests for the mach2 app."""
 
     def setUp(self):
+        """Set up the state before the tests run."""
         app = create_app(database=self.db, library=self.library_db)
-        app.config['TESTING'] = True
+        app.config["TESTING"] = True
         self.app = app.test_client()
 
     def login(self, username, password):
-        return self.app.post('/login', data=dict(
+        """Log in to the app.
+
+        Args:
+            username (str): The username to log in with.
+            password (str): The password to log in with.
+
+        """
+        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)
+        """Log out of the app."""
+        return self.app.get("/logout", follow_redirects=True)
 
     def test_login(self):
+        """Test logging in to the app."""
         rv = self.login("admin", "testpass")
         assert six.b("Log out") in rv.data
         self.logout()
@@ -33,6 +47,7 @@ class Mach2TestCase(unittest.TestCase):
         self.logout()
 
     def test_album(self):
+        """Test retrieving albums."""
         self.login("admin", "testpass")
 
         rv = self.app.get("/albums/1")
@@ -41,6 +56,7 @@ class Mach2TestCase(unittest.TestCase):
         self.logout()
 
     def test_artists(self):
+        """Test retrieving artists."""
         self.login("admin", "testpass")
         rv = self.app.get("/artists")
 
@@ -51,3 +67,24 @@ class Mach2TestCase(unittest.TestCase):
         assert artists
 
         self.logout()
+
+    def test_encoding_options(self):
+        """Test setting encoding options."""
+        self.login("admin", "testpass")
+
+        transcode_string = "".join(
+            random.choice(
+                string.ascii_lowercase + string.digits) for _ in range(10))
+
+        transcode_command = dict(transcode_command=transcode_string)
+
+        put_response = self.app.put(
+            "/user", data=json.dumps(transcode_command),
+            content_type="application/json")
+
+        assert put_response.status_code == 200
+
+        get_response = self.app.get("/user")
+
+        user = json.loads(get_response.data.decode("utf-8"))
+        assert user["transcode_command"] == six.u(transcode_string)
diff --git a/tests/testapp.db b/tests/testapp.db
index 3ccfa2f..ae0702d 100644
Binary files a/tests/testapp.db and b/tests/testapp.db differ
-- 
cgit v1.2.3