Ejemplo n.º 1
0
    def test_render_citations_mla_one_author(self):
        citation = render_citation(self.preprint, 'modern-language-association')
        assert_equal(citation, u'Tordoff, John. “{}.” {}, {}. Web.'.format(
            self.preprint.node.title,
            self.preprint.provider.name,
            self.formated_date)
        )

        # test_suffix
        self.user.suffix = 'Junior'
        self.user.save()
        citation = render_citation(self.preprint, 'modern-language-association')
        assert_equal(citation, u'Tordoff, John, Junior. “{}.” {}, {}. Web.'.format(
            self.preprint.node.title,
            self.preprint.provider.name,
            self.formated_date)
        )

        # test_no_middle_names
        self.user.suffix = ''
        self.user.middle_names = ''
        self.user.save()
        citation = render_citation(self.preprint, 'modern-language-association')
        assert_equal(citation, u'Tordoff, John. “{}.” {}, {}. Web.'.format(
            self.preprint.node.title,
            self.preprint.provider.name,
            self.formated_date)
        )
Ejemplo n.º 2
0
    def test_one_author(self):
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(
            citation,
            render_citation(self.published_preprint,
                            'modern-language-association'))

        # test_suffix
        self.admin_contributor.suffix = 'Junior'
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(
            citation,
            render_citation(self.published_preprint,
                            'modern-language-association'))

        # test_no_middle_names
        self.admin_contributor.suffix = ''
        self.admin_contributor.middle_names = ''
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(
            citation,
            render_citation(self.published_preprint,
                            'modern-language-association'))
Ejemplo n.º 3
0
    def test_render_citations_mla_one_author(self):
        citation = render_citation(self.preprint,
                                   'modern-language-association')
        assert_equal(
            citation, u'Tordoff, John. “{}.” {}, {}. Web.'.format(
                self.preprint.title, self.preprint.provider.name,
                self.formated_date))

        # test_suffix
        self.user.suffix = 'Junior'
        self.user.save()
        citation = render_citation(self.preprint,
                                   'modern-language-association')
        assert_equal(
            citation, u'Tordoff, John, Junior. “{}.” {}, {}. Web.'.format(
                self.preprint.title, self.preprint.provider.name,
                self.formated_date))

        # test_no_middle_names
        self.user.suffix = ''
        self.user.middle_names = ''
        self.user.save()
        citation = render_citation(self.preprint,
                                   'modern-language-association')
        assert_equal(
            citation, u'Tordoff, John. “{}.” {}, {}. Web.'.format(
                self.preprint.title, self.preprint.provider.name,
                self.formated_date))
Ejemplo n.º 4
0
 def test_citation_no_repeated_periods(self):
     self.published_preprint.title = 'A Study of Coffee.'
     self.published_preprint.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
    def test_three_authors(self):
        self.published_preprint.add_contributor(self.second_contrib)
        self.published_preprint.add_contributor(self.third_contrib)
        self.published_preprint.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))

        # first name suffix
        self.admin_contributor.suffix = 'Jr.'
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 6
0
 def test_two_authors(self):
     self.node.add_contributor(self.second_contrib)
     self.node.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 7
0
    def test_three_authors(self):
        self.published_preprint.add_contributor(self.second_contrib)
        self.published_preprint.add_contributor(self.third_contrib)
        self.published_preprint.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))

        # first name suffix
        self.admin_contributor.suffix = 'Jr.'
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
 def test_citation_no_repeated_periods(self):
     self.published_preprint.title = 'A Study of Coffee.'
     self.published_preprint.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 9
0
 def test_two_authors(self):
     self.preprint.node.add_contributor(self.second_contrib)
     self.preprint.node.save()
     citation = render_citation(self.preprint, 'modern-language-association')
     assert_equal(citation, u'Tordoff, John, and Carson Wentz. “{}.” {}, {}. Web.'.format(
             self.preprint.node.title,
             self.preprint.provider.name,
             self.formated_date)
     )
