From b05054af90f5a619af14aa7ebc05f3146b1e2d41 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 30 Oct 2014 11:22:33 -0400 Subject: [PATCH] Add test for the addition and removal of documents to tags --- mayan/apps/tags/tests.py | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/mayan/apps/tags/tests.py b/mayan/apps/tags/tests.py index 48beb1c77e..ca90d6806a 100644 --- a/mayan/apps/tags/tests.py +++ b/mayan/apps/tags/tests.py @@ -1,16 +1,54 @@ +import os + +from django.conf import settings +from django.contrib.auth.models import User +from django.core.files.base import File from django.test import TestCase +from documents.models import Document, DocumentType + from .literals import COLOR_RED from .models import Tag +TEST_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'title_page.png') + class TagTestCase(TestCase): def setUp(self): - self.tag = Tag(label='test', color=COLOR_RED) - self.tag.save() + self.document_type = DocumentType(name='test doc type') + self.document_type.save() + + self.document = Document( + document_type=self.document_type, + description='description', + ) + self.document.save() + + with open(TEST_DOCUMENT_PATH) as file_object: + self.document.new_version(file_object=File(file_object)) def runTest(self): - self.failUnlessEqual(self.tag.label, 'test') - self.failUnlessEqual(self.tag.get_color_code(), 'red') + tag = Tag(label='test', color=COLOR_RED) + tag.save() + self.failUnlessEqual(tag.label, 'test') + self.failUnlessEqual(tag.get_color_code(), 'red') -# TODO: Add test for attaching and removing documents to a tag + def test_addition_and_deletion_of_documents(self): + tag = Tag(label='test', color=COLOR_RED) + tag.save() + + tag.documents.add(self.document) + + self.assertEqual(tag.documents.count(), 1) + self.assertEqual(list(tag.documents.all()), [self.document]) + + tag.documents.remove(self.document) + + self.assertEqual(tag.documents.count(), 0) + self.assertEqual(list(tag.documents.all()), []) + + tag.delete() + + def tearDown(self): + self.document.delete() + self.document_type.delete()