Files
mayan-edms/mayan/apps/cabinets/tests/test_models.py
Roberto Rosario 8e69178e07 Project: Switch to full app paths
Instead of inserting the path of the apps into the Python app,
the apps are now referenced by their full import path.

This app name claves with external or native Python libraries.
Example: Mayan statistics app vs. Python new statistics library.

Every app reference is now prepended with 'mayan.apps'.

Existing config.yml files need to be updated manually.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-12-05 02:04:20 -04:00

67 lines
2.2 KiB
Python

from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.test import override_settings
from mayan.apps.common.tests import BaseTestCase
from mayan.apps.documents.tests import DocumentTestMixin
from ..models import Cabinet
from .literals import TEST_CABINET_LABEL
@override_settings(OCR_AUTO_OCR=False)
class CabinetTestCase(DocumentTestMixin, BaseTestCase):
def test_cabinet_creation(self):
cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
self.assertEqual(Cabinet.objects.all().count(), 1)
self.assertQuerysetEqual(Cabinet.objects.all(), (repr(cabinet),))
def test_cabinet_duplicate_creation(self):
cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
with self.assertRaises(ValidationError):
cabinet_2 = Cabinet(label=TEST_CABINET_LABEL)
cabinet_2.validate_unique()
cabinet_2.save()
self.assertEqual(Cabinet.objects.all().count(), 1)
self.assertQuerysetEqual(Cabinet.objects.all(), (repr(cabinet),))
def test_inner_cabinet_creation(self):
cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
inner_cabinet = Cabinet.objects.create(
parent=cabinet, label=TEST_CABINET_LABEL
)
self.assertEqual(Cabinet.objects.all().count(), 2)
self.assertQuerysetEqual(
Cabinet.objects.all(), map(repr, (cabinet, inner_cabinet))
)
def test_addition_of_documents(self):
cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
cabinet.documents.add(self.document)
self.assertEqual(cabinet.documents.count(), 1)
self.assertQuerysetEqual(
cabinet.documents.all(), (repr(self.document),)
)
def test_addition_and_deletion_of_documents(self):
cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
cabinet.documents.add(self.document)
self.assertEqual(cabinet.documents.count(), 1)
self.assertQuerysetEqual(
cabinet.documents.all(), (repr(self.document),)
)
cabinet.documents.remove(self.document)
self.assertEqual(cabinet.documents.count(), 0)
self.assertQuerysetEqual(cabinet.documents.all(), ())