class SingleReferenceTestCase(TestCase):

    def setUp(self):
        self.reference = Reference(bibtex=fluff)
        self.reference.save()

    def test_key(self):
        """Check that the key can be extracted"""
        self.assertEqual(self.reference.key, 'steinhauser2009nature')

    def test_year(self):
        """Check that the year can be extracted"""
        self.assertEqual(self.reference.get_year(), 2009)

    def test_title(self):
        """Check that the title can be extracted"""
        self.assertEqual(self.reference.get_title(), "The nature of navel fluff")

    def test_authors(self):
        """Check that authors can be extracted"""
        self.assertIn('Steinhauser', self.reference.get_authors())
    
    def test_html(self):
        """Check that the html is output correctly"""
        self.assertEqual(self.reference.get_html(csl=csl), html)

    def test_abstract(self):
        """Check that the abstract is returned"""    
        self.assertIn('lint', self.reference.get_abstract())
        self.assertIn('Why do men have nipples', self.reference.get_abstract())
Exemplo n.º 2
0
class SingleReferenceTestCase(TestCase):
    def setUp(self):
        self.reference = Reference(bibtex=fluff)
        self.reference.save()

    def test_key(self):
        """Check that the key can be extracted"""
        self.assertEqual(self.reference.key, 'steinhauser2009nature')

    def test_year(self):
        """Check that the year can be extracted"""
        self.assertEqual(self.reference.get_year(), 2009)

    def test_title(self):
        """Check that the title can be extracted"""
        self.assertEqual(self.reference.get_title(),
                         "The nature of navel fluff")

    def test_authors(self):
        """Check that authors can be extracted"""
        self.assertIn('Steinhauser', self.reference.get_authors())

    def test_html(self):
        """Check that the html is output correctly"""
        self.assertEqual(self.reference.get_html(csl=csl), html)

    def test_abstract(self):
        """Check that the abstract is returned"""
        self.assertIn('lint', self.reference.get_abstract())
        self.assertIn('Why do men have nipples', self.reference.get_abstract())
class ReferenceViewTest(TestCase):

    def setUp(self):
        self.reference = Reference(bibtex=fluff)
        self.reference.save()
        self.reference.tags.add('blah')

    def test_get_bib(self):
        url = reverse('show_reference_as_bibtex', kwargs=dict(key=self.reference.key))
        response = self.client.get(url)

    def test_get_html(self):
        url = reverse('show_reference', kwargs=dict(key=self.reference.key))
        response = self.client.get(url)

    def test_tagging(self):
        url = reverse('admin_tagging', kwargs=dict(tag_name='blah'))
        response = self.client.get(url)
