Skip to content

Commit

Permalink
unittest for url
Browse files Browse the repository at this point in the history
  • Loading branch information
by46 committed Dec 3, 2015
1 parent 146812b commit 8c33e31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 6 additions & 2 deletions simplekit/url/url.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import six
from six.moves import urllib

import util
from .path import Path
from .query import Query

import util

__author__ = 'benjamin.c.yan'

SAFE_SEGMENT_CHARS = ":@-._~!$&'()*+,;="
Expand All @@ -17,6 +16,7 @@
'https': 443,
}


class URL(object):
def __init__(self, url):
self._host = self._port = None
Expand Down Expand Up @@ -50,6 +50,10 @@ def scheme(self, scheme):
def netloc(self):
return self._netloc

@netloc.setter
def netloc(self, value):
self._netloc = value

@property
def url(self):
return str(self)
Expand Down
16 changes: 11 additions & 5 deletions tests/url_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
class UrlTestCase(unittest.TestCase):
def test_join_path_segments(self):
tests = [(['a'], ['b'], ['a', 'b']),
(['a', ''], ['b'], ['a', 'b']),
(['a'], ['', 'b'], ['a', 'b']),
(['a', ''], ['', 'b'], ['a', '', 'b']),
(['a', 'b'], ['c', 'd'], ['a', 'b', 'c', 'd'])]
(['a', ''], ['b'], ['a', 'b']),
(['a'], ['', 'b'], ['a', 'b']),
(['a', ''], ['', 'b'], ['a', '', 'b']),
(['a', 'b'], ['c', 'd'], ['a', 'b', 'c', 'd'])]
for base, segments, expected in tests:
actual = url.join_path_segments(base, segments)
self.assertListEqual(expected, actual)
Expand All @@ -24,4 +24,10 @@ def test_remove_path_segments(self):
def test_url(self):
raw = 'http://www.google.com.hk/search?title=benjamin&age=27#/target'
u = url.URL(raw)
self.assertEqual(raw, u.url)
self.assertEqual(raw, u.url)
u.netloc = 'www.google.com'
self.assertEqual(raw.replace('.hk', ''), u.url)
u.query.add(dict(name='wendy', high=175))

raw = 'http://www.google.com/search?title=benjamin&age=27&high=175&name=wendy#/target'
self.assertEqual(raw, u.url)

0 comments on commit 8c33e31

Please sign in to comment.