Example #1
0
    def __writeback_test(self, filename, mimetype, prop, expectedKey=None):
        """
        Set a value in @prop for the @filename. Then ask tracker-extractor
        for metadata and check in the results dictionary if the property is there.

        Note: given the special translation of some property-names in the dictionary
        with extracted metadata, there is an optional parameter @expectedKey
        to specify what property to check in the dictionary. If None, then
        the @prop is used.
        """

        path = self.prepare_test_image(self.datadir_path(filename))
        initial_mtime = path.stat().st_mtime

        TEST_VALUE = prop.replace(":", "") + "test"
        SPARQL_TMPL = """
           DELETE { ?u %s ?v } WHERE { ?u nie:url '%s' ; %s ?v }
           INSERT { ?u %s '%s' }
           WHERE  { ?u nie:url '%s' }
        """
        self.tracker.update(
            SPARQL_TMPL %
            (prop, path.as_uri(), prop, prop, TEST_VALUE, path.as_uri()))

        log("Waiting for change on %s" % path)
        self.wait_for_file_change(path, initial_mtime)
        log("Got the change")

        results = get_tracker_extract_jsonld_output(path, mimetype)
        keyDict = expectedKey or prop
        self.assertIn(TEST_VALUE, results[keyDict])
Example #2
0
    def __writeback_hasTag_test(self, filename, mimetype):

        SPARQL_TMPL = """
            INSERT {
              <test://writeback-hasTag-test/1> a nao:Tag ;
                        nao:prefLabel "testTag" .

              ?u nao:hasTag <test://writeback-hasTag-test/1> .
            } WHERE {
              ?u nie:url '%s' .
            }
        """

        CLEAN_VALUE = """
           DELETE {
              <test://writeback-hasTag-test/1> a rdfs:Resource.
              ?u nao:hasTag <test://writeback-hasTag-test/1> .
           } WHERE {
              ?u nao:hasTag <test://writeback-hasTag-test/1> .
           }
        """

        self.tracker.update(SPARQL_TMPL % (filename))

        time.sleep(REASONABLE_TIMEOUT)

        results = get_tracker_extract_jsonld_output(filename, mimetype)
        self.assertIn("testTag", results["nao:hasTag"])
