Example #1
0
 def test_delete_handler(self, people_landing_page):
     """deleting person should delete corresponding profile"""
     person = Person.objects.create(first_name="tom", last_name="jones")
     people_landing_page.add_child(instance=Profile(
         title="tom r. jones",
         person=person,
     ))
     people_landing_page.save()
     person.delete()
     assert Profile.objects.count() == 0
Example #2
0
 def test_person_required(self, people_landing_page):
     """profile page must be for an existing person"""
     with pytest.raises(ValidationError):
         people_landing_page.add_child(instance=Profile(
             title="tom r. jones",
             education=rich_text("school"),
             body=json.dumps([{
                 "type": "paragraph",
                 "value": "about me"
             }]),
         ))
Example #3
0
def make_staffer_profile(people_landing_page, staffer):
    """Create a profile page for a given staff person."""
    profile = Profile(
        person=staffer,
        title="Staffer",
        education="Princeton University",
        body=to_streamfield_safe(
            "<p>I'm a member of the CDH staff. I do digital humanities.</p>"),
    )
    people_landing_page.add_child(instance=profile)
    people_landing_page.save()
    return profile
Example #4
0
    def setUp(self):
        """create example user/person/profile and testing client"""
        # set up wagtail page tree
        root = Page.objects.get(title="Root")
        home = HomePage(title="home", slug="")
        root.add_child(instance=home)
        root.save()
        lp = PeopleLandingPage(title="people", slug="people", tagline="people")
        home.add_child(instance=lp)
        home.save()
        site = Site.objects.first()
        site.root_page = home
        site.save()
        self.site = site

        # set up user/person/profile
        User = get_user_model()
        self.user = User.objects.create_user(username="******")
        self.person = Person.objects.create(
            user=self.user,
            first_name="tom",
            email="*****@*****.**",
            phone_number="609-000-0000",
            office_location="on campus",
        )
        self.profile = Profile(
            person=self.person,
            title="tom r. jones",
            slug="tom-jones",
            education="<ul><li>college dropout</li></ul>",
            body=json.dumps([{
                "type": "paragraph",
                "value": "<b>about me</b>"
            }]),
        )
        lp.add_child(instance=self.profile)
        lp.save()
Example #5
0
 def test_can_create(self, people_landing_page):
     """should be creatable as child of people landing page"""
     person = Person.objects.create(first_name="tom", last_name="jones")
     profile = Profile(
         title="tom r. jones",
         person=person,
         education=rich_text("school"),
         body=json.dumps([{
             "type": "paragraph",
             "value": "about me"
         }]),
     )
     people_landing_page.add_child(instance=profile)
     people_landing_page.save()
     assert person.profile == profile
Example #6
0
    def test_recent_blogposts(self, people_landing_page, blog_link_page):
        """profile should have person's most recent blog posts in context"""
        # create the profile page
        person = Person.objects.create(first_name="tom", last_name="jones")
        profile = Profile(
            title="tom jones",
            slug="tom-jones",
            person=person,
        )
        people_landing_page.add_child(instance=profile)
        people_landing_page.save()

        # context obj with blog posts is empty
        factory = RequestFactory()
        request = factory.get(profile.get_url())
        context = profile.get_context(request)
        assert not context["recent_posts"]  # empty list

        # create some blog posts by this person
        # "one"     2021-01-01  published
        # "two"     2021-01-02  published
        # "three"   2021-01-03  published
        # "four"    2021-01-04  draft
        # "five"    2021-01-05  published
        posts = {}
        for i, title in enumerate(["one", "two", "three", "four", "five"]):
            post = BlogPost(title=title)
            post.first_published_at = timezone.make_aware(
                datetime.datetime(2021, 1, i + 1))
            blog_link_page.add_child(instance=post)
            blog_link_page.save()
            Author.objects.create(post=post, person=person)
            posts[title] = post
        posts["four"].unpublish()

        # only 3 most recent *published* posts should be in context, in order
        # with most recent first: "five", "three", "two"
        factory = RequestFactory()
        request = factory.get(profile.get_url())
        context = profile.get_context(request)
        assert context["recent_posts"][0] == posts["five"]
        assert context["recent_posts"][1] == posts["three"]
        assert context["recent_posts"][2] == posts["two"]
        assert posts["four"] not in context["recent_posts"]
        assert posts["one"] not in context["recent_posts"]
