reciprocity/ggrc-core — pull request #443 by danring (2013-10-16 19:04:07+00:00)
Title: Import unittests

Moved import unit tests to a new branch; this one is more complete.

Functionality added:

- Importer now recognizes the format YYYY-MM-DD (i.e. with dashes instead of slashes); test coverage added for sheets with this format.
- Throws an error if a non-dry-run sheet import has errors (which would require the user to bypass the interface's rejection and so is only a "last ditch" catch).

From Silas' original pull request:

Tests added:

- `test_import`: checks that
-- imported controls will update the database as indicated
-- invalid dates (if forced through as a non-dry-run) will make no change to the database
-- imported sheets whose directive slug does not match anything in the database will raise an ImportException
-- imported sheets using UTF8-incompatible encodings will raise an ImportException
-- imports from csvs trigger a write to the event log
-- imports from sheets update the fulltext search with their titles

- `test_export`: checks that
-- a known database state, when exported, matches a reference spreadsheet on a cell-wise comparison (see `helpers.py`, below

- `test_consistency`: checks that
-- a csv that is imported (adding controls to a directive without any) and then re-exported, then looks the same as the original import *except* for the Created/Updated fields

- `test_helper`: checks that
-- the help function `compare_csvs` will correctly return true if two `AbstractCSV`s have the same cells except for time-varying ones, and will ignore differences in such time-varying cells (see helper below)

Helper added (file `helper.py`):

- `AbstractCSV`: represents a csv passed to its constructor as a nested list of cells to facilitate comparison
- `compare_csvs`: a function for comparing two csvs in a way that ignores time-varying columns (in this case, the Created/Updated fields)