diff --git a/theses/factories.py b/theses/factories.py index 926d1c192b142c5637669be954235eb013fa3fd3..60e67d1ae827327e9c73d9056e46b70130eb915f 100644 --- a/theses/factories.py +++ b/theses/factories.py @@ -1,10 +1,17 @@ import factory -from . import models +from .models import ThesisLink class ThesisLinkFactory(factory.django.DjangoModelFactory): class Meta: - model = models.ThesisLink + model = ThesisLink - vetted = True - type = models + # requested_by = factory.SubFactory(ContributorFactory) + type = ThesisLink.MASTER_THESIS + title = factory.Sequence(lambda n: "thesis {0}".format(n)) + pub_link = factory.Faker('uri') + author = factory.Faker('name') + supervisor = factory.Faker('name') + institution = factory.Faker('company') + defense_date = factory.Faker('date_time_this_century') + abstract = factory.Faker('text') diff --git a/theses/models.py b/theses/models.py index b2bfe6242f5dafc54fc91c40b3336a3c33ba8881..139948b9175deb6bc62fdc098bef6d3fc4a4ef86 100644 --- a/theses/models.py +++ b/theses/models.py @@ -18,7 +18,7 @@ class ThesisLink(models.Model): (PHD_THESIS, 'Ph.D.'), (HABILITATION_THESIS, 'Habilitation'), ) - thesis_type_dict = dict(THESIS_TYPES) + THESIS_TYPES_DICT = dict(THESIS_TYPES) """ An URL pointing to a thesis """ requested_by = models.ForeignKey( @@ -29,13 +29,13 @@ class ThesisLink(models.Model): vetted_by = models.ForeignKey( Contributor, blank=True, null=True, on_delete=models.CASCADE) - type = models.CharField(choices=THESIS_TYPES) + type = models.CharField(choices=THESIS_TYPES, max_length=3) discipline = models.CharField( max_length=20, choices=SCIPOST_DISCIPLINES, default='physics') domain = models.CharField( max_length=3, choices=SCIPOST_JOURNALS_DOMAINS, - blank=True) + blank=False) subject_area = models.CharField( max_length=10, choices=SCIPOST_SUBJECT_AREAS, @@ -88,7 +88,7 @@ class ThesisLink(models.Model): header += '<td>(not claimed)</td>' header += ( '</tr>' - '<tr><td>Type: </td><td></td><td>' + thesis_type_dict[self.type] + + '<tr><td>Type: </td><td></td><td>' + self.THESIS_TYPES_DICT[self.type] + '</td></tr>' '<tr><td>Discipline: </td><td></td><td>' + disciplines_dict[self.discipline] + '</td></tr>' @@ -119,7 +119,7 @@ class ThesisLink(models.Model): '<li><div class="flex-container">' '<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" ' 'class="pubtitleli">{{ title }}</a></p>' - '<p>' + thesis_type_dict[self.type] + ' thesis by {{ author }} ' + '<p>' + self.THESIS_TYPES_DICT[self.type] + ' thesis by {{ author }} ' '(supervisor(s): {{ supervisor }}) in ' + disciplines_dict[self.discipline] + ', ' + journals_domains_dict[self.domain] + ' ' + @@ -138,7 +138,7 @@ class ThesisLink(models.Model): '<li><div class="flex-container">' '<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" ' 'class="pubtitleli">{{ title }}</a></p>' - '<p>' + thesis_type_dict[self.type] + + '<p>' + self.THESIS_TYPES_DICT[self.type] + ' thesis by {{ author }} </div></div></li>') template = Template(header) return template.render(context) diff --git a/theses/test_models.py b/theses/test_models.py index 2e9cb5f6ba351402af656aec1be5d9ac257bc5c0..4308ab25f1d22c56e33cb5047cb6f571fe080bf7 100644 --- a/theses/test_models.py +++ b/theses/test_models.py @@ -1 +1,15 @@ +import re + from django.test import TestCase +from django.core.exceptions import ValidationError + +from .models import ThesisLink +from .factories import ThesisLinkFactory + + +class ThesisLinkTestCase(TestCase): + def test_domain_cannot_be_blank(self): + thesis_link = ThesisLinkFactory() + thesis_link.domain = "" + self.assertRaisesRegexp(ValidationError, re.compile(r'domain'), + thesis_link.full_clean)