Exemplo n.º 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.
        """

        # 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))

        self.wait_for_file_change(filename_real, initial_mtime)

        results = get_tracker_extract_output (filename, mimetype)
        keyDict = expectedKey or prop
        self.assertIn (TEST_VALUE, results[keyDict])
        self.__clean_property (prop, filename, False)
Exemplo n.º 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_output (filename, mimetype)
        self.assertIn ("testTag", results ["nao:hasTag"])
Exemplo n.º 3
0
    def __writeback_test(self, filename, 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.
        """

        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))

        # There is no way to know when the operation is finished
        time.sleep(REASONABLE_TIMEOUT)

        results = get_tracker_extract_output(filename)
        keyDict = expectedKey or prop
        self.assertIn(TEST_VALUE, results[keyDict])
        self.__clean_property(prop, filename, False)
Exemplo n.º 4
0
    def __writeback_hasTag_test(self, filename):

        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_output(filename)
        self.assertIn("testTag", results["nao:hasTag"])
Exemplo n.º 5
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))

        self.wait_for_file_change(filename_real, initial_mtime)

        results = get_tracker_extract_output (filename, mimetype)
        keyDict = expectedKey or prop
        self.assertIn (TEST_VALUE, results[keyDict])
        self.__clean_property (prop, filename, False)
Exemplo n.º 6
0
    def generic_test_extraction (self):
        abs_description = os.path.abspath (self.rel_description)

        # 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.configParser.get ("TestFile", "Filename")
        self.file_to_extract = os.path.join (desc_root, filename_to_extract)

        result = get_tracker_extract_output(self.file_to_extract)
        self.__assert_extraction_ok (result)
Exemplo n.º 7
0
    def generic_test_extraction(self):
        abs_description = os.path.abspath(self.rel_description)

        # 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.configParser.get("TestFile", "Filename")
        self.file_to_extract = os.path.join(desc_root, filename_to_extract)

        result = get_tracker_extract_output(self.file_to_extract)
        self.__assert_extraction_ok(result)
Exemplo n.º 8
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_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])
Exemplo n.º 9
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 ;
                 nie:contentCreated ?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)

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

        # Check the value is written in the file
        metadata = get_tracker_extract_output(self.get_test_filename_jpeg())
        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])