Skip to content

Commit 3b0d40c

Browse files
committed
Make utils module a package
Following the same directory structure as the JavaScript version.
1 parent e755ed2 commit 3b0d40c

File tree

8 files changed

+37
-46
lines changed

8 files changed

+37
-46
lines changed

src/graphql_relay/connection/arrayconnection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import binascii
22

3-
from ..utils import base64, unbase64
3+
from ..utils.base64 import base64, unbase64
44
from .connectiontypes import Connection, PageInfo, Edge
55

66

src/graphql_relay/node/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql_relay.utils import base64, unbase64
1+
from graphql_relay.utils.base64 import base64, unbase64
22

33
from graphql.type import (
44
GraphQLArgument,

src/graphql_relay/utils.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/graphql_relay/utils/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""graphql_relay.utils"""
2+
3+
4+
def resolve_maybe_thunk(f): # TODO: do we need that?
5+
return f() if callable(f) else f
6+

src/graphql_relay/utils/base64.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from base64 import b64encode, b64decode
2+
3+
__all__ = ['base64', 'unbase64']
4+
5+
6+
def base64(s: str) -> str:
7+
""""Encode the string s using Base64."""
8+
return b64encode(s.encode('utf-8')).decode('utf-8')
9+
10+
11+
def unbase64(s: str) -> str:
12+
""""Decode the string s using Base64."""
13+
return b64decode(s).decode('utf-8')

tests/test_utils.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for graphql_relay.utils"""

tests/utils/test_base64.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import base64
2+
3+
from graphql_relay.utils.base64 import base64, unbase64
4+
5+
6+
example_unicode = 'Some examples: ❤😀'
7+
example_base64 = 'U29tZSBleGFtcGxlczog4p2k8J+YgA=='
8+
9+
10+
def test_converts_from_unicode_to_base64():
11+
assert base64(example_unicode) == example_base64
12+
13+
14+
def test_converts_from_base_64_to_unicode():
15+
assert unbase64(example_base64) == example_unicode

0 commit comments

Comments
 (0)