Example #1
0
    def test_all(my):

        Batch()
        from pyasm.web.web_init import WebInit

        WebInit().execute()

        test_env = UnittestEnvironment()
        test_env.create()
        my.transaction = Transaction.get(create=True)
        try:

            my.person = Person.create("Unit", "Test", "ComputerWorld", "Fake Unittest Person")
            my.search_type = my.person.get_search_type()
            my.search_id = my.person.get_id()
            my.context = "test"
            my.full_context = "test/subtest"

            my._test_pipeline()
            my._test_pipeline_connects()

            my._test_schema()
            my._test_snapshot()
            my._test_level()
            my._test_naming_util()
            my._test_sobject_hierarchy()

            my._test_add_tasks()
        finally:
            my.transaction.rollback()
            Project.set_project("unittest")

            test_env.delete()
Example #2
0
    def _test_cache(my):
        from pyasm.common import Config

        Config.set_value("security", "mode", "cache", no_exception=True)
        # Config.set_value("security", "authenticate_class", "pyasm.security.authenticate_test.AutocreateAuthenticate", no_exception=True)
        Config.set_value(
            "security", "authenticate_class", "pyasm.security.mms_authenticate.MMSAuthenticate", no_exception=True
        )
        mode = Config.get_value("security", "authenticate_class", use_cache=False)

        mode = Config.get_value("security", "mode", use_cache=False)
        my.assertEquals(mode, "cache")

        # verify that the user exists in the database
        search = Search("sthpw/login")
        search.add_filter("login", "foofoo")
        login = search.get_sobject()
        my.assertEquals(None, login)

        from pyasm.search import Transaction

        transaction = Transaction.get(create=True)
        transaction.start()

        my.security.login_user("foofoo", "wow")

        # verify that the user exists in the database
        search = Search("sthpw/login")
        search.add_filter("login", "foofoo")
        login = search.get_sobject()
        my.assertNotEquals(None, login)
Example #3
0
    def test_all(my):
        """entry point function"""
        my.description = "Checkin unit test"
        my.errors = []

        Batch()

        # FIXME: this is needed for the triggers to be registerd. These
        # triggers have nothing to do with the web
        from pyasm.web import WebInit

        WebInit().execute()

        test_env = UnittestEnvironment()
        test_env.create()
        my.transaction = Transaction.get(create=True)

        Project.set_project("unittest")

        try:
            # Command.execute_cmd(my)

            # undo the command
            # undo = UndoCmd()
            # undo.execute()
            my.execute()

        finally:
            my.transaction.rollback()
            test_env.delete()
