blob: c2bc4a7331bd3996fc56b0efee239320549dfa79 [file] [log] [blame]
Jon Wayne Parrott8713a712016-10-04 14:19:01 -07001# Copyright 2016 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Jon Wayne Parrott5824ad82016-10-06 09:27:44 -070015import datetime
Jon Wayne Parrott8713a712016-10-04 14:19:01 -070016
17import pytest
18
19from google.auth import _helpers
20
21
Jon Wayne Parrott5824ad82016-10-06 09:27:44 -070022def test_utcnow():
23 assert isinstance(_helpers.utcnow(), datetime.datetime)
24
25
26def test_datetime_to_secs():
27 assert _helpers.datetime_to_secs(
28 datetime.datetime(1970, 1, 1)) == 0
29 assert _helpers.datetime_to_secs(
30 datetime.datetime(1990, 5, 29)) == 643939200
31
32
Jon Wayne Parrott8713a712016-10-04 14:19:01 -070033def test_to_bytes_with_bytes():
34 value = b'bytes-val'
35 assert _helpers.to_bytes(value) == value
36
37
38def test_to_bytes_with_unicode():
39 value = u'string-val'
40 encoded_value = b'string-val'
41 assert _helpers.to_bytes(value) == encoded_value
42
43
44def test_to_bytes_with_nonstring_type():
45 with pytest.raises(ValueError):
46 _helpers.to_bytes(object())
47
48
49def test_from_bytes_with_unicode():
50 value = u'bytes-val'
51 assert _helpers.from_bytes(value) == value
52
53
54def test_from_bytes_with_bytes():
55 value = b'string-val'
56 decoded_value = u'string-val'
57 assert _helpers.from_bytes(value) == decoded_value
58
59
60def test_from_bytes_with_nonstring_type():
61 with pytest.raises(ValueError):
62 _helpers.from_bytes(object())