コード例 #1
0
    def setUp(self):
        super(FeedFileListViewTests, self).setUp()
        feed = Feed.objects.get(name=self.feedname)
        self.corresponding_feed_url = reverse("feed-detail", kwargs={"pk": feed.id})
        self.list_url = reverse("feedfile-list", kwargs={"pk": feed.id})

        # create a test file 
        test_file_path = self.test_dir
        self.test_file = test_file_path + '/file1.txt'
        file = open(self.test_file, "w")
        file.write("test file1")
        file.close()
        file = open(test_file_path + '/file2.txt', "w")
        file.write("test file2")
        file.close()

        # create two files in the DB "already uploaded" to the server)
        pl_inst = PluginInstance.objects.all()[0]
        #file = open(self.test_file, "r")
        #django_file = File(file)
        #feedfile = FeedFile(plugin_inst=pl_inst)
        #feedfile.fname.save("file2.txt", django_file, save=True)
        #feedfile.feed = [feed]
        #feedfile.save()
        #feedfile = FeedFile(plugin_inst=pl_inst)
        #feedfile.fname.save("file3.txt", django_file, save=True)
        #feedfile.feed = [feed]
        #feedfile.save()
        #file.close()
        feedfile = FeedFile(plugin_inst=pl_inst, feed=feed)
        feedfile.fname.name = 'file1.txt'
        feedfile.save()
        feedfile = FeedFile(plugin_inst=pl_inst, feed=feed)
        feedfile.fname.name = 'file2.txt'
        feedfile.save()
コード例 #2
0
ファイル: models.py プロジェクト: keni93/ChRIS_ultron_backEnd
 def register_output_files(self):
     """
     Custom method to register files generated by the plugin instance object
     with the REST API.
     """
     # initiate a Swift service connection
     conn = swiftclient.Connection(
         user=settings.SWIFT_USERNAME,
         key=settings.SWIFT_KEY,
         authurl=settings.SWIFT_AUTH_URL,
     )
     output_path = self.get_output_path()
     # get the full list of objects with prefix output_path in Swift storage
     object_list = conn.get_container(settings.SWIFT_CONTAINER_NAME,
                                      prefix=output_path,
                                      full_listing=True)[1]
     root_instance = self.get_root_instance()
     feed = root_instance.feed
     fileCount = 0
     for object in object_list:
         feedfile = FeedFile(plugin_inst=self, feed=feed)
         feedfile.fname.name = object['name']
         feedfile.save()
         fileCount += 1
     return fileCount
コード例 #3
0
 def setUp(self):
     super(FileResourceViewTests, self).setUp()
     feed = Feed.objects.get(name=self.feedname)
     pl_inst = PluginInstance.objects.all()[0]
     self.pl_inst = pl_inst
     # create a file in the DB "already uploaded" to the server
     feedfile = FeedFile(plugin_inst=pl_inst, feed=feed)
     feedfile.fname.name = '/tests/file1.txt'
     feedfile.save()
     self.download_url = reverse("feedfile-resource",
                                 kwargs={"pk": feedfile.id}) + 'file1.txt'
コード例 #4
0
    def register_output_files(self, *args, **kwargs):
        """
        Custom method to register files generated by the plugin instance object
        with the REST API.
        """
        d_swiftState = {}
        for k, v in kwargs.items():
            if k == 'swiftState': d_swiftState = v

        # initiate a Swift service connection
        conn = swiftclient.Connection(
            user=settings.SWIFT_USERNAME,
            key=settings.SWIFT_KEY,
            authurl=settings.SWIFT_AUTH_URL,
        )
        output_path = self.get_output_path()

        # the following gets the full list of objects in the swift storage
        # with prefix of <output_path>. Since there is a lag in consistency
        # of swift state from different clients, we poll here using the
        # information returned from pfcon that indicates how many files

        object_list = []
        pollLoop = 0
        maxPolls = 20
        if 'd_swiftstore' in d_swiftState.keys():
            objectsReportedInSwift = d_swiftState['d_swiftstore'][
                'filesPushed']
        else:
            objectsReportedInSwift = 0

        while len(
                object_list) <= objectsReportedInSwift and pollLoop < maxPolls:
            object_list = conn.get_container(settings.SWIFT_CONTAINER_NAME,
                                             prefix=output_path,
                                             full_listing=True)[1]
            time.sleep(0.2)
            pollLoop += 1
        root_instance = self.get_root_instance()
        feed = root_instance.feed
        fileCount = 0
        for object in object_list:
            feedfile = FeedFile(plugin_inst=self, feed=feed)
            feedfile.fname.name = object['name']
            feedfile.save()
            fileCount += 1
        return {
            'status': True,
            'l_object': object_list,
            'total': fileCount,
            'outputPath': output_path,
            'pollLoop': pollLoop
        }
コード例 #5
0
 def register_output_files(self):
     """
     Custom method to register files generated by the plugin instance object
     with the REST API.
     """
     fileCount = 0
     root_instance = self.get_root_instance()
     feed = root_instance.feed
     output_path = self.get_output_path()
     for (dirpath, dirnames, filenames) in os.walk(output_path):
         for name in filenames:
             feedfile = FeedFile(plugin_inst=self, feed=feed)
             feedfile.fname.name = os.path.join(dirpath, name)
             feedfile.save()
             fileCount += 1
     return fileCount
コード例 #6
0
    def setUp(self):
        super(FileResourceViewTests, self).setUp()
        feed = Feed.objects.get(name=self.feedname)

        # create a test file 
        test_file_path = self.test_dir
        self.test_file = test_file_path + '/file1.txt'
        file = open(self.test_file, "w")
        file.write("test file")
        file.close()
            
        # create a file in the DB "already uploaded" to the server
        pl_inst = PluginInstance.objects.all()[0]
        feedfile = FeedFile(plugin_inst=pl_inst, feed=feed)
        feedfile.fname.name = 'file1.txt'
        feedfile.save()
        self.download_url = reverse("file-resource",
                                    kwargs={"pk": feedfile.id}) + 'file1.txt'
コード例 #7
0
    def setUp(self):
        super(FeedFileDetailViewTests, self).setUp()
        feed = Feed.objects.get(name=self.feedname)
        self.corresponding_feed_url = reverse("feed-detail", kwargs={"pk": feed.id})

        # create a test file 
        test_file_path = self.test_dir
        self.test_file = test_file_path + '/file1.txt'
        file = open(self.test_file, "w")
        file.write("test file")
        file.close()

        # create a file in the DB "already uploaded" to the server
        pl_inst = PluginInstance.objects.all()[0]
        feedfile = FeedFile(plugin_inst=pl_inst, feed=feed)
        feedfile.fname.name = 'file1.txt'
        feedfile.save()

        self.read_update_delete_url = reverse("feedfile-detail", kwargs={"pk": feedfile.id})