Example #4
0
    def test_all(my):

        my.transaction = Transaction.get(create=True)
        try:
            my.create_snapshot()

            my._test_base_alias()

            my._test_file_naming()
            my._test_file_naming_base()
            my._test_dir_naming()
            # this comes after test_dir_naming so the file_object doesn't get polluted
            my._test_file_naming_manual_version()
            my._test_get_naming()
            my._test_checkin_type()
            my._test_naming_util()
        finally:
            my.transaction.rollback()
            Project.set_project("unittest")

            my.test_env.delete()
            my.sample3d_env.delete()

        # reset the unittest project type to whatever it was
        """
Example #5
0
    def test_all(my):

        my.description = "Checkin unit test"
        my.errors = []

        Batch()
        Project.set_project("unittest")

        my.transaction = Transaction.get(create=True)
        try:
            my._test_create()
        finally:
            my.transaction.rollback()
Example #6
0
    def test_all(my):

        Batch()
        from pyasm.web.web_init import WebInit

        WebInit().execute()

        test_env = UnittestEnvironment()
        test_env.create()
        my.transaction = Transaction.get(create=True)
        Project.set_project("unittest")
        try:
            my.person = Person.create("Unit", "Test", "ComputerWorld", "Fake Unittest Person")
            my._test_notification()

            my.transaction = Transaction.get(create=True)
            my._test_result()
        finally:
            my.transaction.rollback()
            test_env.delete()

        return
Example #7
0
    def test_all(my):
        Batch()
        from pyasm.web.web_init import WebInit

        WebInit().execute()

        test_env = UnittestEnvironment()
        test_env.create()
        my.transaction = Transaction.get(create=True)
        try:
            my._test_multiple_schema()
        finally:
            my.transaction.rollback()
            Project.set_project("unittest")

            test_env.delete()
Example #8
0
def import_schema(plugin_code):
    from pyasm.search import Transaction

    transaction = Transaction.get(create=True)

    install_dir = Environment.get_install_dir()
    base_dir = Environment.get_plugin_dir()
    template_dir = "%s/%s" % (base_dir, plugin_code)
    manifest_path = "%s/manifest.xml" % (template_dir)
    print "Reading manifest: ", manifest_path

    xml = Xml()
    xml.read_file(manifest_path)

    # create a new project
    installer = PluginInstaller(base_dir=base_dir, manifest=xml.to_string())
    installer.execute()
Example #9
0
    def _test_autocreate(my):
        from pyasm.common import Config

        Config.set_value("security", "mode", "autocreate", no_exception=True)
        Config.set_value(
            "security",
            "authenticate_class",
            "pyasm.security.authenticate_test.AutocreateAuthenticate",
            no_exception=True,
        )

        mode = Config.get_value("security", "mode", use_cache=False)
        my.assertEquals(mode, "autocreate")

        # verify that the user exists in the database
        search = Search("sthpw/login")
        search.add_filter("login", "foofoo")
        login = search.get_sobject()
        my.assertEquals(None, login)

        from pyasm.search import Transaction

        transaction = Transaction.get(create=True)
        transaction.start()

        my.security.login_user("foofoo", "wow")

        # verify that the user exists in the database
        search = Search("sthpw/login")
        search.add_filter("login", "foofoo")
        login = search.get_sobject()
        my.assertNotEquals(None, login)

        email = login.get_value("email")
        my.assertEquals("test@test.com", email)

        transaction.rollback()

        # after rollback, this user should not exist
        search = Search("sthpw/login")
        search.add_filter("login", "foofoo")
        login = search.get_sobject()
        my.assertEquals(None, login)
Example #10
0
    def log(cls, level, message, category="default"):
        assert level in ("critical", "error", "warning", "info", "debug")

        # record the exception
        user_name = Environment.get_user_name()
        if not user_name:
            user_name = "UNKNOWN"

        # put the debug in a completely separate transaction from the main
        # transaction
        transaction = Transaction.get(force=True)
        transaction.set_record(False)

        debug_log = SObjectFactory.create("sthpw/debug_log")
        debug_log.set_value("login", user_name)
        debug_log.set_value("level", level)
        debug_log.set_value("category", category)
        debug_log.set_value("message", message)
        debug_log.commit()

        transaction.commit()
        transaction.remove_from_stack()

        return debug_log
Example #11
0
    def postprocess(my):
        web = get_web_container()

        keys = web.get_form_keys()

        from pyasm.search import Transaction

        transaction = Transaction.get()
        assert transaction

        # first get some data based in
        column = my.get_value("%s|column" % my.name)
        if column == "":
            column = my.name

        # NOTE: why did this change?
        # prefix = my.get_input_name()
        prefix = my.get_name()

        context = my.get_value("%s|context" % prefix)
        description = my.get_value("%s|description" % prefix)

        field_storage = my.get_value(prefix)
        handoff_path = my.get_value("%s|path" % prefix)
        custom_ticket = my.get_value("%s|ticket" % prefix)

        from pyasm.widget import CheckboxWdg

        cb = CheckboxWdg("%s|is_revision" % prefix)
        is_rev = cb.is_checked()

        if handoff_path:
            handoff_path = handoff_path.replace("\\", "/")

            # This check causes issues.. Just assume it's in the upload location
            # if not os.path.exists(handoff_path):
            security = Environment.get_security()
            ticket = security.get_ticket_key()

            # in case it's supplied by widget like SimpleUploadWdg
            if custom_ticket:
                ticket = custom_ticket

            handoff_path = os.path.basename(handoff_path)
            handoff_path = Common.get_filesystem_name(handoff_path)

            handoff_path = "%s/upload/%s/%s" % (Environment.get_tmp_dir(), ticket, handoff_path)

            print "Uploaded path: ", handoff_path
            if not os.path.exists(handoff_path):
                raise Exception("Uploaded Path [%s] does not exist" % handoff_path)

            my.files = [handoff_path]
            file_types = ["main"]

            # create an icon
            icon_creator = IconCreator(handoff_path)
            icon_creator.execute()
            icon_path = icon_creator.get_web_path()
            if icon_path:
                my.files.append(icon_path)
                file_types.append("icon")
            web_path = icon_creator.get_icon_path()
            if web_path:
                my.files.append(web_path)
                file_types.append("web")

        elif field_storage != "":
            # else:
            # process and get the uploaded files
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.execute()

            # get files and file types
            my.files = upload.get_files()
            if not my.files:
                return
            file_types = upload.get_file_types()
        else:
            if my.get_option("file_required") == "true":
                err_msg = _("upload is required")
                raise TacticException("%s %s" % (my.name, err_msg))
            else:
                return

        checkin_class = my.get_option("checkin")
        if checkin_class:
            snapshot_type = my.get_option("snapshot_type")
            my.checkin = Common.create_from_class_path(
                checkin_class, [my.sobject, my.files, file_types, context, snapshot_type]
            )

        else:
            from pyasm.checkin import FileCheckin

            my.checkin = FileCheckin.get(
                my.sobject, my.files, file_types, context=context, column=column, snapshot_type="file"
            )

        my.sobjects.append(my.sobject)

        my.checkin.set_description(description)
        my.checkin.set_revision(is_rev)
        my.checkin.execute()

        # remove the files in upload area
        for file in my.files:
            if os.path.exists(file):
                os.unlink(file)
Example #12
0
    def execute(my):

        file_path = my.kwargs.get("path")
        project_code = my.kwargs.get("project_code")
        base_dir = my.kwargs.get("base_dir")
        search_type = my.kwargs.get("search_type")
        process = my.kwargs.get("process")
        if not process:
            process = "publish"

        basename = os.path.basename(file_path)

        context = my.kwargs.get("context")
        if not context:
            context = "%s/%s" % (process, basename)

        # find the relative_dir and relative_path
        relative_path = file_path.replace("%s/" % base_dir, "")
        relative_dir = os.path.dirname(relative_path)

        file_name = os.path.basename(file_path)
        log_path = "%s/TACTIC_log.txt" % (base_dir)
        my.create_checkin_log()

        # Define asset type of the file
        asset_type = my.get_asset_type(file_path)
        description = "drop folder check-in of %s" % file_name

        from client.tactic_client_lib import TacticServerStub

        server = TacticServerStub.get(protocol="local")
        server.set_project(project_code)

        transaction = Transaction.get(create=True)
        server.start(title="Check-in of media", description="Check-in of media")

        server_return_value = {}

        try:
            filters = [
                ["name", "=", file_name],
                # [ 'relative_dir', '=', relative_dir ]
            ]
            sobj = server.query(search_type, filters=filters, single=True)

            if not sobj:
                # create sobject if it does not yet exist
                sobj = SearchType.create(search_type)
                if SearchType.column_exists(search_type, "name"):
                    sobj.set_value("name", basename)
                if SearchType.column_exists(search_type, "media_type"):
                    sobj.set_value("media_type", asset_type)

                if SearchType.column_exists(search_type, "relative_dir"):
                    sobj.set_value("relative_dir", relative_dir)

                if SearchType.column_exists(search_type, "keywords"):
                    relative_path = relative_path
                    keywords = Common.get_keywords_from_path(relative_path)
                    keywords = " ".join(keywords)
                    sobj.set_value("keywords", keywords)

                sobj.commit()
                search_key = sobj.get_search_key()
            else:
                search_key = sobj.get("__search_key__")

            # task = server.create_task(sobj.get('__search_key__'),process='publish')
            # server.update(task, {'status': 'New'})

            server_return_value = server.simple_checkin(
                search_key, context, file_path, description=description, mode="copy"
            )

        except Exception, e:
            print "Error occurred", e
            error_message = str(e)
            version_num = "Error:"
            system_time = strftime("%Y/%m/%d %H:%M", gmtime())
            pre_log = (
                file_name
                + (50 - len(file_name)) * " "
                + system_time
                + (33 - len(system_time)) * " "
                + version_num
                + (15 - len(version_num)) * " "
                + error_message
                + "\n"
            )
            # Write data into TACTIC_log file under /tmp/drop
            f = open(log_path, "a")
            f.write(pre_log)
            f.close()

            # server.abort()
            transaction.rollback()
            raise
Example #13
0
    def test_all(my):

        # set up some widget configs in the database

        my.transaction = Transaction.get(create=True)

        widget_config_type = "config/widget_config"

        def_config = """
        <config>
        <definition>
          <element name='test'>
            <display class='SelectWdg'/>
          </element>
        </definition>
        </config>
        """

        config = """
        <config>
        <test>
          <element name='dan'/>
          <element name='dan2'>
             <display class='SelectWdg'/>
          </element>
          <element name='test'/>
          <element name='test2'>
            <display class='CheckboxWdg'/>
          </element>
          <element name='drop'/>
        </test>
        </config>
        """

        edit_config = """
        <config>
        <edit layout='EditWdg'>
          <element name='asset_category'/>
          <element name='code'>
            <display class='EditLevelTextWdg'/>
          </element>
          <element name='drop'/>
        </edit>
        </config>
        """
        edit_def_config = """
        <config>
        <edit_definition>
        <element name='asset_category'>
          <display class='ProcessSelectWdg'/>
        </element>
            
        <element name='code'>
            <display class='TextAreaWdg'/>
          </element>
        <element name='drop'>
            <action class='DropElementAction'>
               <path>path_test</path>
            </action>   
        </element>
        </edit_definition>
        </config>
        """

        ALL_def_config = """
        <config>
        <definition>
          <element name='dan'>
            <display class='tactic.ui.table.ExpressionElementWdg'/>
          </element>
        </definition>
        </config>
        """

        try:
            # add the ALL definition view
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "ALL")
            widget_config.set_value("view", "definition")
            widget_config.set_value("config", ALL_def_config)
            widget_config.commit()

            # add the definition view
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "unittest/person")
            widget_config.set_value("view", "definition")
            widget_config.set_value("config", def_config)
            widget_config.commit()

            # add the test view for person
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "unittest/person")
            widget_config.set_value("view", "test")
            widget_config.set_value("config", config)
            widget_config.commit()

            # add the test view for city
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "unittest/city")
            widget_config.set_value("view", "test")
            widget_config.set_value("config", config)
            widget_config.commit()

            # add the edit view
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "unittest/person")
            widget_config.set_value("view", "edit")
            widget_config.set_value("config", edit_config)
            widget_config.commit()

            # add the edit def view
            widget_config = SearchType.create(widget_config_type)
            widget_config.set_value("search_type", "unittest/person")
            widget_config.set_value("view", "edit_definition")
            widget_config.set_value("config", edit_def_config)
            widget_config.commit()

            my._test_get_display_handler()
            my._test_get_action_handler()

        finally:
            my.transaction.rollback()
            Project.set_project("unittest")

            my.test_env.delete()