Repository: googleapis/google-cloud-python

Issue:
New BigQuery system tests fail on Python 3.
@tseaver One of the new BigQuery system tests consistently fails on Python 3.x:

Running `tox -e system-tests3 -- bigquery` on current master:

```
test_create_dataset (bigquery.TestBigQuery) ... ok
test_create_table (bigquery.TestBigQuery) ... ok
test_create_table_insert_fetch_nested_schema (bigquery.TestBigQuery) ... ok
test_dump_table_w_public_data (bigquery.TestBigQuery) ... ok
test_insert_data_then_dump_table (bigquery.TestBigQuery) ... _has_rows. Trying again in 1 seconds...
ok
test_insert_nested_nested (bigquery.TestBigQuery) ... ok
test_job_cancel (bigquery.TestBigQuery) ... ok
test_list_datasets (bigquery.TestBigQuery) ... ok
test_list_tables (bigquery.TestBigQuery) ... ok
test_load_table_from_local_file_then_dump_table (bigquery.TestBigQuery) ... _job_done. Trying again in 1 seconds...
_job_done. Trying again in 2 seconds...
_job_done. Trying again in 4 seconds...
ok
test_load_table_from_storage_then_dump_table (bigquery.TestBigQuery) ... _job_done. Trying again in 1 seconds...
_job_done. Trying again in 2 seconds...
ok
test_patch_dataset (bigquery.TestBigQuery) ... ok
test_patch_table (bigquery.TestBigQuery) ... ok
test_reload_dataset (bigquery.TestBigQuery) ... ok
test_sync_query_w_legacy_sql_types (bigquery.TestBigQuery) ... ok
test_sync_query_w_query_params (bigquery.TestBigQuery) ... ERROR
test_sync_query_w_standard_sql_types (bigquery.TestBigQuery) ... ok
test_update_dataset (bigquery.TestBigQuery) ... ok
test_update_table (bigquery.TestBigQuery) ... ok

======================================================================
ERROR: test_sync_query_w_query_params (bigquery.TestBigQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/google/home/lukesneeringer/Code/Google/google-cloud-python/system_tests/bigquery.py", line 770, in test_sync_query_w_query_params
    query.run()
  File "/usr/local/google/home/lukesneeringer/Code/Google/google-cloud-python/.tox/system-tests3/lib/python3.5/site-packages/google/cloud/bigquery/query.py", line 364, in run
    method='POST', path=path, data=self._build_resource())
  File "/usr/local/google/home/lukesneeringer/Code/Google/google-cloud-python/.tox/system-tests3/lib/python3.5/site-packages/google/cloud/_http.py", line 294, in api_request
    data = json.dumps(data)
  File "/usr/local/lib/python3.5/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/lib/python3.5/json/encoder.py", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.5/json/encoder.py", line 256, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.5/json/encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'REVBREJFRUY=' is not JSON serializable

----------------------------------------------------------------------
Ran 19 tests in 88.302s

FAILED (errors=1)
ERROR: InvocationError: '/usr/local/google/home/lukesneeringer/Code/Google/google-cloud-python/.tox/system-tests3/bin/python /usr/local/google/home/lukesneeringer/Code/Google/google-cloud-python/system_tests/attempt_system_tests.py bigquery'
_______________________________________________ summary ________________________________________________
ERROR:   system-tests3: commands failed
```


Discussion:
@lukesneeringer OK, should be a simple fix.
Great, thanks! I tried to fix it and was scratching my head this morning. But it was 7:00 AM, which might have been the issue.

Resolving patch:
diff --git a/bigquery/google/cloud/bigquery/_helpers.py b/bigquery/google/cloud/bigquery/_helpers.py
--- a/bigquery/google/cloud/bigquery/_helpers.py
+++ b/bigquery/google/cloud/bigquery/_helpers.py
@@ -144,7 +144,7 @@ def _bool_to_json(value):
 def _bytes_to_json(value):
     """Coerce 'value' to an JSON-compatible representation."""
     if isinstance(value, bytes):
-        value = base64.standard_b64encode(value)
+        value = base64.standard_b64encode(value).decode('ascii')
     return value
 
 


Test patch:
diff --git a/bigquery/unit_tests/test__helpers.py b/bigquery/unit_tests/test__helpers.py
--- a/bigquery/unit_tests/test__helpers.py
+++ b/bigquery/unit_tests/test__helpers.py
@@ -555,11 +555,10 @@ def test_w_non_bytes(self):
         self.assertIs(self._call_fut(non_bytes), non_bytes)
 
     def test_w_bytes(self):
-        import base64
-
         source = b'source'
-        expected = base64.standard_b64encode(source)
-        self.assertEqual(self._call_fut(source), expected)
+        expected = u'c291cmNl'
+        converted = self._call_fut(source)
+        self.assertEqual(converted, expected)
 
 
 class Test_timestamp_to_json(unittest.TestCase):