-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add statistics on the homepage (#20)
cache this part of the homepage for 30s using caching lib. Be careful to not cache full page, otherwise username will not be updated when login Bug: T204157
- Loading branch information
Showing
6 changed files
with
62 additions
and
8 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 |
---|---|---|
|
@@ -30,3 +30,4 @@ xlsxwriter==3.0.3 | |
importlib-metadata==4.6.3 | ||
zipp==3.5.0 | ||
typing-extensions==3.10.0.0 | ||
flask_caching==2.0.2 |
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 |
---|---|---|
@@ -1,5 +1,37 @@ | ||
def test_frontpage(client, redisdb): | ||
rv = client.get("/") | ||
print(rv.__dict__) | ||
assert rv.status_code == 200 | ||
assert rv.data | ||
from mock_alchemy.mocking import UnifiedAlchemyMagicMock | ||
|
||
from quarry.web.models.query import Query | ||
from quarry.web.models.queryrevision import QueryRevision | ||
from quarry.web.models.queryrun import QueryRun | ||
from quarry.web.models.user import User | ||
|
||
|
||
class TestApp: | ||
def test_frontpage(self, mocker, client): | ||
self.db_session = UnifiedAlchemyMagicMock() | ||
|
||
# Homepage shows statistics | ||
for user_id in range(5): | ||
self.db_session.add(User(id=user_id)) | ||
for query_id in range(3): | ||
self.db_session.add(Query(id=query_id, user_id=user_id)) | ||
for queryrev_id in range(3): | ||
self.db_session.add( | ||
QueryRevision(id=queryrev_id, query_id=query_id) | ||
) | ||
for queryrun_id in range(3): | ||
self.db_session.add( | ||
QueryRun(id=queryrun_id, query_rev_id=queryrev_id) | ||
) | ||
|
||
mocker.patch( | ||
"quarry.web.connections.Connections.session", | ||
new_callable=mocker.PropertyMock(return_value=self.db_session), | ||
) | ||
|
||
response = client.get("/") | ||
print(response.__dict__) | ||
assert response.status_code == 200 | ||
assert response.data | ||
assert "5 users" in response.data.decode("utf8") | ||
assert f"{5 * 3 * 3 * 3} queries" in response.data.decode("utf8") |