Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaFaer committed Mar 12, 2020
1 parent b01c801 commit f56440b
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 8,047 deletions.
2 changes: 1 addition & 1 deletion google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def generate_signed_post_policy(
)
str_to_sign = base64.b64encode(policy.encode("utf-8"))

signature_bytes = self._credentials.sign_bytes(str_to_sign.encode("ascii"))
signature_bytes = self._credentials.sign_bytes(str_to_sign)
signature = binascii.hexlify(signature_bytes).decode("ascii")

timestamp, datestamp = get_v4_dtstamps()
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test__signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,22 @@ def test_bytes(self):
self.assertEqual(encoded_param, "bytes")


class TestV4Stamps(unittest.TestCase):
def test_get_v4_dtstamps(self):
import datetime
from google.cloud.storage._signing import get_v4_dtstamps

with mock.patch(
"google.cloud.storage._signing.NOW",
return_value=datetime.datetime(2020, 3, 12, 13, 14, 15),
) as now_mock:
timestamp, datestamp = get_v4_dtstamps()
now_mock.assert_called_once()

self.assertEqual(timestamp, "20200312T131415Z")
self.assertEqual(datestamp, "20200312")


_DUMMY_SERVICE_ACCOUNT = None


Expand Down

0 comments on commit f56440b

Please sign in to comment.