2021-02-12 19:01:42 +01:00
|
|
|
import unittest
|
|
|
|
|
2021-02-16 19:10:11 +01:00
|
|
|
from ..navigation import join_url, parse_url, set_parameter
|
2021-02-12 19:01:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestNavigation(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_parse_url(self):
|
|
|
|
res = parse_url("gemini://dece.space/parse-me.gmi")
|
|
|
|
self.assertEqual(res.scheme, "gemini")
|
|
|
|
self.assertEqual(res.netloc, "dece.space")
|
|
|
|
self.assertEqual(res.path, "/parse-me.gmi")
|
|
|
|
|
|
|
|
res_netloc = parse_url("//dece.space/parse-me.gmi")
|
|
|
|
self.assertEqual(res, res_netloc)
|
|
|
|
|
|
|
|
res = parse_url("dece.space/parse-me.gmi", absolute=True)
|
|
|
|
self.assertEqual(res.scheme, "gemini")
|
|
|
|
self.assertEqual(res.netloc, "dece.space")
|
|
|
|
self.assertEqual(res.path, "/parse-me.gmi")
|
|
|
|
|
2021-02-17 01:31:24 +01:00
|
|
|
res = parse_url("https://dece.space/index.html")
|
|
|
|
self.assertEqual(res.scheme, "https")
|
|
|
|
self.assertEqual(res.netloc, "dece.space")
|
|
|
|
self.assertEqual(res.path, "/index.html")
|
|
|
|
|
2021-03-08 23:40:03 +01:00
|
|
|
res = parse_url("file:///home/dece/gemini/index.gmi")
|
|
|
|
self.assertEqual(res.scheme, "file")
|
|
|
|
self.assertEqual(res.path, "/home/dece/gemini/index.gmi")
|
|
|
|
|
2021-02-12 19:01:42 +01:00
|
|
|
def test_join_url(self):
|
2021-02-17 01:31:24 +01:00
|
|
|
url = join_url("gemini://dece.space/", "some-file.gmi")
|
|
|
|
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
|
|
|
url = join_url("gemini://dece.space/", "./some-file.gmi")
|
2021-02-12 19:01:42 +01:00
|
|
|
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
2021-02-17 01:31:24 +01:00
|
|
|
url = join_url("gemini://dece.space/dir1", "/some-file.gmi")
|
2021-02-12 19:01:42 +01:00
|
|
|
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
|
|
|
url = join_url("gemini://dece.space/dir1/file.gmi", "other-file.gmi")
|
|
|
|
self.assertEqual(url, "gemini://dece.space/dir1/other-file.gmi")
|
|
|
|
url = join_url("gemini://dece.space/dir1/file.gmi", "../top-level.gmi")
|
|
|
|
self.assertEqual(url, "gemini://dece.space/top-level.gmi")
|
2021-02-16 19:10:11 +01:00
|
|
|
|
|
|
|
def test_set_parameter(self):
|
|
|
|
url = set_parameter("gemini://gus.guru/search", "my search")
|
|
|
|
self.assertEqual(url, "gemini://gus.guru/search?my%20search")
|
|
|
|
url = set_parameter("gemini://gus.guru/search?old%20search", "new")
|
|
|
|
self.assertEqual(url, "gemini://gus.guru/search?new")
|