Esempio n. 1
0
    def run_test_document_application(self, private):
        with open(
                Path(__file__).parent.joinpath('resources', 'document.xlsx'),
                "rb") as file:
            app = DocumentApplication(path=TM1PY_APP_FOLDER,
                                      name=DOCUMENT_NAME,
                                      content=file.read())
            self.tm1.applications.create(application=app, private=private)

        app_retrieved = self.tm1.applications.get(app.path,
                                                  app.application_type,
                                                  app.name,
                                                  private=private)
        self.assertEqual(app, app_retrieved)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertTrue(exists)

        self.tm1.applications.delete(app.path,
                                     app.application_type,
                                     app.name,
                                     private=private)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertFalse(exists)
Esempio n. 2
0
    def get_document(self,
                     path: str,
                     name: str,
                     private: bool = False,
                     **kwargs) -> DocumentApplication:
        """ Get Excel Application from TM1 Server in binary format. Can be dumped to file.

        :param path: path through folder structure to application. For instance: "Finance/P&L.xlsx"
        :param name: name of the application
        :param private: boolean
        :return: Return DocumentApplication
        """
        if not name.endswith(ApplicationTypes.DOCUMENT.suffix):
            name += ApplicationTypes.DOCUMENT.suffix

        contents = 'PrivateContents' if private else 'Contents'
        mid = "".join([
            format_url("/Contents('{}')", element)
            for element in path.split('/')
        ])
        url = format_url("/api/v1/Contents('Applications')" + mid + "/" +
                         contents + "('{name}')/Document/Content",
                         name=name)

        response = self._rest.GET(url, **kwargs)
        return DocumentApplication(path, name, response.content)
Esempio n. 3
0
 def create_document_from_file(self,
                               path_to_file,
                               path,
                               name,
                               private=False):
     with open(path_to_file, 'rb') as file:
         app = DocumentApplication(path=path,
                                   name=name,
                                   content=file.read())
         return self.create(application=app, private=private)
Esempio n. 4
0
    def run_document_application(self, private):
        with open(
                Path(__file__).parent.joinpath('resources', 'document.xlsx'),
                "rb") as file:
            app = DocumentApplication(path=self.tm1py_app_folder,
                                      name=self.document_name,
                                      content=file.read())
            self.tm1.applications.create(application=app, private=private)

        app_retrieved = self.tm1.applications.get(app.path,
                                                  app.application_type,
                                                  app.name,
                                                  private=private)
        self.assertEqual(app_retrieved.last_updated[:10],
                         datetime.today().strftime('%Y-%m-%d'))
        self.assertIsNotNone(app_retrieved.file_id)
        self.assertIsNotNone(app_retrieved.file_name)

        self.assertEqual(app, app_retrieved)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertTrue(exists)

        self.tm1.applications.rename(
            app.path,
            application_type=ApplicationTypes.DOCUMENT,
            application_name=app.name,
            new_application_name=app.name + self.rename_suffix,
            private=private)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertFalse(exists)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name + self.rename_suffix,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertTrue(exists)

        self.tm1.applications.delete(app.path,
                                     app.application_type,
                                     app.name + self.rename_suffix,
                                     private=private)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name + self.rename_suffix,
            application_type=ApplicationTypes.DOCUMENT,
            private=private)
        self.assertFalse(exists)
    def create_document_from_file(self, path_to_file: str, application_path: str, application_name: str,
                                  private: bool = False, **kwargs) -> Response:
        """ Create DocumentApplication in TM1 from local file

        :param path_to_file:
        :param application_path:
        :param application_name:
        :param private:
        :return:
        """
        with open(path_to_file, 'rb') as file:
            application = DocumentApplication(path=application_path, name=application_name, content=file.read())
            return self.create(application=application, private=private, **kwargs)
Esempio n. 6
0
    def get_document(self, path, name, private=False):
        """ Get Excel Application from TM1 Server in binary format. Can be dumped to file.

        :param path: path through folder structure to application. For instance: "Finance/P&L.xlsx"
        :param name: name of the application
        :param private: boolean
        :return: Return DocumentApplication
        """
        if not name.endswith(ApplicationTypes.DOCUMENT.suffix):
            name += ApplicationTypes.DOCUMENT.suffix

        contents = 'PrivateContents' if private else 'Contents'
        mid = "".join(
            ["/Contents('{}')".format(element) for element in path.split('/')])
        request = "/api/v1/Contents('Applications'){dynamic_mid}/{contents}('{name}')/Document/Content".format(
            dynamic_mid=mid, contents=contents, name=name)
        response = self._rest.GET(request)
        return DocumentApplication(path, name, response.content)