[#1879] Set DataStore to legacy mode when using PostgreSQL < 9.x

Up until now the user had to actively set legacy mode when running PG
8.x, and if not you could end up with the full datastore running on an
old postgres version. Features like the SQL search are not properly
supported on these versions, so we need to explicitly disable them when
running on PG 8.x, by setting `legacy_mode` to True.

The current behaviour is that legacy mode will be activated if
`ckan.datastore.read_url` is not present in the configuration and/or
postgres < 9.x.
[#1879] Fix tests

The travis setup explicitly removes the `ckan.datastore.read_url`
setting when running the tests, so we need to use a dummy one.

Also some refactoring
[#1871] Add function to extract table names from SQL statement

The function performs an EXPLAIN query with the provided statement and
parses its output looking for table names. It requires Postgres >= 9.x,
as it uses the FORMAT JSON option to get and parse a JSON objects.
 [#1871] Disallow DataStore SQL queries involving system tables

 Using the `get_table_names_from_sql` helper function before running the
 provided statement, we raise a Validation error if some of the tables
 start with `pg_`.
[#1871] Fix tests

PEP9 and skip the get table names tests if running on legacy mode.

Conflicts:
	ckanext/datastore/tests/test_helpers.py
[#1871] Fix wrong call in tests
[#1902] Don't show private datasets to group members

1. User Sean creates organization my-org
2. Sean adds private dataset my-dataset to my-org
3. Sean creates group my-group
4. Sean adds private dataset my-dataset to my-group
5. Sean adds user Fred to my-group
6. The group_show API will now show the private dataset my-dataset to
   Fred, even though Fred is not a member of my-org.

For some reason the private dataset does not show on the group's page,
but it does show in ther API.

This commit removes it from the API.

If backported this commit will also fix a problem present on 2.2 and
2.2.1 (but not master) that after following the steps above Fred will
see the private dataset on the site front page.

Arguably you should not be able to add private datasets to groups at
all, but you could add a public dataset to a group and then make the
dataset private and it would still belong to the group, so we do need to
filter private datasets out of groups.

Conflicts:
	ckan/lib/dictization/model_dictize.py
[#1902] Test that group_show() doesn't show private datasets

Conflicts:
	ckan/new_tests/logic/action/test_get.py
[#1902] PEP8
Update test factories with the latest version from master

Otherwise is really difficult to keep tests on this branch up to date
[#1697] Don't break PEP8 tests if test files have lines >79 chars

According to naming test methods [1] in our testing coding standards, we should
make the test names clear "...even if it means your method name gets really
long, since we don’t write code that calls our test methods there’s no
advantage to having short test method names".  Given this, we shouldn't
validate E501 on our test suite.

[1] https://ckan.readthedocs.org/en/latest/contributing/testing.html#naming-test-methods
[#1697] Revert blacklisted files removed in cc7e917

They still fail even without validating E501.
[#1697] Unblacklist test files that are passing PEP8
[#1697] Fix minor PEP8 issues
[#1697] Add comment explaining why we're ignoring E501 on tests
[#1745] remove lie about python 3 string formatting
[#1745] nothing wrong with from module import name
[#1745] recommend from module import name
[#1745] add importing diagram to imports section of coding guidelines