Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/unit/utils/test_utils.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
import pytest | |||||
from swh.graphql.utils import utils | from swh.graphql.utils import utils | ||||
class TestUtils: | class TestUtils: | ||||
def test_get_b64_string(self): | def test_get_b64_string(self): | ||||
assert utils.get_b64_string("testing") == "dGVzdGluZw==" | assert utils.get_b64_string("testing") == "dGVzdGluZw==" | ||||
def test_get_b64_string_binary(self): | def test_get_b64_string_binary(self): | ||||
assert utils.get_b64_string(b"testing") == "dGVzdGluZw==" | assert utils.get_b64_string(b"testing") == "dGVzdGluZw==" | ||||
def test_get_encoded_cursor_is_none(self): | def test_get_encoded_cursor_is_none(self): | ||||
assert utils.get_encoded_cursor(None) is None | assert utils.get_encoded_cursor(None) is None | ||||
def test_get_encoded_cursor(self): | def test_get_encoded_cursor(self): | ||||
assert utils.get_encoded_cursor(None) is None | assert utils.get_encoded_cursor(None) is None | ||||
assert utils.get_encoded_cursor("testing") == "dGVzdGluZw==" | assert utils.get_encoded_cursor("testing") == "dGVzdGluZw==" | ||||
def test_get_encoded_numeric_cursor(self): | |||||
assert utils.get_encoded_cursor("1003") == "VFJLSkplR1IxMDAzSkpFSEROT0hU" | |||||
def test_get_decoded_cursor_is_none(self): | def test_get_decoded_cursor_is_none(self): | ||||
assert utils.get_decoded_cursor(None) is None | assert utils.get_decoded_cursor(None) is None | ||||
def test_get_decoded_cursor(self): | def test_get_decoded_cursor(self): | ||||
assert utils.get_decoded_cursor("dGVzdGluZw==") == "testing" | assert utils.get_decoded_cursor("dGVzdGluZw==") == "testing" | ||||
def test_get_decoded_numeric_cursor(self): | |||||
assert utils.get_decoded_cursor("VFJLSkplR1IxMDAzSkpFSEROT0hU") == "1003" | |||||
@pytest.mark.parametrize("cursor", ["FOO", "00", "test"]) | |||||
def test_cursor_decode_encode_reverse(self, cursor): | |||||
assert cursor == utils.get_decoded_cursor(utils.get_encoded_cursor(cursor)) | |||||
def test_get_formatted_date(self): | def test_get_formatted_date(self): | ||||
date = datetime.datetime( | date = datetime.datetime( | ||||
2015, 8, 4, 22, 26, 14, 804009, tzinfo=datetime.timezone.utc | 2015, 8, 4, 22, 26, 14, 804009, tzinfo=datetime.timezone.utc | ||||
) | ) | ||||
assert utils.get_formatted_date(date) == "2015-08-04T22:26:14.804009+00:00" | assert utils.get_formatted_date(date) == "2015-08-04T22:26:14.804009+00:00" | ||||
def test_paginated(self): | def test_paginated(self): | ||||
source = [1, 2, 3, 4, 5] | source = [1, 2, 3, 4, 5] | ||||
Show All 25 Lines |