Skip to content
Permalink
f289774945
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
196 lines (179 sloc) 6.71 KB
from django.test import TestCase
from django.utils import timezone
from django.db.utils import IntegrityError
from django.core.management import call_command
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
from itertools import chain
from io import StringIO
from .models import *
class AuthorModelTests(TestCase):
def setUp(self):
Author.objects.create(
firstname='Test',
lastname='Ußer',
middlenames ='D.',
homepage='www.data.de',
email='test@test.ert')
Author.objects.create(
firstname='Test2',
lastname='Äöü-89',
)
Author.objects.create(
firstname='Drei',
lastname='Hurra-89',
)
def test_string_output(self):
user = Author.objects.get(firstname='Test')
user2 = Author.objects.get(firstname='Test2')
self.assertEqual(user.__str__(), 'Test D. Ußer')
self.assertEqual(user2.email,None)
def testUniqueEmail(self):
with self.assertRaises(IntegrityError):
Author.objects.create(
firstname='Mer',
lastname='Bauer',
email='test@test.ert')
class AuthorFormTests(TestCase):
pass
class PublicationModelTests(TestCase):
def setUp(self):
Publication.objects.create(
series='studies',
language='de',
published=True,
featured=True,
publication_id=4,
publisher='Edition Open Access',
title='Test case publication',
subtitle='The revenge of editors',
description='Testing a longer sentence in a TextField requiers more typing or lorem ipsum.',
pages=20,
price=19.90,
created_date=timezone.now(),
published_date=timezone.now()
)
Author.objects.create(
firstname='Test',
lastname='Ußer',
middlenames ='D.',
homepage='www.data.de',
email='test@test.ert')
Author.objects.create(
firstname='More',
middlenames='',
lastname='Testing',
homepage='www.data.de',
email='more@test.ert')
def test_string_output(self):
pub1 = Publication.objects.get(publication_id=4)
self.assertEqual(pub1.__str__(),'Test case publication')
def test_add_publications(self):
pub1 = Publication.objects.get(publication_id=4)
aut1 = Author.objects.get(email='test@test.ert')
aut2 = Author.objects.get(email='more@test.ert')
aut1.publications.add(pub1)
aut2.publications.add(pub1)
self.assertEqual(aut1.publications.get(pk=pub1.pk),pub1)
autList = [a.__str__() for a in pub1.authors.all()]
self.assertEqual(sorted(autList),[a.__str__() for a in [aut2,aut1]])
class CitationModelTest(TestCase):
def setUp(self):
cit1 = Citation.objects.create(
pubtype = 'book',
titlem = 'Testing citations',
date = 1909,
pupPlace = 'Berlin',
idstring = 'Mop1909',
)
aut1 = Author.objects.create(
firstname='Test',
lastname='Ußer',
middlenames ='D.',
homepage='www.data.de',
email='test@test.ert')
aut1.citations.add(cit1)
def testCit(self):
aut1 = Author.objects.get(firstname='Test')
cit1 = Citation.objects.get(idstring = 'Mop1909')
self.assertEqual(aut1.citations.get(pk = cit1.pk),cit1)
self.assertEqual(cit1.__str__(), 'Mop1909: Testing citations')
class MixedContentModelTest(TestCase):
def setUp(self):
pub1 = Publication.objects.create(
series='studies',
language='de',
published=True,
featured=True,
publication_id=4,
publisher='Edition Open Access',
title='Test case publication',
subtitle='The revenge of editors',
description='Testing a longer sentence in a TextField requiers more typing or lorem ipsum.',
pages=20,
price=19.90,
created_date=timezone.now(),
published_date=timezone.now()
)
mix1 = MixedContent.objects.create(
position = 0,
)
mix2 = MixedContent.objects.create(
parent = mix1,
position = mix1.position,
tagname = 'hi',
attributes = {'rend':'bold'},
)
mix2text = Text.objects.create(
parent = mix2,
position = mix2.position,
text = 'Part 1:',
)
txt1 = Text.objects.create(
parent = mix1,
position = 2,
text = 'Testing mixed content model',
)
par1 = Paragraph.objects.create(
publication = pub1,
idstring = 'p1',
content = mix1,
)
def testMixed(self):
pub1 = Publication.objects.get(publication_id=4)
par1 = pub1.paragraphs.get(idstring='p1')
mix1 = MixedContent.objects.filter(position=0).exclude(parent=True)
con1 = par1.content
self.assertEqual(mix1[0].pk,con1.pk)
self.assertEqual(
[x.attributes for x in con1.children.filter(position=0)][0],
{'rend': 'bold'}
)
self.assertEqual(
con1.children.filter(position=0)[0].textcontent.all()[0].text,
'Part 1:')
res = []
result_list = list(chain(con1.children.all(), con1.textcontent.all()))
for child in result_list:
try:
child.tagname
tag = child.tagname
value = child.attributes
for i in value:
attr = i
val = value[i]
text = child.textcontent.filter(position=child.position)[0].text
res.append('<{0} {1}="{2}">{3}</{0}>'.format(tag,attr,val,text))
except:
child.text
res.append((child.text))
self.assertEqual(''.join(res),'<hi rend="bold">Part 1:</hi>Testing mixed content model')
# class ImporterCommandTests(TestCase):
# def test_tei_importer(self):
# " Test import of TEI docs."
# out = StringIO()
# call_command('tei_import', f='baernighausen.xml', stdout=out)
# pub = Publication.objects.get(title='Into The Archive')
# aut = pub.authors.get(lastname='Bärnighausen')
# sec = Section.objects.get(order=1)
# para = Paragraph.objects.filter(section=sec)
# self.assertIn("Successfully read TEI file, by", out.getvalue())