Skip to content

Commit

Permalink
tests: fix up fixtures and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
asfaltboy committed Mar 28, 2024
1 parent 4d59cd7 commit 16cde7a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
20 changes: 0 additions & 20 deletions advanced_filters/tests/conftest.py

This file was deleted.

19 changes: 19 additions & 0 deletions advanced_filters/tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import pytest

from tests.factories import ClientFactory, SalesRepFactory


@pytest.fixture(scope="session")
def base_url(live_server):
return live_server.url


@pytest.fixture
@pytest.mark.usefixtures("db")
def user():
return SalesRepFactory()


@pytest.fixture()
def client(client, user):
client.force_login(user)
return client


@pytest.fixture
def three_clients(user):
return ClientFactory.create_batch(3, assigned_to=user)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.db.models import Q
from django.urls import reverse

from ..models import AdvancedFilter
from .factories import AdvancedFilterFactory
from advanced_filters.models import AdvancedFilter
from advanced_filters.tests.factories import AdvancedFilterFactory

URL_NAME_CHANGE = "admin:advanced_filters_advancedfilter_change"
URL_NAME_ADD = "admin:advanced_filters_advancedfilter_add"
Expand Down Expand Up @@ -42,7 +42,9 @@ def test_change_and_goto(client, user, settings, advanced_filter):
res = client.post(url, data=form_data)
assert res.status_code == 302
url = res["location"]
assert url.endswith("%s?_afilter=1" % reverse(URL_NAME_CLIENT_CHANGELIST))
changelist_url = reverse(URL_NAME_CLIENT_CHANGELIST)
new_filter_id = AdvancedFilter.objects.last().pk
assert url.endswith(f"{changelist_url}?_afilter={new_filter_id}")


def test_create_page_disabled(client, user):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.models import Permission
from django.urls import reverse_lazy

from ..models import AdvancedFilter
from advanced_filters.models import AdvancedFilter

URL_CLIENT_CHANGELIST = reverse_lazy("admin:customers_client_changelist")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import json
import sys
from datetime import timedelta
from operator import attrgetter, itemgetter
from operator import itemgetter

import django
import factory
import pytest
from django.urls import reverse
from django.utils import timezone
from django.utils.encoding import force_str
from django.urls import reverse
from tests.factories import ClientFactory

from tests.factories import ClientFactory

URL_NAME = "afilters_get_field_choices"

Expand All @@ -24,7 +22,7 @@ def assert_json(content, expect):


def assert_view_error(client, error, exception=None, **view_kwargs):
""" Ensure view either raises exception or returns a 400 json error """
"""Ensure view either raises exception or returns a 400 json error"""
view_url = reverse(URL_NAME, kwargs=view_kwargs)

if exception is not None:
Expand Down Expand Up @@ -99,8 +97,8 @@ def test_database_choices(three_clients, client):
response = client.get(view_url)
result = parse_json(response.content)
data = (dict(id=e.email, text=e.email) for e in three_clients)
sort_func = itemgetter('id')
assert sorted(result['results'], key=sort_func) == sorted(data, key=sort_func)
sort_func = itemgetter("id")
assert sorted(result["results"], key=sort_func) == sorted(data, key=sort_func)


def test_more_than_max_database_choices(user, client, settings):
Expand Down
1 change: 1 addition & 0 deletions test-reqs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pytest-django==4.5.2
pytest-cov==4.1.0
pytest-playwright==0.4.4
pytest-env==1.1.3
tzdata==2024.1

0 comments on commit 16cde7a

Please sign in to comment.