blob: b7e0bab8477067f9fafd7c5cc0913e61d0b73c4d [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
15
16import pytest
17
18from google.auth import _helpers
19
20
21def test_to_bytes_with_bytes():
22 value = b'bytes-val'
23 assert _helpers.to_bytes(value) == value
24
25
26def test_to_bytes_with_unicode():
27 value = u'string-val'
28 encoded_value = b'string-val'
29 assert _helpers.to_bytes(value) == encoded_value
30
31
32def test_to_bytes_with_nonstring_type():
33 with pytest.raises(ValueError):
34 _helpers.to_bytes(object())
35
36
37def test_from_bytes_with_unicode():
38 value = u'bytes-val'
39 assert _helpers.from_bytes(value) == value
40
41
42def test_from_bytes_with_bytes():
43 value = b'string-val'
44 decoded_value = u'string-val'
45 assert _helpers.from_bytes(value) == decoded_value
46
47
48def test_from_bytes_with_nonstring_type():
49 with pytest.raises(ValueError):
50 _helpers.from_bytes(object())