Improve stats view testing with another user
This commit is contained in:
parent
deb0ab09d3
commit
6f72df82b7
2 changed files with 16 additions and 3 deletions
|
@ -2,6 +2,7 @@ import shutil
|
|||
import tempfile
|
||||
|
||||
import pytest
|
||||
from django.core.cache import cache
|
||||
from django.core.signing import get_cookie_signer
|
||||
|
||||
from .base import DataLayerFactory, MapFactory, UserFactory
|
||||
|
@ -12,6 +13,7 @@ TMP_ROOT = tempfile.mkdtemp()
|
|||
|
||||
def pytest_configure(config):
|
||||
from django.conf import settings
|
||||
|
||||
settings.MEDIA_ROOT = TMP_ROOT
|
||||
|
||||
|
||||
|
@ -19,11 +21,20 @@ def pytest_unconfigure(config):
|
|||
shutil.rmtree(TMP_ROOT, ignore_errors=True)
|
||||
|
||||
|
||||
def pytest_runtest_teardown():
|
||||
cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user():
|
||||
return UserFactory(password="123123")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2():
|
||||
return UserFactory(username="Averell", password="456456")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def licence():
|
||||
# Should be created by the migrations.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
import socket
|
||||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
|
@ -150,13 +150,15 @@ def test_stats_empty(client):
|
|||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_stats_basic(client, map, datalayer):
|
||||
def test_stats_basic(client, map, datalayer, user2):
|
||||
map.owner.last_login = date.today()
|
||||
map.owner.save()
|
||||
user2.last_login = date.today() - timedelta(days=8)
|
||||
user2.save()
|
||||
response = client.get(reverse("stats"))
|
||||
assert json.loads(response.content.decode()) == {
|
||||
"maps_active_last_week_count": 1,
|
||||
"maps_count": 1,
|
||||
"users_active_last_week_count": 1,
|
||||
"users_count": 1,
|
||||
"users_count": 2,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue