Improve ICANN reporting golden query test

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159570806
This commit is contained in:
nickfelt 2017-06-20 09:29:39 -07:00 committed by Ben McIlwain
parent e94ba8d2af
commit d05151b026
2 changed files with 17 additions and 4 deletions

View file

@ -14,6 +14,7 @@
"""Tests for google.registry.reporting.icann_report_query_builder."""
import logging
import os
import unittest
@ -35,10 +36,20 @@ class IcannReportQueryBuilderTest(unittest.TestCase):
golden_activity_query_path = os.path.join(self.testdata_path,
'golden_activity_query.sql')
with open(golden_activity_query_path, 'r') as golden_activity_query:
self.assertMultiLineEqual(golden_activity_query.read(),
query_builder.BuildActivityReportQuery(
month='2016-06',
registrar_count=None))
golden_file_contents = golden_activity_query.read()
# Remove golden file copyright header by stripping until END OF HEADER.
golden_file_sql = golden_file_contents.split('-- END OF HEADER\n')[1]
actual_sql = query_builder.BuildActivityReportQuery(
month='2016-06', registrar_count=None)
try:
self.assertMultiLineEqual(golden_file_sql, actual_sql)
except AssertionError as e:
# Print the actual SQL generated so that it's easy to copy-paste into
# the golden file when updating the query.
sep = '=' * 50 + '\n'
logging.warning(
'Generated activity query SQL:\n' + sep + actual_sql + sep)
raise e
def testStringTrailingWhitespaceFromLines(self):
def do_test(expected, original):

View file

@ -12,6 +12,8 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- END OF HEADER
SELECT
Tld.tld AS tld,
SUM(IF(metricName = 'operational-registrars', count, 0)) AS operational_registrars,