Ejemplo n.º 1
0
    def test_incomplete_entries(self):
        self.repo.faceted_data = Mock(return_value=self.faceted_data)

        # make our entries incomplete in various ways
        entry = DocumentEntry(self.repo.store.documententry_path("1"))
        entry.published = None
        entry.save()

        # try very hard to remove title from everywhere
        entry = DocumentEntry(self.repo.store.documententry_path("2"))
        del entry.title
        entry.save()
        g = rdflib.Graph().parse(self.repo.store.distilled_path("2"))
        g.remove((rdflib.URIRef("http://localhost:8000/res/base/2"),
                  self.repo.ns['dcterms'].title, rdflib.Literal("Doc #2")))
        with open(self.repo.store.distilled_path("2"), "wb") as fp:
            g.serialize(fp, format="pretty-xml")

        os.unlink(self.repo.store.distilled_path("3"))

        # entries w/o published date and w/o distilled file should not
        # be published, but w/o title is OK
        with silence():  # avoid warnings about stale entry files
            # since the downloaded and intermediate file
            # is missing, which would exist in a real
            # scenario
            self.assertEqual(len(list(self.repo.news_entries())), 23)

            # also make sure that corresponding faceted_entries do not
            # show these non-published entries
            self.assertEqual(len(self.repo.news_facet_entries()), 23)
Ejemplo n.º 2
0
    def test_incomplete_entries(self):
        self.repo.faceted_data = Mock(return_value=self.faceted_data)

        # make our entries incomplete in various ways
        entry = DocumentEntry(self.repo.store.documententry_path("1"))
        entry.published = None
        entry.save()

        # try very hard to remove title from everywhere
        entry = DocumentEntry(self.repo.store.documententry_path("2"))
        del entry.title
        entry.save()
        g = rdflib.Graph().parse(self.repo.store.distilled_path("2"))
        g.remove((rdflib.URIRef("http://localhost:8000/res/base/2"),
                  self.repo.ns['dcterms'].title,
                  rdflib.Literal("Doc #2")))
        with open(self.repo.store.distilled_path("2"), "wb") as fp:
            g.serialize(fp, format="pretty-xml")

        os.unlink(self.repo.store.distilled_path("3"))

        # entries w/o published date and w/o distilled file should not
        # be published, but w/o title is OK
        with silence():  # avoid warnings about stale entry files
                         # since the downloaded and intermediate file
                         # is missing, which would exist in a real
                         # scenario
            self.assertEqual(len(list(self.repo.news_entries())),
                             23)

            # also make sure that corresponding faceted_entries do not
            # show these non-published entries
            self.assertEqual(len(self.repo.news_facet_entries()), 23)
Ejemplo n.º 3
0
    def test_files(self):
        # it'd be better to test _get_context, _get_common_graph and
        # _get_term_graph in isolation, but _create_api_files contains
        # common code to serialize the structures to files. Easier to
        # test all three.
        #
        # don't include all default ontologies to cut down on test
        # time, SKOS+FOAF ought to be enough.
        self.repo.ns = ({
            "foaf": "http://xmlns.com/foaf/0.1/",
            'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
            'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
            'owl': 'http://www.w3.org/2002/07/owl#',
            'skos': 'http://www.w3.org/2004/02/skos/core#'
        })
        with silence():
            got = Resources([self.repo],
                            self.datadir + "/data/rsrc",
                            legacyapi=True).make(css=False,
                                                 js=False,
                                                 img=False,
                                                 xml=False,
                                                 api=True)
        s = os.sep
        want = {
            'json': [
                s.join(['rsrc', 'api', 'context.json']),
                s.join(['rsrc', 'api', 'common.json']),
                s.join(['rsrc', 'api', 'terms.json'])
            ]
        }
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/context.json") as fp:
            got = json.load(fp)
        with open("test/files/api/jsonld-context.json") as fp:
            want = json.load(fp)
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/terms.json") as fp:
            got = json.load(fp)
        with open("test/files/api/var-terms.json") as fp:
            want = json.load(fp)
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/common.json") as fp:
            got = json.load(fp)
        with open("test/files/api/var-common.json") as fp:
            want = json.load(fp)
        self.assertEqual(want, got)
