Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Testing both front page and single set state.txt output
Browse files Browse the repository at this point in the history
  • Loading branch information
migurski committed Oct 9, 2015
1 parent 4aa11fc commit 6f05eb0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions openaddr/ci/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
45 changes: 23 additions & 22 deletions openaddr/tests/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 6f05eb0

Please sign in to comment.