commit fbc97e15711752a9ec7eef9121a4910147bc9fa3
Author: Arturo Filastò <art(a)fuffa.org>
Date: Mon Aug 18 14:37:13 2014 +0200
Implement unittests for report lists.
Spot a bug and fix it.
---
ooni/reporter.py | 4 ++--
ooni/tests/test_reporter.py | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index f0f8822..e0e92c6 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -422,7 +422,7 @@ class OONIBReportLog(object):
for report_file, value in report_log.items():
if value['status'] in ('created'):
try:
- os.kill(value['pid'])
+ os.kill(value['pid'], 0)
except:
reports.append((report_file, value))
return reports
@@ -434,7 +434,7 @@ class OONIBReportLog(object):
for report_file, value in report_log.items():
if value['status'] in ('created'):
try:
- os.kill(value['pid'])
+ os.kill(value['pid'], 0)
reports.append((report_file, value))
except:
pass
diff --git a/ooni/tests/test_reporter.py b/ooni/tests/test_reporter.py
index 06659fd..9aae88c 100644
--- a/ooni/tests/test_reporter.py
+++ b/ooni/tests/test_reporter.py
@@ -161,3 +161,14 @@ class TestOONIBReportLog(unittest.TestCase):
report = yaml.safe_load(f)
assert "path_to_my_report.yaml" in report
assert report["path_to_my_report.yaml"]["status"] == "creation-failed"
+
+ @defer.inlineCallbacks
+ def test_list_reports(self):
+ yield self.report_log.creation_failed("failed_report.yaml",
+ 'httpo://foo.onion')
+ yield self.report_log.created("created_report.yaml",
+ 'httpo://foo.onion', 'XXXX')
+
+ assert len(self.report_log.reports_in_progress) == 1
+ assert len(self.report_log.reports_incomplete) == 0
+ assert len(self.report_log.reports_to_upload) == 1