-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress information for background tasks (#493)
* Add progress to search index * Remove test due to issues with celery/pytest * Do not fail on unserializable results
- Loading branch information
1 parent
420b2a5
commit 7da26ec
Showing
4 changed files
with
70 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1010,69 +1010,3 @@ def test_create_owner(self): | |
assert get_number_users() == 1 | ||
rv = self.client.get(f"{BASE_URL}/token/create_owner/") | ||
assert rv.status_code == 405 | ||
|
||
|
||
@pytest.mark.usefixtures("celery_session_app") | ||
@pytest.mark.usefixtures("celery_session_worker") | ||
class TestUserCelery(unittest.TestCase): | ||
"""Test cases for the /api/user endpoints, using celery.""" | ||
|
||
def setUp(self): | ||
self.name = "Test Web API" | ||
self.dbman = CLIDbManager(DbState()) | ||
dbpath, _name = self.dbman.create_new_db_cli(self.name, dbid="sqlite") | ||
self.tree = os.path.basename(dbpath) | ||
with patch.dict("os.environ", {ENV_CONFIG_FILE: TEST_AUTH_CONFIG}): | ||
self.app = create_app( | ||
config={ | ||
"TESTING": True, | ||
"RATELIMIT_ENABLED": False, | ||
"CELERY_CONFIG": { | ||
"broker_url": "redis://", | ||
"result_backend": "redis://", | ||
}, | ||
} | ||
) | ||
self.client = self.app.test_client() | ||
with self.app.app_context(): | ||
user_db.create_all() | ||
add_user( | ||
name="user", | ||
password="123", | ||
email="[email protected]", | ||
role=ROLE_MEMBER, | ||
tree=self.tree, | ||
) | ||
add_user( | ||
name="owner", | ||
password="123", | ||
email="[email protected]", | ||
role=ROLE_OWNER, | ||
tree=self.tree, | ||
) | ||
self.assertTrue(self.app.testing) | ||
self.ctx = self.app.test_request_context() | ||
self.ctx.push() | ||
|
||
def tearDown(self): | ||
self.ctx.pop() | ||
self.dbman.remove_database(self.name) | ||
|
||
def test_reset_password_celery(self): | ||
rv = self.client.post(BASE_URL + "/users/user/password/reset/trigger/") | ||
assert rv.status_code == 202 | ||
assert "task" in rv.json | ||
url = rv.json["task"]["href"] | ||
rv = self.client.post( | ||
BASE_URL + "/token/", json={"username": "user", "password": "123"} | ||
) | ||
assert rv.status_code == 200 | ||
token = rv.json["access_token"] | ||
from time import sleep | ||
|
||
sleep(5) | ||
rv = self.client.get( | ||
url, | ||
headers={"Authorization": f"Bearer {token}"}, | ||
) | ||
assert rv.status_code == 200 |