From 6f05eb03f7c61036bac2ce5696a65987798b72bb Mon Sep 17 00:00:00 2001 From: Michal Migurski Date: Thu, 8 Oct 2015 18:40:34 -0700 Subject: [PATCH] Testing both front page and single set state.txt output --- openaddr/ci/webhooks.py | 4 ++-- openaddr/tests/ci.py | 45 +++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/openaddr/ci/webhooks.py b/openaddr/ci/webhooks.py index a01eec4b..85e375f7 100644 --- a/openaddr/ci/webhooks.py +++ b/openaddr/ci/webhooks.py @@ -125,7 +125,7 @@ def app_get_state_txt(): buffer = csvIO() output = csvDictWriter(buffer, CSV_HEADER, dialect='excel-tab', encoding='utf8') output.writerow({col: col for col in CSV_HEADER}) - for run in runs: + for run in sorted(runs, key=attrgetter('source_path')): run_state = run.state or {} row = {col: run_state.get(col, None) for col in CSV_HEADER} row['source'] = os.path.relpath(run.source_path, 'sources') @@ -281,7 +281,7 @@ def app_get_set_state_txt(set_id): buffer = csvIO() output = csvDictWriter(buffer, CSV_HEADER, dialect='excel-tab', encoding='utf8') output.writerow({col: col for col in CSV_HEADER}) - for run in runs: + for run in sorted(runs, key=attrgetter('source_path')): run_state = run.state or {} row = {col: run_state.get(col, None) for col in CSV_HEADER} row['source'] = os.path.relpath(run.source_path, 'sources') diff --git a/openaddr/tests/ci.py b/openaddr/tests/ci.py index e131db5c..13c41984 100644 --- a/openaddr/tests/ci.py +++ b/openaddr/tests/ci.py @@ -1073,28 +1073,29 @@ def test_get_latest_set(self): self.assertEqual(got1.status_code, 302) self.assertTrue(got1.headers.get('Location').endswith('/sets/2')) - got2 = self.client.get('/state.txt') - self.assertEqual(got2.status_code, 200) - - # El-Cheapo CSV parser. - lines = got2.data.decode('utf8').split('\r\n')[:3] - head, row1, row2 = [row.split('\t') for row in lines] - got_state1 = dict(zip(head, row1)) - got_state2 = dict(zip(head, row2)) - - for key in ('source', 'cache', 'sample', 'geometry type', 'address count', - 'version', 'fingerprint', 'cache time', 'processed', 'output', - 'process time', 'attribution required', 'attribution name'): - self.assertIn(key, got_state1) - self.assertIn(key, got_state2) - - for (key, value) in got_state1.items(): - if key in run_state1: - self.assertEqual(value, run_state1[key]) - - for (key, value) in got_state2.items(): - if key in run_state2: - self.assertEqual(value, run_state2[key]) + for path in ('/state.txt', '/sets/2/state.txt'): + got2 = self.client.get(path) + self.assertEqual(got2.status_code, 200) + + # El-Cheapo CSV parser. + lines = got2.data.decode('utf8').split('\r\n')[:3] + head, row1, row2 = [row.split('\t') for row in lines] + got_state1 = dict(zip(head, row1)) + got_state2 = dict(zip(head, row2)) + + for key in ('source', 'cache', 'sample', 'geometry type', 'address count', + 'version', 'fingerprint', 'cache time', 'processed', 'output', + 'process time', 'attribution required', 'attribution name'): + self.assertIn(key, got_state1) + self.assertIn(key, got_state2) + + for (key, value) in got_state1.items(): + if key in run_state1: + self.assertEqual(value, run_state1[key]) + + for (key, value) in got_state2.items(): + if key in run_state2: + self.assertEqual(value, run_state2[key]) class TestRuns (unittest.TestCase):