Commit Graph

37 Commits

Author SHA1 Message Date
Arik Fraimovich
2dff8b9a00
Black support for the Python codebase (#4297)
* Apply black formatting

* Add auto formatting when committing to master

* Update CONTRIBUTING.md re. Black & Prettier
2019-12-11 13:54:29 +02:00
Nicolas Le Manchet
246eca1121 Migrate the application to Python 3 (#4251)
* Make core app compatible with Python 3

No backward compatibility with Python 2.7 is kept.
This commit mostly contains changes made with 2to3 and manual
tweaking when necessary.

* Use Python 3.7 as base docker image

Since it is not possible to change redash/base:debian to Python 3
without breaking future relases, its Dockerfile is temporarly
copied here.

* Upgrade some requirements to newest versions

Some of the older versions were not compatible with Python 3.

* Migrate tests to Python 3

* Build frontend on Python 3

* Make the HMAC sign function compatible with Python 3

In Python 3, HMAC only works with bytes so the strings and the
float used in the sign function need to be encoded.
Hopefully this is still backward compatible with already generated
signatures.

* Use assertCountEqual instead of assertItemsEqual

The latter is not available in Python 3.
See https://bugs.python.org/issue17866

* Remove redundant encoding header for Python 3 modules

* Remove redundant string encoding in CLI

* Rename list() functions in CLI

These functions shadow the builtin list function which is
problematic since 2to3 adds a fair amount of calls to the builtin
list when it finds dict.keys() and dict.values().

Only the Python function is renamed, from the perspective of the
CLI nothing changes.

* Replace usage of Exception.message in CLI

`message` is not available anymore, instead use the string
representation of the exception.

* Adapt test handlers to Python 3

* Fix test that relied on dict ordering

* Make sure test results are always uploaded (#4215)

* Support encoding memoryview to JSON

psycopg2 returns `buffer` objects in Python 2.7 and `memoryview`
in Python 3. See #3156

* Fix test relying on object address ordering

* Decode bytes returned from Redis

* Stop using e.message for most exceptions

Exception.message is not available in Python 3 anymore, except
for some exceptions defined by third-party libraries.

* Fix writing XLSX files in Python 3

The buffer for the file should be made of bytes and the actual
content written to it strings.

Note: I do not know why the diff is so large as it's only a two
lines change. Probably a white space or file encoding issue.

* Fix test by comparing strings to strings

* Fix another exception message unavailable in Python 3

* Fix export to CSV in Python 3

The UnicodeWriter is not used anymore. In Python 3, the interface
provided by the CSV module only deals with strings, in and out.
The encoding of the output is left to the user, in our case
it is given to Flask via `make_response`.

* (Python 3) Use Redis' decode_responses=True option (#4232)

* Fix test_outdated_queries_works_scheduled_queries_tracker (use utcnow)

* Make sure Redis connection uses decoded_responses option

* Remove unused imports.

* Use Redis' decode_responses option

* Remove cases of explicit Redis decoding

* Rename helper function and make sure it doesn't apply twice.

* Don't add decode_responses to Celery Redis connection URL

* Fix displaying error while connecting to SQLite

The exception message is always a string in Python 3, so no
need to try to decode things.

* Fix another missing exception message

* Handle JSON encoding for datasources returning bytes

SimpleJSON assumes the bytes it receives contain text data, so it
tries to UTF-8 encode them. It is sometimes not true, for instance
the SQLite datasource returns bytes for BLOB types, which typically
do not contain text but truly binary data.

This commit disables SimpleJSON auto encoding of bytes to str and
instead uses the same method as for memoryviews: generating a
hex representation of the data.

* Fix Python 3 compatibility with RQ

* Revert some changes 2to3 tends to do (#4261)

- Revert some changes 2to3 tends to do when it errs on the side of caution regarding dict view objects.

- Also fixed some naming issues with one character variables in list comprehensions.

- Fix Flask warning.

* Upgrade dependencies

* Remove useless `iter` added by 2to3

* Fix get_next_path tests (#4280)

* Removed setting SERVER_NAME in tests setup to avoid a warning.

* Change get_next_path to not return empty string in case of a domain only value.

* Fix redirect tests:

Since version 0.15 of Werkzeug it uses full path for fixing the location header instead of the root path.

* Remove explicit dependency for Werkzeug

* Switched pytz and certifi to unbinded versions.

* Switch to new library for getting country from IP

`python-geoip-geolite2` is not compatible with Python 3, instead
use `maxminddb-geolite2` which is very similar as it includes
the geolite2 database in the package .

* Python 3 RQ modifications (#4281)

* show current worker job (alongside with minor cosmetic column tweaks)

* avoid loading entire job data for queued jobs

* track general RQ queues (default, periodic and schemas)

* get all active RQ queues

* call get_celery_queues in another place

* merge dicts the Python 3 way

* extend the result_ttl of refresh_queries to 600 seconds to allow it to continue running periodically even after longer executions

* Remove legacy Python flake8 tests
2019-10-24 12:42:13 +03:00
Jannis Leidel
aa9d2466cd
Split redash/__init__.py to prevent import time side-effects. (#3601)
## What type of PR is this? (check all applicable)
<!-- Please leave only what's applicable -->

- [x] Refactor
- [x] Bug Fix

## Description

This basically makes sure that when import the redash package we don't accidentally trigger import-time side-effects such as requiring Redis.

Refs #3569 and #3466.
2019-04-18 18:39:38 +02:00
Arik Fraimovich
e485c964c5
Add rate limits to user creation/update (#3709)
* Add rate limits for user resources.

* Disable rate limiting in tests (except for tests that need it).

* Update strings to unicode to avoid SQLA warnings
2019-04-15 13:58:30 +03:00
Gabriel Dutra
70d4c724c2
Add env var to skip Flask rate limits (#3622) 2019-03-25 13:15:20 -03:00
Omer Lachish
c426c826f7 fix tests that rely on sessions 2018-12-10 12:27:39 +02:00
Jannis Leidel
c2429e92d2
Consistently use simplejson to loading and dumping JSON. (#2817)
* Consistently use simplejson to loading and dumping JSON.

This introduces the new functions redash.utils.json_dumps and redash.utils.json_loads and simplifies the custom encoder setup.

UUIDs are now handled by the default encoder, too.

Fixes #2807.

Use string comparison in parse_boolean instead of the (simple)json module.
2018-10-09 15:38:06 +02:00
Jannis Leidel
b1f5d60460 Minor code smell cleanup. (#2820)
* Remove unused parse_db_url function.

* Fix tests to not show command line warnings anymore.

* Minor code smell cleanup.

Removing unneeded imports fixing PEP8 issues.
2018-09-16 09:43:44 +03:00
Jannis Leidel
2af926703a
Implement server side sorting and new search.
- Redirect the old search API handler.
- Sort by specific database columns or relationships.
- Allow showing “my” queries per tag as well.
2018-07-18 22:55:19 +02:00
Sami Jaktholm
a96b0b6e4c feat: make trusted header authentication compatible with multiorg mode
The previous implementation of remote header login did not
support the multiorg mode of Re:Dash. These changes modify
the trusted header authentication to expose a per-organization
login endpoint that logs users in the specified organization.

The feature itself is not that interesting as multiorg is pretty
much impossible to use in a standalone Re:Dash installation. What's
more interesting is that all tests are executed in multiorg mode. It's
not possible to write tests for the trusted header authentication if
the method does not support multiorg mode.

To make benefits of these changes more concrete, some tests were
written to test the basic functionality of trusted header
authentication.
2018-02-02 20:17:53 +02:00
Arik Fraimovich
7cc97fafdb Add tests entry point to docker 2017-01-22 13:28:46 +02:00
Allen Short
c2378d837a test_handlers passes 2016-12-07 02:13:20 -06:00
Arik Fraimovich
04447e0df6 Fix: connections leaking during tests. 2016-12-07 02:13:20 -06:00
Arik Fraimovich
55cb3747ed Use db.drop_all/create_all directly 2016-12-07 02:13:20 -06:00
Arik Fraimovich
2bff12b376 Update all tests to use the same test_client 2016-12-07 02:13:20 -06:00
Arik Fraimovich
b390cd2e3d Close DB connection between tests.
Otherwise we were running out of connections.
2016-12-07 02:13:20 -06:00
Allen Short
24217d969e schema for sqlalchemy, basic test support 2016-12-07 02:13:20 -06:00
Arik Fraimovich
edea6f3a05 WIP:
- Move version/change tracking logic to mixins (the change mixin is still WIP).
- Tests for queries update API.
2016-10-24 16:58:30 +03:00
Arik Fraimovich
c12b059d10 Add API to trigger query refresh and support for parameters. 2016-02-22 10:40:46 +02:00
Arik Fraimovich
7c6b95e71d Change multi-org implementation:
To avoid complications with how Google Auth works, when enabling organization
multi-tenancy on a single instance, each organization becomes a "sub folder"
instead of a sub-domain.
2016-01-04 00:03:49 +02:00
Arik Fraimovich
f7b57fa580 Feature: new permissions system
This is one huge change for the permissions system and related:

* (Backward incompatible:) Remove the table based permissions in favour of the new model.
* Manage permission to view or query datasources based on groups.
* Add the concept of Organization. It's irrelevant for most deployments, but allows for
  multi-tenant support in re:dash.
* Replace ActivityLog with Event based rows (old data in activity_log table is retained).
* Enforce permissions on the server-side. There were some permissions that were only enforced
  on the client side. This is no more. All permissions are enforced by the server.
* Added new permission: 'super-admin' to access the status and Flask-Admin interface.
* Make sure that html is never cached by the browser - this is to make sure that the browser
  will always ask for the new Javascript/CSS resources (if such are available).
2015-12-31 10:43:33 +02:00
Arik Fraimovich
6e28f949fb Merge pull request #725 from akariv/master
Fix: Google OAuth - support for next
2015-12-28 12:07:34 +02:00
Adam Kariv
a9ccfb8b42 Fix next for Google oauth 2015-12-27 13:48:59 +02:00
Arik Fraimovich
200131bb45 Silence metrics collection in tests. 2015-12-27 09:43:36 +02:00
Arik Fraimovich
aaac5928c4 Fix: tests w/ celery breaking 2015-09-06 10:15:26 +03:00
Arik Fraimovich
6ff6bdad9f Use the correct redis connection in tests 2015-04-02 11:25:42 +03:00
Arik Fraimovich
1fe4f291f2 Flush test redis db after each test 2015-04-02 11:25:22 +03:00
Arik Fraimovich
ad1b9b06cf Fix test. 2015-03-22 14:42:08 +02:00
Arik Fraimovich
4af979d3eb Split __init__ into several modules and remove flask-peewee dependency.
This should make imports more sensible and with less side effects. Also might reduce the memory footprint of the workers.
2014-05-18 10:19:07 +03:00
Arik Fraimovich
dad9eb21a0 Create user groups in test setup. 2014-05-13 18:29:59 +03:00
Arik Fraimovich
21e02ee04e Reduce Peewee's logging level to INFO in tests. 2014-03-20 19:45:16 +02:00
Arik Fraimovich
b0d6ce61b0 Fix tests 2014-02-22 14:52:04 +02:00
Arik Fraimovich
84ec26f648 Tests for HMAC authentication. 2014-02-09 18:51:04 +02:00
Arik Fraimovich
44a95c4888 Use same database name in tests as CircleCI (until we add config for tests). 2014-02-06 21:02:13 +02:00
Arik Fraimovich
8dad478a19 Factories for all models for tests. 2014-02-06 21:02:13 +02:00
Arik Fraimovich
1e4f70747b More tests (Dasboard API). 2014-02-06 20:56:00 +02:00
Arik Fraimovich
e97d3172eb Initial version of tests. 2014-02-06 20:55:14 +02:00