Ejemplo n.º 10
0
 def test_citation_osf_provider(self):
     self.published_preprint.title = 'A Study of Coffee.'
     self.published_preprint.save()
     self.published_preprint.provider.name = 'Open Science Framework'
     self.published_preprint.provider.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 11
0
 def test_citation_no_repeated_periods(self):
     self.preprint.title = 'A Study of Coffee.'
     self.preprint.save()
     citation = render_citation(self.preprint,
                                'modern-language-association')
     assert_equal(
         citation, u'Tordoff, John. “{}” {}, {}. Web.'.format(
             self.preprint.title, self.preprint.provider.name,
             self.formated_date))
 def test_citation_osf_provider(self):
     self.published_preprint.title = 'A Study of Coffee.'
     self.published_preprint.save()
     self.published_preprint.provider.name = 'Open Science Framework'
     self.published_preprint.provider.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 13
0
 def test_citation_no_repeated_periods(self):
     self.preprint.node.title = 'A Study of Coffee.'
     self.preprint.node.save()
     citation = render_citation(self.preprint, 'modern-language-association')
     assert_equal(citation, u'Tordoff, John. “{}” {}, {}. Web.'.format(
             self.preprint.node.title,
             self.preprint.provider.name,
             self.formated_date)
     )
Ejemplo n.º 14
0
 def test_two_authors(self):
     self.node.add_contributor(self.second_contrib)
     self.node.save()
     res = self.app.get(self.published_preprint_url)
     assert_equal(res.status_code, 200)
     citation = res.json['data']['attributes']['citation']
     assert_equal(
         citation,
         render_citation(self.published_preprint,
                         'modern-language-association'))
Ejemplo n.º 15
0
 def test_two_authors(self):
     self.preprint.add_contributor(self.second_contrib)
     self.preprint.save()
     citation = render_citation(self.preprint,
                                'modern-language-association')
     assert_equal(
         citation,
         u'Tordoff, John, and Carson Wentz. “{}.” {}, {}. Web.'.format(
             self.preprint.title, self.preprint.provider.name,
             self.formated_date))
 def test_citation_osf_provider(self):
     self.preprint.node.title = 'A Study of Coffee.'
     self.preprint.node.save()
     self.preprint.provider.name = 'Open Science Framework'
     self.preprint.provider.save()
     citation = render_citation(self.preprint,
                                'modern-language-association')
     assert_equal(
         citation, u'Tordoff, John. “{}” {}, {}. Web.'.format(
             self.preprint.node.title, 'OSF Preprints', self.formated_date))
Ejemplo n.º 17
0
 def test_citation_osf_provider(self):
     self.preprint.node.title = 'A Study of Coffee.'
     self.preprint.node.save()
     self.preprint.provider.name = 'Open Science Framework'
     self.preprint.provider.save()
     citation = render_citation(self.preprint, 'modern-language-association')
     assert_equal(citation, u'Tordoff, John. “{}” {}, {}. Web.'.format(
             self.preprint.node.title,
             'OSF Preprints',
             self.formated_date)
     )
Ejemplo n.º 18
0
    def test_three_authors(self):
        self.preprint.node.add_contributor(self.second_contrib)
        self.preprint.node.add_contributor(self.third_contrib)
        self.preprint.node.save()
        citation = render_citation(self.preprint, 'modern-language-association')
        assert_equal(citation, u'Tordoff, John, et al. “{}.” {}, {}. Web.'.format(
                self.preprint.node.title,
                self.preprint.provider.name,
                self.formated_date)
        )

        # first name suffix
        self.user.suffix = 'Jr.'
        self.user.save()
        citation = render_citation(self.preprint, 'modern-language-association')
        assert_equal(citation, u'Tordoff, John, Jr., et al. “{}.” {}, {}. Web.'.format(
                self.preprint.node.title,
                self.preprint.provider.name,
                self.formated_date)
        )