Example #3
0
    def __writeback_test (self, filename, mimetype, prop, expectedKey=None):
        """
        Set a value in @prop for the @filename. Then ask tracker-extractor
        for metadata and check in the results dictionary if the property is there.

        Note: given the special translation of some property-names in the dictionary
        with extracted metadata, there is an optional parameter @expectedKey
        to specify what property to check in the dictionary. If None, then
        the @prop is used.
        """

        # FIXME: filename is actually a URI! :(
        filename_real = filename[len('file://'):]
        initial_mtime = os.stat(filename_real).st_mtime

        TEST_VALUE = prop.replace (":","") + "test"
        SPARQL_TMPL = """
           INSERT { ?u %s '%s' }
           WHERE  { ?u nie:url '%s' }
        """ 
        self.__clean_property (prop, filename)
        self.tracker.update (SPARQL_TMPL % (prop, TEST_VALUE, filename))

        log("Waiting for change on %s" % filename_real)
        self.wait_for_file_change(filename_real, initial_mtime)
        log("Got the change")

        results = get_tracker_extract_jsonld_output (filename, mimetype)
        keyDict = expectedKey or prop
        self.assertIn (TEST_VALUE, results[keyDict])
        self.__clean_property (prop, filename, False)
    def test_01_NB217627_content_created_date(self):
        """
        NB#217627 - Order if results is different when an image is marked as favorite.
        """
        jpeg_path = self.prepare_test_image(self.datadir_path('writeback-test-1.jpeg'))
        tif_path = self.prepare_test_image(self.datadir_path('writeback-test-2.tif'))
        png_path = self.prepare_test_image(self.datadir_path('writeback-test-4.png'))

        query_images = """
          SELECT nie:url(?u) ?contentCreated WHERE {
              ?u a nfo:Visual ;
              nfo:fileLastModified ?contentCreated
          } ORDER BY ?contentCreated
          """
        results = self.tracker.query(query_images)
        self.assertEqual(len(results), 3, results)

        log("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp")
        time.sleep(2)

        initial_mtime = jpeg_path.stat().st_mtime

        # This triggers the writeback
        mark_as_favorite = """
         INSERT {
           ?u nao:hasTag nao:predefined-tag-favorite .
         } WHERE {
           ?u nie:url <%s> .
         }
        """ % jpeg_path.as_uri()
        self.tracker.update(mark_as_favorite)
        log("Setting favorite in <%s>" % jpeg_path.as_uri())

        self.wait_for_file_change(jpeg_path, initial_mtime)

        # Check the value is written in the file
        metadata = get_tracker_extract_jsonld_output(jpeg_path, "")

        tags = metadata.get('nao:hasTag', [])
        tag_names = [tag['nao:prefLabel'] for tag in tags]
        self.assertIn(self.favorite, tag_names,
                      "Tag hasn't been written in the file")

        # Now check the modification date of the files and it should be the same :)
        new_results = self.tracker.query(query_images)
        # for (uri, date) in new_results:
        ##     print "Checking dates of <%s>" % uri
        ##     previous_date = convenience_dict[uri]
        ##     print "Before: %s \nAfter : %s" % (previous_date, date)
        ##     self.assertEquals (date, previous_date, "File <%s> has change its contentCreated date!" % uri)

        # Indeed the order of the results should be the same
        for i in range(0, len(results)):
            self.assertEqual(results[i][0], new_results[i][0], "Order of the files is different")
            self.assertEqual(results[i][1], new_results[i][1], "Date has change in file <%s>" % results[i][0])
    def test_01_NB217627_content_created_date(self):
        """
        NB#217627 - Order if results is different when an image is marked as favorite.
        """
        query_images = """
          SELECT nie:url(?u) ?contentCreated WHERE {
              ?u a nfo:Visual ;
              nfo:fileLastModified ?contentCreated
          } ORDER BY ?contentCreated
          """
        results = self.tracker.query(query_images)
        self.assertEquals(len(results), 3, results)

        log("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp"
            )
        time.sleep(2)

        url = self.get_test_filename_jpeg()

        filename = url[len('file://'):]
        initial_mtime = os.stat(filename).st_mtime

        # This triggers the writeback
        mark_as_favorite = """
         INSERT {
           ?u nao:hasTag nao:predefined-tag-favorite .
         } WHERE {
           ?u nie:url <%s> .
         }
        """ % url
        self.tracker.update(mark_as_favorite)
        log("Setting favorite in <%s>" % url)

        self.wait_for_file_change(filename, initial_mtime)

        # Check the value is written in the file
        metadata = get_tracker_extract_jsonld_output(filename, "")
        self.assertIn(self.favorite, metadata["nao:hasTag"],
                      "Tag hasn't been written in the file")

        # Now check the modification date of the files and it should be the same :)
        new_results = self.tracker.query(query_images)
        ## for (uri, date) in new_results:
        ##     print "Checking dates of <%s>" % uri
        ##     previous_date = convenience_dict[uri]
        ##     print "Before: %s \nAfter : %s" % (previous_date, date)
        ##     self.assertEquals (date, previous_date, "File <%s> has change its contentCreated date!" % uri)

        # Indeed the order of the results should be the same
        for i in range(0, len(results)):
            self.assertEquals(results[i][0], new_results[i][0],
                              "Order of the files is different")
            self.assertEquals(results[i][1], new_results[i][1],
                              "Date has change in file <%s>" % results[i][0])
Example #6
0
    def generic_test_extraction(self):
        abs_description = os.path.abspath(self.descfile)

        # Filename contains the file to extract, in a relative path to the description file
        desc_root, desc_file = os.path.split(abs_description)

        filename_to_extract = self.spec['test']['Filename']
        self.file_to_extract = os.path.join(desc_root, filename_to_extract)

        result = get_tracker_extract_jsonld_output(self.file_to_extract)
        self.__assert_extraction_ok(result)
    def test_external_cue_sheet(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            datadir = os.path.join(os.getcwd() + "/test-extraction-data")
            shutil.copy(os.path.join(datadir, 'audio', 'cuesheet-test.cue'),
                        tmpdir)

            audio_path = os.path.join(tmpdir, 'cuesheet-test.flac')
            create_test_flac(audio_path, duration=6 * 60)

            result = get_tracker_extract_jsonld_output(audio_path)

        self.assert_extract_result_matches_spec(self.spec(audio_path), result,
                                                audio_path, __file__)