learningequality/ka-lite — pull request #2576 by cpauya (2014-11-03 10:24:25+00:00)
Title: Feature/2417 add a base test suite for ka lite

Hi @aronasorman

This is for #2417 based on `develop` branch and is still a WIP.

**Done**

1. Made `basetests` app and created a `DependenciesTests` base class.
1. Added `unittest2` and the `six` packages.
1. Customized the output so we display the message for the test then the status of "OK" or "FAIL" at the end, the `print` and `logging` modules appends a `\n` (newline character) so I had to create custom logging class methods.
1. Some unit tests completed
1. test if sqlite is installed
1. test minimum sqlite version
1. test sqlite path is writable
1. test django is installed
1. test django version
1. test minimum python version

**To Use**

To run the `unittest2` tests
> $ python kalite/basetests/dependencies.py

Here's an example output

```bash
cyril-lappy6:ka-lite-src cyril$ python kalite/basetests/dependencies.py
Testing if SQLite3 is installed...OK!
Testing minimum SQLite3 version 3.3.6 for Django version 1.5.1...OK!
Testing writable SQLite3 database "/Users/cyril/w/fle/ka-lite/ka-lite-src/kalite/database/data.sqlite"...OK!
Testing if Django is installed...OK!
Testing Django 1.5.1 version...OK!
Testing minimum Python version 2.6.5 for Django version 1.5.1...OK!
Testing read-only access to content folder "/Users/cyril/w/fle/ka-lite/ka-lite-src/content"...OK!
Testing writable SQLite3 database "/Users/cyril/w/fle/ka-lite/ka-lite-src/kalite/database/data.sqlite"...OK!
======================================================================
FAIL: test_exercise_json (__main__.PathsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "kalite/basetests/dependencies.py", line 177, in test_exercise_json
self.assertTrue(False)
AssertionError: False is not true

======================================================================
FAIL: test_packages_are_installed (__main__.PackagesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "kalite/basetests/dependencies.py", line 149, in test_packages_are_installed
self.assertTrue(False)
AssertionError: False is not true

======================================================================
FAIL: test_packages_version (__main__.PackagesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "kalite/basetests/dependencies.py", line 153, in test_packages_version
self.assertTrue(False)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 11 tests in 8.641s

FAILED (failures=3)
```

To run the management command (WIP)
> $ python manage.py check_dependencies

**ToDos**

1. More unit tests:
1. test if django can serve on production port
1. test packages
1. test packages versions and dependencies
1. test paths to json files like `exercise.json`
1. platform-specific tests (ie: `psutil`)
1. Refactor the `check_dependencies` management command based on the `DependenciesTests` class.

**Questions**

1. Can you please elaborate the other paths that we need to test and their equivalent access permissions (read-only, write-access, etc)?
1. Do I need to test for dependencies between packages? Any pointers to facilitate the checks like do we have some docs for it? If none, no worries, will just look in the source. :)
1. Any details/plans for the cross-platform irks we need to watch-out?
1. I plan to refactor the management command so it just calls the `unittest2` tests. Is that okay?

/cc: @jamalex