Ejemplo n.º 19
0
    def test_three_authors(self):
        self.preprint.add_contributor(self.second_contrib)
        self.preprint.add_contributor(self.third_contrib)
        self.preprint.save()
        citation = render_citation(self.preprint,
                                   'modern-language-association')
        assert_equal(
            citation, u'Tordoff, John, et al. “{}.” {}, {}. Web.'.format(
                self.preprint.title, self.preprint.provider.name,
                self.formated_date))

        # first name suffix
        self.user.suffix = 'Jr.'
        self.user.save()
        citation = render_citation(self.preprint,
                                   'modern-language-association')
        assert_equal(
            citation, u'Tordoff, John, Jr., et al. “{}.” {}, {}. Web.'.format(
                self.preprint.title, self.preprint.provider.name,
                self.formated_date))
    def test_one_author(self):
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))

        # test_suffix
        self.admin_contributor.suffix = 'Junior'
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))

        # test_no_middle_names
        self.admin_contributor.suffix = ''
        self.admin_contributor.middle_names = ''
        self.admin_contributor.save()
        res = self.app.get(self.published_preprint_url)
        assert_equal(res.status_code, 200)
        citation = res.json['data']['attributes']['citation']
        assert_equal(citation, render_citation(self.published_preprint, 'modern-language-association'))
Ejemplo n.º 21
0
    def get_object(self):
        preprint = self.get_preprint()
        auth = get_user_auth(self.request)
        style = self.kwargs.get('style_id')

        if preprint.can_view(auth):
            try:
                citation = render_citation(node=preprint, style=style)
            except ValueError as err:  # style requested could not be found
                csl_name = re.findall(r'[a-zA-Z]+\.csl', str(err))[0]
                raise NotFound('{} is not a known style.'.format(csl_name))

            return {'citation': citation, 'id': style}

        raise PermissionDenied if auth.user else NotAuthenticated
Ejemplo n.º 22
0
    def get_object(self):
        preprint = self.get_preprint()
        auth = get_user_auth(self.request)
        style = self.kwargs.get('style_id')

        if preprint.node.is_public or preprint.node.can_view(auth) or preprint.is_published:
            try:
                citation = render_citation(node=preprint, style=style)
            except ValueError as err:  # style requested could not be found
                csl_name = re.findall('[a-zA-Z]+\.csl', err.message)[0]
                raise NotFound('{} is not a known style.'.format(csl_name))

            return {'citation': citation, 'id': style}

        raise PermissionDenied if auth.user else NotAuthenticated
Ejemplo n.º 23
0
 def test_passing_citations(self):
     node = Node()
     url_data_path = os.path.join(os.path.dirname(__file__), '../website/static/citeprocpy_test_data.json')
     with open(url_data_path) as url_test_data:
         data = json.load(url_test_data)['passes']
     not_matches = []
     for k, v in data.iteritems():
         try:
             citeprocpy = render_citation(node, k)
         except (TypeError, AttributeError):
             citeprocpy = ''
         if citeprocpy != v:
             not_matches.append(k)
             print k
     assert(len(not_matches) == 0)
Ejemplo n.º 24
0
 def test_failing_citations(self):
     node = Node()
     node.visible_contributors = OSFUser.objects.filter(fullname='Henrique Harman')
     url_data_path = os.path.join(os.path.dirname(__file__), '../website/static/citeprocpy_test_data.json')
     with open(url_data_path) as url_test_data:
         data = json.load(url_test_data)['fails']
     matches = []
     for k, v in data.iteritems():
         try:
             citeprocpy = render_citation(node, k)
         except (TypeError, AttributeError):
             citeprocpy = ''
         if citeprocpy == v:
             matches.append(k)
             print k
     assert(len(matches) == 0)
Ejemplo n.º 25
0
 def test_passing_citations(self):
     node = Node()
     url_data_path = os.path.join(
         os.path.dirname(__file__),
         '../website/static/citeprocpy_test_data.json')
     with open(url_data_path) as url_test_data:
         data = json.load(url_test_data)['passes']
     not_matches = []
     for k, v in data.iteritems():
         try:
             citeprocpy = render_citation(node, k)
         except (TypeError, AttributeError):
             citeprocpy = ''
         if citeprocpy != v:
             not_matches.append(k)
             print k
     assert (len(not_matches) == 0)