Exemplo n.º 4
0
class ReferenceViewTest(TestCase):
    def setUp(self):
        self.reference = Reference(bibtex=fluff)
        self.reference.save()
        self.reference.tags.add('blah')

    def test_get_bib(self):
        url = reverse('show_reference_as_bibtex',
                      kwargs=dict(key=self.reference.key))
        response = self.client.get(url)

    def test_get_html(self):
        url = reverse('show_reference', kwargs=dict(key=self.reference.key))
        response = self.client.get(url)

    def test_tagging(self):
        url = reverse('admin_tagging', kwargs=dict(tag_name='blah'))
        response = self.client.get(url)
    def handle(self, *args, **options):
        fname = options['in_file']
        self.stdout.write('-- Importing references in %s' % fname)
        if not os.path.exists(fname):
            CommandError('Input file does not exist.')

        if options['force']:
            self.stdout.write('-- Force import' + os.linesep)

        if options['clear']:
            self.stdout.write('-- Clear tags before import' + os.linesep)

        with open(fname, 'r') as f:
            contents = f.read().decode('utf-8')

        cont =  contents.split("@")
        cont.pop(0)

        allkeys = [x.key for x in Reference.objects.all()]

        nsuccess = 0
        nfail = 0
        nfiles = 0

        for rec in cont:
            rkey = get_key(rec)
            ref = Reference.objects.filter(key = rkey)
            if ref:
                bib = Reference.objects.get(key = rkey)
                bib.bibtex = '@%s' % rec
                action = 'Updating'
            else:
                bib = Reference(bibtex = '@%s'% rec)
                action = 'Creating'
            #pdb.set_trace()
            try: 
                bib.clean()
            except:
                pdb.set_trace()
                self.stderr.write("Warning: Failed to load @%s" % rec)
                nfail += 1
                continue
            if not rkey in allkeys or options['force']:
                self.stdout.write("%s %s" % (action, rkey))
                bib.save()
                if options['clear']:
                    bib.tags.clear()
                for a in options['tags']:
                            bib.tags.add(a)
                keywords = get_keywords(rec)
                if keywords:
                    for k in keywords:
                        bib.tags.add(k)
                if os.path.exists('files/%s' % rkey):
                    files = os.listdir('files/%s' % rkey)
                    for f in files:
                        shutil.copy('files/%s/%s' % (rkey, f), '%s/resources/%s' % (settings.MEDIA_ROOT, f))
                        res = bib.resource_set.create(file='resources/%s' % f, title='%s' % f)
                        self.stdout.write('Found and added %s' % f)
                        nfiles += 1
                bib.save()
                nsuccess += 1    
                allkeys.append(rkey.decode())

            else:
                self.stderr.write("Skipped pre-existing key: %s" % rkey)
                nfail += 1

        self.stdout.write(os.linesep + "=> Imported %i references and %i files. %i failed." % (nsuccess, nfiles, nfail))
 def setUp(self):
     self.reference = Reference(bibtex=fluff)
     self.reference.save()
     self.reference.tags.add('blah')
 def setUp(self):
     self.reference = Reference(bibtex=fluff)
     self.reference.save()
 def test_accent(self):
     reference = Reference(bibtex=erdos)
     self.assertEqual(reference.get_authors(), u'B Bollob\u2019as & P Erdos')
    def handle(self, *args, **options):
        fname = options['in_file']
        self.stdout.write('-- Importing references in %s' % fname)
        if not os.path.exists(fname):
            CommandError('Input file does not exist.')

        if options['force']:
            self.stdout.write('-- Force import' + os.linesep)

        if options['clear']:
            self.stdout.write('-- Clear tags before import' + os.linesep)

        with open(fname, 'r') as f:
            contents = f.read().decode('utf-8')

        cont = contents.split("@")
        cont.pop(0)

        allkeys = [x.key for x in Reference.objects.all()]

        nsuccess = 0
        nfail = 0
        nfiles = 0

        for rec in cont:
            rkey = get_key(rec)
            ref = Reference.objects.filter(key=rkey)
            if ref:
                bib = Reference.objects.get(key=rkey)
                bib.bibtex = '@%s' % rec
                action = 'Updating'
            else:
                bib = Reference(bibtex='@%s' % rec)
                action = 'Creating'
            #pdb.set_trace()
            try:
                bib.clean()
            except:
                pdb.set_trace()
                self.stderr.write("Warning: Failed to load @%s" % rec)
                nfail += 1
                continue
            if not rkey in allkeys or options['force']:
                self.stdout.write("%s %s" % (action, rkey))
                bib.save()
                if options['clear']:
                    bib.tags.clear()
                for a in options['tags']:
                    bib.tags.add(a)
                keywords = get_keywords(rec)
                if keywords:
                    for k in keywords:
                        bib.tags.add(k)
                if os.path.exists('files/%s' % rkey):
                    files = os.listdir('files/%s' % rkey)
                    for f in files:
                        shutil.copy(
                            'files/%s/%s' % (rkey, f),
                            '%s/resources/%s' % (settings.MEDIA_ROOT, f))
                        res = bib.resource_set.create(file='resources/%s' % f,
                                                      title='%s' % f)
                        self.stdout.write('Found and added %s' % f)
                        nfiles += 1
                bib.save()
                nsuccess += 1
                allkeys.append(rkey.decode())

            else:
                self.stderr.write("Skipped pre-existing key: %s" % rkey)
                nfail += 1

        self.stdout.write(
            os.linesep + "=> Imported %i references and %i files. %i failed." %
            (nsuccess, nfiles, nfail))
Exemplo n.º 10
0
 def setUp(self):
     self.reference = Reference(bibtex=fluff)
     self.reference.save()
     self.reference.tags.add('blah')
Exemplo n.º 11
0
 def setUp(self):
     self.reference = Reference(bibtex=fluff)
     self.reference.save()
Exemplo n.º 12
0
 def test_accent(self):
     reference = Reference(bibtex=erdos)
     self.assertEqual(reference.get_authors(),
                      u'B Bollob\u2019as & P Erdos')