Example #7
0
class TestProfile(TestCase):
    def setUp(self):
        """create example user/person/profile and testing client"""
        # set up wagtail page tree
        root = Page.objects.get(title="Root")
        home = HomePage(title="home", slug="")
        root.add_child(instance=home)
        root.save()
        lp = PeopleLandingPage(title="people", slug="people", tagline="people")
        home.add_child(instance=lp)
        home.save()
        site = Site.objects.first()
        site.root_page = home
        site.save()
        self.site = site

        # set up user/person/profile
        User = get_user_model()
        self.user = User.objects.create_user(username="******")
        self.person = Person.objects.create(
            user=self.user,
            first_name="tom",
            email="*****@*****.**",
            phone_number="609-000-0000",
            office_location="on campus",
        )
        self.profile = Profile(
            person=self.person,
            title="tom r. jones",
            slug="tom-jones",
            education="<ul><li>college dropout</li></ul>",
            body=json.dumps([{
                "type": "paragraph",
                "value": "<b>about me</b>"
            }]),
        )
        lp.add_child(instance=self.profile)
        lp.save()

    def test_title(self):
        """profile page should display profile's title"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response, "<h1>tom r. jones</h1>", html=True)

    def test_education(self):
        """profile page should display person's education"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response, "<li>college dropout</li>", html=True)

    def test_bio(self):
        """profile page should display person's bio (body content)"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response, "<b>about me</b>", html=True)

    def test_email(self):
        """profile page should display person's email"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(
            response,
            '<a href="mailto:[email protected]">[email protected]</a>',
            html=True,
        )

    def test_missing_email(self):
        """profile page should not display person's email if not set"""
        self.person.email = ""
        self.person.save()
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertNotContains(response, 'href="mailto')
        self.assertNotContains(response, "None")

    def test_phone_number(self):
        """profile page should display person's phone number"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response, "<p>609-000-0000</p>", html=True)

    def test_office_location(self):
        """profile page should display person's office location"""
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response, "<p>on campus</p>", html=True)

    def test_positions(self):
        """profile page should display all positions held by its person"""
        # create some positions
        director = Title.objects.create(title="director")
        developer = Title.objects.create(title="developer")
        Position.objects.create(person=self.person,
                                title=developer,
                                start_date=datetime.date(2021, 1, 1))
        Position.objects.create(
            person=self.person,
            title=director,
            start_date=datetime.date(2020, 1, 1),
            end_date=datetime.date(2020, 10, 1),
        )

        # should all be displayed with dates
        response = self.client.get(self.profile.relative_url(self.site))
        self.assertContains(response,
                            "<p class='title'>developer</p>",
                            html=True)
        self.assertContains(response,
                            "<p class='title'>2020 director</p>",
                            html=True)
Example #8
0
    def test_detail(self):
        proj = Project.objects.create(
            title="Derrida's Margins",
            slug='derrida',
            short_description='Citations and interventions',
            long_description='<p>an annotation project</p>')
        today = datetime.today()
        grtype = GrantType.objects.create(grant_type='Sponsored Project')
        grant = Grant.objects.create(project=proj,
                                     grant_type=grtype,
                                     start_date=today - timedelta(days=2),
                                     end_date=today + timedelta(days=1))
        # add project members to test contributor display
        contrib1 = get_user_model().objects.create(username='******')
        contrib2 = get_user_model().objects.create(username='******')
        contrib3 = get_user_model().objects.create(
            username='******')
        site = Site.objects.first()
        Profile.objects.bulk_create([
            Profile(user=contrib1, title=contrib1.username, site=site),
            Profile(user=contrib2, title=contrib2.username, site=site),
            Profile(user=contrib3, title=contrib3.username, site=site)
        ])
        consult = Role.objects.create(title='Consultant', sort_order=2)
        pi = Role.objects.create(title='Principal Investigator', sort_order=1)
        Membership.objects.bulk_create([
            Membership(project=proj, user=contrib1, grant=grant, role=consult),
            Membership(project=proj, user=contrib2, grant=grant, role=consult),
            Membership(project=proj, user=contrib3, grant=grant, role=pi)
        ])
        # add a website url
        website = ResourceType.objects.get(name='Website')
        project_url = 'http://something.princeton.edu'
        ProjectResource.objects.create(project=proj,
                                       resource_type=website,
                                       url=project_url)

        response = self.client.get(
            reverse('project:detail', kwargs={'slug': proj.slug}))
        assert response.context['project'] == proj
        self.assertContains(response, escape(proj.title))
        self.assertContains(response, proj.short_description)
        self.assertContains(response, proj.long_description)
        # contributors
        self.assertContains(
            response,
            consult.title,
            count=1,
            msg_prefix='contributor roles should only show up once')
        self.assertContains(
            response,
            pi.title,
            count=1,
            msg_prefix='contributor roles should only show up once')
        for contributor in [contrib1, contrib2, contrib3]:
            self.assertContains(response, contributor.profile.title)
        self.assertContains(response, project_url)

        # test grant dates displayed
        self.assertContains(response, '<h2>CDH Grant History</h2>')
        self.assertContains(response,
                            '%s %s' % (grant.years, grant.grant_type))

        # if for some reason a project has no grants, should not display grants
        proj.grant_set.all().delete()
        response = self.client.get(
            reverse('project:detail', kwargs={'slug': proj.slug}))
        self.assertNotContains(response, '<h2>CDH Grant History</h2>')