Skip to content

Commit

Permalink
Basic tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Sep 8, 2018
1 parent 40115c4 commit baa4c8c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 5 deletions.
4 changes: 3 additions & 1 deletion admirarchy/tests/conftest.py
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,
)
58 changes: 55 additions & 3 deletions admirarchy/tests/test_basic.py
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
12 changes: 12 additions & 0 deletions admirarchy/tests/testapp/admin.py
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)
10 changes: 10 additions & 0 deletions admirarchy/tests/testapp/models.py
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
9 changes: 9 additions & 0 deletions admirarchy/tests/testapp/urls.py
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),
])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_version():
test_suite='tests',
tests_require=[
'pytest',
'pytest-djangoapp>=0.8.0',
'pytest-djangoapp>=0.9.0',
],

classifiers=[
Expand Down

0 comments on commit baa4c8c

Please sign in to comment.