Ejemplo n.º 4
0
 def test_mislabeled(self):
     path = self.datadir + os.sep + "out.xml"
     try:
         with silence():
             with open(path, "wb") as fp:
                 filetype = self.reader.read("test/files/wordreader/mislabeled.doc",
                                             fp)
         self.assertEqual(filetype, "docx")
         self.assertTrue(os.path.exists(path))
         tree = etree.parse(path)
         self.assertEqual("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document",
                          tree.getroot().tag)
         xpath = '//*[contains(text(), "mis-labeled as a .doc file")]'
         self.assertTrue(tree.getroot().xpath(xpath))
     except ExternalCommandError as e:
         raise unittest.SkipTest("Antiword does not seem to be installed")
Ejemplo n.º 5
0
 def test_nonexistent_resource(self):
     # test9: nonexistent resources should not be included
     s = os.sep
     test = staticmockclass()        
     test.config.cssfiles = ['nonexistent.css']
     want = {'css':[],
             'img':[s.join(['rsrc', 'img','test.png'])],
             'js':[s.join(['rsrc', 'js','test.js'])],
             'xml':[s.join(['rsrc', 'resources.xml'])]
     }
     with silence():
         got = Resources([test], self.tempdir+os.sep+'rsrc',
                         cssfiles=[],
                         jsfiles=[],
                         imgfiles=[]).make(api=False)
     self.assertEqual(want,got)
Ejemplo n.º 6
0
 def test_nonexistent_resource(self):
     # test9: nonexistent resources should not be included
     s = os.sep
     test = staticmockclass()        
     test.config.cssfiles = ['nonexistent.css']
     want = {'css':[],
             'img':[s.join(['rsrc', 'img','test.png'])],
             'js':[s.join(['rsrc', 'js','test.js'])],
             'xml':[s.join(['rsrc', 'resources.xml'])]
     }
     with silence():
         got = Resources([test], self.tempdir+os.sep+'rsrc',
                         cssfiles=[],
                         jsfiles=[],
                         imgfiles=[]).make(api=False)
     self.assertEqual(want,got)
Ejemplo n.º 7
0
 def test_mislabeled(self):
     path = self.datadir + os.sep + "out.xml"
     try:
         with silence():
             with open(path, "wb") as fp:
                 filetype = self.reader.read(
                     "test/files/wordreader/mislabeled.doc", fp)
         self.assertEqual(filetype, "docx")
         self.assertTrue(os.path.exists(path))
         tree = etree.parse(path)
         self.assertEqual(
             "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}document",
             tree.getroot().tag)
         xpath = '//*[contains(text(), "mis-labeled as a .doc file")]'
         self.assertTrue(tree.getroot().xpath(xpath))
     except ExternalCommandError as e:
         raise unittest.SkipTest("Antiword does not seem to be installed")
Ejemplo n.º 8
0
    def test_files(self):
        # it'd be better to test _get_context, _get_common_graph and
        # _get_term_graph in isolation, but _create_api_files contains
        # common code to serialize the structures to files. Easier to
        # test all three.
        #
        # don't include all default ontologies to cut down on test
        # time, SKOS+FOAF ought to be enough.
        self.repo.ns = ({"foaf": "http://xmlns.com/foaf/0.1/",
                         'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
                         'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
                         'owl': 'http://www.w3.org/2002/07/owl#',
                         'skos': 'http://www.w3.org/2004/02/skos/core#'})
        with silence():
            got = Resources([self.repo], self.datadir + "/data/rsrc",
                            legacyapi=True).make(css=False, js=False, img=False, xml=False, api=True)
        s = os.sep
        want = {'json': [s.join(['rsrc','api','context.json']),
                         s.join(['rsrc','api','common.json']),
                         s.join(['rsrc','api','terms.json'])]}
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/context.json") as fp:
            got  = json.load(fp)
        with open("test/files/api/jsonld-context.json") as fp:
            want = json.load(fp)
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/terms.json") as fp:
            got  = json.load(fp)
        with open("test/files/api/var-terms.json") as fp:
            want = json.load(fp)
        self.assertEqual(want, got)

        with open(self.datadir + "/data/rsrc/api/common.json") as fp:
            got  = json.load(fp)
        with open("test/files/api/var-common.json") as fp:
            want = json.load(fp)
        self.assertEqual(want,got)