Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulnarang95 committed Sep 18, 2024
1 parent 345c9b7 commit 5e3c972
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from cms.test_utils.testcases import CMSTestCase

Check failure on line 1 in tests/test_admin.py

View workflow job for this annotation

GitHub Actions / isort

Imports are incorrectly sorted and/or formatted.

Check failure on line 1 in tests/test_admin.py

View workflow job for this annotation

GitHub Actions / flake8

'cms.test_utils.testcases.CMSTestCase' imported but unused

from django.shortcuts import reverse
from django.test import TestCase, RequestFactory
from django.contrib.auth.models import User
from django.core.paginator import Paginator

from djangocms_versioning.helpers import proxy_model
from filer.models import File

from filer.models import File, Folder
from filer.admin.folderadmin import FolderAdmin

Check failure on line 11 in tests/test_admin.py

View workflow job for this annotation

GitHub Actions / flake8

'filer.admin.folderadmin.FolderAdmin' imported but unused

from tests.base import BaseFilerVersioningTestCase

Expand Down Expand Up @@ -55,3 +62,26 @@ def test_admin_edit_button_disabled(self):
self.assertContains(response, "js-versioning-action-btn")
self.assertContains(response, "js-versioning-action")
self.assertContains(response, "inactive")


class FolderAdminTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.user = User.objects.create(username='testuser', password='12345')
self.folder = Folder.objects.create(name='Test Folder', owner=self.user)
self.file1 = File.objects.create(name='Test File 1', folder=self.folder, owner=self.user)
self.file2 = File.objects.create(name='Test File 2', folder=self.folder, owner=self.user)

def test_list_per_page_from_request(self):
# Simulate a Get request with list_per_page parameter
request = self.factory.get('/', {'list_per_page': '1'})
request.user = self.user

request.GET = {'list_per_page': '1'}
folder_qs = Folder.objects.filter(id=self.folder.id)
file_qs = File.objects.filter(folder=self.folder)
items = list(folder_qs) + list(file_qs)
paginator_count = int(request.GET.get('list_per_page', 10))
paginator = Paginator(items, paginator_count)

self.assertEqual(paginator.per_page, 1)

0 comments on commit 5e3c972

Please sign in to comment.