summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormar77i <mar77i@protonmail.ch>2020-02-01 23:01:26 +0100
committermar77i <mar77i@protonmail.ch>2020-02-01 23:01:26 +0100
commit791ceb9dc457352cb996f1640053050852d75aed (patch)
tree4470edddd015b230fa34affcad819969024556fe
parent83355f67124e81bf8d5d4593f27d80ff843b37a3 (diff)
use spaces.
-rwxr-xr-xshortcut/api.py22
-rw-r--r--tests.py32
2 files changed, 27 insertions, 27 deletions
diff --git a/shortcut/api.py b/shortcut/api.py
index ee9b44f..a50694a 100755
--- a/shortcut/api.py
+++ b/shortcut/api.py
@@ -7,18 +7,18 @@ import sys
class URLResolver:
- conn = sqlite3.connect(os.path.join(os.getcwd(), "urls.sqlite3"))
+ conn = sqlite3.connect(os.path.join(os.getcwd(), "urls.sqlite3"))
- def __call__(self, req, resp):
- c = self.conn.cursor()
- c.execute("SELECT * FROM urls WHERE hash=?", (req.path.strip("/"),))
- entry = c.fetchone()
- if entry is not None:
- raise HTTPMovedPermanently(entry[2])
- raise HTTPNotFound(
- title="Resource not found",
- description="Resource not found: {}".format(req.path)
- )
+ def __call__(self, req, resp):
+ c = self.conn.cursor()
+ c.execute("SELECT * FROM urls WHERE hash=?", (req.path.strip("/"),))
+ entry = c.fetchone()
+ if entry is not None:
+ raise HTTPMovedPermanently(entry[2])
+ raise HTTPNotFound(
+ title="Resource not found",
+ description="Resource not found: {}".format(req.path)
+ )
api = API()
diff --git a/tests.py b/tests.py
index af50e80..1c59ab9 100644
--- a/tests.py
+++ b/tests.py
@@ -5,21 +5,21 @@ from shortcut.api import api
class ShortcutTest(TestCase):
- def setUp(self):
- super().setUp()
- self.app = api
+ def setUp(self):
+ super().setUp()
+ self.app = api
- def test_fail(self):
- print("test_fail")
- result = json.loads(self.simulate_get('/test').content.decode())
- self.assertEqual(result["title"], "Resource not found")
+ def test_fail(self):
+ print("test_fail")
+ result = json.loads(self.simulate_get('/test').content.decode())
+ self.assertEqual(result["title"], "Resource not found")
- @patch('shortcut.api.URLResolver.conn')
- def test_success(self, mock_conn):
- expected_url = "https://example.com/destination"
- mock_conn.cursor().fetchone.side_effect = lambda: (
- None, None, expected_url,
- )
- response = self.simulate_get('/test')
- self.assertEqual(response.status_code, 301)
- self.assertEqual(response.headers['Location'], expected_url)
+ @patch('shortcut.api.URLResolver.conn')
+ def test_success(self, mock_conn):
+ expected_url = "https://example.com/destination"
+ mock_conn.cursor().fetchone.side_effect = lambda: (
+ None, None, expected_url,
+ )
+ response = self.simulate_get('/test')
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response.headers['Location'], expected_url)