Repository: RockefellerArchiveCenter/DACSspace

Issue:
Add the number of errors per resource to the csv
When a resource has many missing fields, it would be useful to know how many required fields are missing. 

To do this, we should add the number of validation errors to a column in the .csv

- Add the number of validation errors, as an integer, to the dictionary that is created inside the validator.py
- Make sure this new column is reflected in field names listed in the reporter.py 


Discussion:

Patch:
diff --git a/dacsspace/reporter.py b/dacsspace/reporter.py
index 67bec10..6d79184 100644
--- a/dacsspace/reporter.py
+++ b/dacsspace/reporter.py
@@ -23,6 +23,7 @@ class CSVReporter:
             fieldnames = [
                 "uri",
                 "valid",
+                "error_count",
                 "explanation"]
             writer = csv.DictWriter(
                 f, fieldnames=fieldnames)
diff --git a/dacsspace/validator.py b/dacsspace/validator.py
index 7d47839..dc5b0c8 100644
--- a/dacsspace/validator.py
+++ b/dacsspace/validator.py
@@ -29,15 +29,16 @@ class Validator:
 
         Returns:
            result (dict): The result of the validation. An dictionary with the
-           object's URI, a boolean indication of the validation result and, if
+           object's URI, a boolean indication of the validation result, an integer representation of the number of validation errors, and, if
            necessary, an explanation of any validation errors.
 
-           { "uri": "/repositories/2/resources/1234", "valid": False, "explanation": "You are missing the following fields..." }
+           { "uri": "/repositories/2/resources/1234", "valid": False, "error_count": 1, "explanation": "You are missing the following fields..." }
         """
         validator = self.validator(self.schema)
         errors_found = [error.message for error in validator.iter_errors(data)]
         if len(errors_found):
-            return {"uri": data["uri"], "valid": False,
+            return {"uri": data["uri"], "valid": False, "error_count": len(errors_found),
                     "explanation": "\n".join(errors_found)}
         else:
-            return {"uri": data["uri"], "valid": True}
+            return {"uri": data["uri"], "valid": True,
+                    "error_count": 0, "explanation": None}


Test patch:
diff --git a/tests/test_reporter.py b/tests/test_reporter.py
index 4e1d134..eb39c79 100644
--- a/tests/test_reporter.py
+++ b/tests/test_reporter.py
@@ -13,8 +13,8 @@ class CSVReporterTest(TestCase):
         Checks if test file exists, then deletes it.
         """
         self.filename = "DACSSpace_results"
-        self.results = [{"valid": True, "explanation": None},
-                        {"valid": False, "explanation": "No title"}]
+        self.results = [{"valid": True, "error_count": 0, "explanation": None},
+                        {"valid": False, "error_count": 1, "explanation": "No title"}]
         if os.path.isfile(self.filename):
             os.remove(self.filename)
 
@@ -35,7 +35,7 @@ class CSVReporterTest(TestCase):
         """Mocks writing only invalid results and valid results to file."""
         CSVReporter(self.filename).write_report(self.results)
         mock_writerows.assert_called_with(
-            [{"valid": False, "explanation": "No title"}])
+            [{"valid": False, "error_count": 1, "explanation": "No title"}])
         CSVReporter(
             self.filename).write_report(
             self.results,
diff --git a/tests/test_validator.py b/tests/test_validator.py
index 0e07b89..444a6e8 100644
--- a/tests/test_validator.py
+++ b/tests/test_validator.py
@@ -55,6 +55,8 @@ class TestValidator(unittest.TestCase):
                 result = Validator(schema, None).validate_data(data)
             self.assertTrue(isinstance(result, dict))
             self.assertEqual(result["valid"], valid, result)
+            self.assertTrue(len(result.keys()) == 4)
+            self.assertTrue(isinstance(result["error_count"], int))
 
     def test_single_level_required_schema(self):
         """Asserts that the single_level_required schema validates fixtures as expected."""