diff options
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r-- | tests/unit/test_utils.py | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index edb545b..8a98a45 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -15,23 +15,59 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import json + from gitlab import utils -def test_url_encode(): - src = "nothing_special" - dest = "nothing_special" - assert dest == utils._url_encode(src) +class TestEncodedId: + def test_init_str(self): + obj = utils.EncodedId("Hello") + assert "Hello" == str(obj) + assert "Hello" == f"{obj}" + + obj = utils.EncodedId("this/is a/path") + assert "this%2Fis%20a%2Fpath" == str(obj) + assert "this%2Fis%20a%2Fpath" == f"{obj}" + + def test_init_int(self): + obj = utils.EncodedId(23) + assert "23" == str(obj) + assert "23" == f"{obj}" + + def test_init_encodeid_str(self): + value = "Goodbye" + obj_init = utils.EncodedId(value) + obj = utils.EncodedId(obj_init) + assert value == str(obj) + assert value == f"{obj}" + assert value == obj.original_str + + value = "we got/a/path" + expected = "we%20got%2Fa%2Fpath" + obj_init = utils.EncodedId(value) + assert value == obj_init.original_str + # Show that no matter how many times we recursively call it we still only + # URL-encode it once. + obj = utils.EncodedId( + utils.EncodedId(utils.EncodedId(utils.EncodedId(utils.EncodedId(obj_init)))) + ) + assert expected == str(obj) + assert expected == f"{obj}" + # We have stored a copy of our original string + assert value == obj.original_str - src = "foo#bar/baz/" - dest = "foo%23bar%2Fbaz%2F" - assert dest == utils._url_encode(src) + def test_init_encodeid_int(self): + value = 23 + expected = f"{value}" + obj_init = utils.EncodedId(value) + obj = utils.EncodedId(obj_init) + assert expected == str(obj) + assert expected == f"{obj}" - src = "foo%bar/baz/" - dest = "foo%25bar%2Fbaz%2F" - assert dest == utils._url_encode(src) + def test_json_serializable(self): + obj = utils.EncodedId("someone") + assert '"someone"' == json.dumps(obj) - # periods/dots should not be modified - src = "docs/README.md" - dest = "docs%2FREADME.md" - assert dest == utils._url_encode(src) + obj = utils.EncodedId("we got/a/path") + assert '"we%20got%2Fa%2Fpath"' == json.dumps(obj) |