-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from pytest_djangoapp import configure_djangoapp_plugin | ||
|
||
|
||
pytest_plugins = configure_djangoapp_plugin() | ||
pytest_plugins = configure_djangoapp_plugin( | ||
admin_contrib=True, | ||
) |
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,6 +1,58 @@ | ||
import pytest | ||
from django import VERSION | ||
|
||
from .testapp.models import AdjacencyListModel | ||
|
||
def test_stub(): | ||
assert True | ||
|
||
VERSION_PRE_19 = VERSION < (1, 9) | ||
|
||
|
||
def test_adjacency_list(settings, request_client, user_create): | ||
|
||
def make_node(title, parent=None): | ||
node = AdjacencyListModel(title=title, parent=parent) | ||
node.save() | ||
return node | ||
|
||
parent = make_node('parent') | ||
make_node('child1', parent=parent) | ||
make_node('child2', parent=parent) | ||
|
||
user = user_create(superuser=True) | ||
|
||
client = request_client() | ||
assert client.login(username=user.username, password='password') | ||
|
||
url_base = '/admin/testapp/adjacencylistmodel/' | ||
|
||
resp = client.get(url_base) | ||
|
||
assert 'Upper level' not in resp.rendered_content | ||
|
||
if VERSION_PRE_19: | ||
assert '/1/' in resp.rendered_content | ||
else: | ||
assert '/1/change/' in resp.rendered_content | ||
|
||
assert 'href="?pid=1"' in resp.rendered_content | ||
assert 'adjlist_parent' in resp.rendered_content | ||
assert 'adjlist_child1' not in resp.rendered_content | ||
assert 'adjlist_child2' not in resp.rendered_content | ||
|
||
resp = client.get(url_base + '?pid=1') | ||
|
||
assert 'Upper level' in resp.rendered_content | ||
|
||
if VERSION_PRE_19: | ||
assert '/1/' not in resp.rendered_content | ||
assert '/2/?_changelist_filters=pid%3D1' in resp.rendered_content | ||
assert '/3/?_changelist_filters=pid%3D1' in resp.rendered_content | ||
|
||
|
||
else: | ||
assert '/1/change/' not in resp.rendered_content | ||
assert '/2/change/?_changelist_filters=pid%3D1' in resp.rendered_content | ||
assert '/3/change/?_changelist_filters=pid%3D1' in resp.rendered_content | ||
|
||
assert 'adjlist_parent' not in resp.rendered_content | ||
assert 'adjlist_child1' in resp.rendered_content | ||
assert 'adjlist_child2' in resp.rendered_content |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.contrib import admin | ||
|
||
from .models import AdjacencyListModel | ||
from admirarchy.toolbox import HierarchicalModelAdmin | ||
|
||
|
||
class MyModelAdmin(HierarchicalModelAdmin): | ||
|
||
hierarchy = True | ||
|
||
|
||
admin.site.register(AdjacencyListModel, MyModelAdmin) |
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,2 +1,12 @@ | ||
from django.db import models | ||
|
||
|
||
class AdjacencyListModel(models.Model): | ||
|
||
title = models.CharField(max_length=100) | ||
|
||
parent = models.ForeignKey( | ||
'self', related_name='%(class)s_parent', on_delete=models.CASCADE, db_index=True, null=True, blank=True) | ||
|
||
def __str__(self): | ||
return 'adjlist_%s' % self.title |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.contrib import admin | ||
from django.conf.urls import url | ||
|
||
from pytest_djangoapp.compat import get_urlpatterns | ||
|
||
|
||
urlpatterns = get_urlpatterns([ | ||
url('admin/', admin.site.urls), | ||
]) |
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