Created
October 31, 2017 15:23
-
-
Save WillianFuks/a5adbc2f865d6ca88e4261715073004c to your computer and use it in GitHub Desktop.
Testing Script to run system test against BigQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import unittest | |
from google.cloud.bigquery import Client | |
bc = Client() | |
class TestQueriesResults(unittest.TestCase): | |
def test_queries(self): | |
query = open( | |
"gae/exporter/queries/customers_interactions.sql").read().strip() | |
simulated_data = open( | |
"tests/system/data/gae/test_query_customers.sql").read().strip() | |
query = re.sub(r"`.*`", simulated_data, query) | |
query = re.sub(r"AND _TABLE_SUFFIX = '{date}'", "", query) | |
job = bc.run_sync_query(query) | |
job.use_legacy_sql = False | |
job.run() | |
# orders by user_id and then by sku | |
result = sorted(list(job.fetch_data()), key=lambda x: (x[0], x[1])) | |
expected = [(u'1', u'sku0', 1), | |
(u'1', u'sku0', 2), | |
(u'1', u'sku0', 3), | |
(u'1', u'sku1', 1), | |
(u'1', u'sku3', 1), | |
(u'2', u'sku0', 1), | |
(u'3', u'sku0', 3), | |
(u'3', u'sku1', 3)] | |
self.assertEqual(result, expected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment