def testSaveAndAddAnotherProject(self):
     self.testname="TestSaveAndAddAnotherProject"
     self.setup()
     util = WebdriverUtilities()
     util.setDriver(self.driver)
     element = Elements()
     do = Helpers(self)
     do.setUtils(util)
     do.login()
     
     object_1_name = do.generateNameForTheObject("Project")
     do.delay(10) # count number does not appear right away, weird
     object_2_name = "Project_" + str(do.getRandomNumber())
     
     do.ensureLHNSectionExpanded("Project")
     count_before = do.countOfAnyObjectLHS("Project")
     do.createObjectSaveAddAnother("Project", object_1_name, "unchecked", True, "", False)
     do.createObjectSaveAddAnother("Project", object_2_name, "unchecked", False, "", True)
     do.clearSearchBoxOnLHS() #clear any text so total count displays
     do.ensureLHNSectionExpanded("Project")
     count_after = do.countOfAnyObjectLHS("Project")
           
     do.assertEqual(count_after, count_before+2, "Count has not incremented by 1 as expected.") 
            
     print "Object 1: "
     object_1_link = do.verifyObjectIsCreatedinLHN("Project", object_1_name)
     do.navigateToObjectAndOpenObjectEditWindow("Project",object_1_link)
     do.deleteObject()
     
     print "Object 2: "
     object_2_link = do.verifyObjectIsCreatedinLHN("Project", object_2_name)
     do.navigateToObjectAndOpenObjectEditWindow("Project",object_2_link)
     do.deleteObject()        
Ejemplo n.º 2
0
    def testDeleteObjects(self):
        self.testname="TestDeleteObjects"
        self.setup()
        util = WebdriverUtilities()
        util.setDriver(self.driver)
        element = Elements()
        grcobject = GRCObject()
        do = Helpers(self)
        do.setUtils(util)
        do.login()
        for section in ["Regulation",
                        "Objective",
                        "Program",                        
                        "Contract",
                        "Policy",
                        "Control",
                        "System",
                        "Process",
                        "Data",
                        "Product",
                        "Project",
                        "Facility",
                        "Market",
                        "Group"
                           ]:
            print "Starting Deletion of Objects for " + section
            deleted_objects=0
            do.ensureLHNSectionExpanded(section)
            do.checkMyWorkBox()
            
            object_left_nav_section_object_link = element.left_nav_expand_object_section_link.replace("OBJECT", section)
            
            # enter term to search
            util.inputTextIntoField("Auto", element.left_nav_search_input_textfield)
            util.pressEnterKey(element.left_nav_search_input_textfield)
            
            left_nav_first_link = element.left_nav_first_object_link_in_the_section.replace("SECTION",section)
            util.waitForElementToBePresent(left_nav_first_link)
            lef_nav_objects_for_deletion_in_section = element.left_nav_objects_candidate_for_deletion.replace("SECTION",section )
            number_of_auto_objects = do.countOfAnyObjectLHS(section)
                
            deleted_objects = number_of_auto_objects - 2     # leave 2 behind                        

            while (deleted_objects > 0):
                            
                do.navigateToObjectAndOpenObjectEditWindow(section,lef_nav_objects_for_deletion_in_section, refresh_page=False)
                do.deleteObject()
                deleted_objects = deleted_objects - 1 #LHN collapse after this
                
                do.showLHMenu(True) # reopen it
            
                object_left_nav_section_object_link = element.left_nav_expand_object_section_link.replace("OBJECT", section)
                left_nav_first_link = element.left_nav_first_object_link_in_the_section.replace("SECTION",section)
                util.waitForElementToBePresent(left_nav_first_link)
                lef_nav_objects_for_deletion_in_section = element.left_nav_objects_candidate_for_deletion.replace("SECTION",section )
                
            print "Finished deletion of objects for " + section + ". " + str(deleted_objects) + " object is left to be deleted."
    def testCreatePersonObjectEditorLogInOut(self):
        self.testname="TestCreatePersonObjectEditorLogInOut"
        self.setup()
        util = WebdriverUtilities()
        util.setDriver(self.driver)
        element = Elements()
        do = Helpers(self)
        do.setUtils(util)
        do.login()

        # ***************************** run this block of codes if run locally *****************************
        if "localhost" in config.url:
            print "Executing the block of codes locally ..."
            aEmail = "auto_email_" + str(do.getRandomNumber(65535)) + "@gmail.com"
            aName = do.getUniqueString("name")
            aCompany = do.getUniqueString("company")
       
            do.selectMenuInTopRight("Admin Dashboard")
            do.selectMenuItemInnerNavDashBoard("People") 
            do.addPersonInAdminDB(aName, aEmail, aCompany)
            self.assertTrue(do.searchPersonInAdminDB(aName), "Fail searching for newly created person in Admin Dashboard.")
       
               
            # edit person authorization
            do.selectMenuItemInnerNavDashBoard("People") # on the roles selection      
            do.clickOnEditAuthorization(aName)
            do.assignUserRole("ObjectEditor")
               
            # now log out and then log in with the new account and try to create a program
            oldEmail = "Example user"
            oldName = "*****@*****.**"
            absFilePath = expanduser("~") + "/ggrc-core/src/ggrc/login/noop.py"
            do.changeUsernameEmail(oldName, aName, oldEmail, aEmail, absFilePath)
            do.selectMenuInTopRight("Logout")
               
            # Refresh the page
            do.refresh()
               
            # Log in with new user
            do.login()
            print "Log in as : " + do.whoAmI()
            
            object_list = ["Workflow", "Vendor", "Regulation", "Policy", "Standard", "Contract", "Clause", "Section",
                           "Section", "Objective", "Control", "Person", "OrgGroup", "System","Process", "DataAsset",
                           "Product", "Project", "Facility", "Market", "Program", "Audit"]
            
            # since it's an object editor role, the Create New button won't show for certain types
            for object in object_list:
                
                if object=="Program" or object=="Audit":
                    do.assertFalse(do.doesCreateNewExist(object), "Create New button exists for " + str(object))
                else:
                    do.assertTrue(do.doesCreateNewExist(object), "Create New button does not exist for " + str(object))
            
            # should be able to create an object that is not Program or Audit
            last_created_object_link = do.createObject("Contract")
            object_name = str(do.util.getTextFromXpathString(last_created_object_link)).strip()
            self.assertTrue(do.partialMatch("contract-auto-test", object_name), "Fail to match contract name.")
            
            # Restore old login information
            do.changeUsernameEmail(aName, oldName, aEmail, oldEmail, absFilePath)
            do.selectMenuInTopRight("Logout")  
        #   ******************* execute this else block of codes if not run locally *******************
        else: 
            print "Executing the block of codes for non-local ..."
            aEmail = config.editor2
            aName = do.getUniqueString("name")
            aCompany = do.getUniqueString("company")
       
            do.selectMenuInTopRight("Admin Dashboard")
            do.selectMenuItemInnerNavDashBoard("People") 
            do.addPersonInAdminDB(aName, aEmail, aCompany)
            self.assertTrue(do.searchPersonInAdminDB(aName), "Fail searching for newly created person in Admin Dashboard.")
                     
            # edit person authorization
            do.selectMenuItemInnerNavDashBoard("People") # on the roles selection      
            do.clickOnEditAuthorization(aName)
            do.assignUserRole("ObjectEditor")
               
            # now log out and then log in with the new account and try to create a program
            do.selectMenuInTopRight("Logout")
               
            # Refresh the page
            do.refresh()
               
            # Log in with new user
            do.login(aEmail, config.password)
            print "Log in as : " + do.whoAmI()
            
            object_list = ["Workflow", "Vendor", "Regulation", "Policy", "Standard", "Contract", "Clause", "Section",
                           "Section", "Objective", "Control", "Person", "OrgGroup", "System","Process", "DataAsset",
                           "Product", "Project", "Facility", "Market", "Program", "Audit"]
            
            # since it's an object editor role, the Create New button won't show for certain types
            
            for object in object_list:
                
                do.ensureLHNSectionExpanded(object)
                
                if object=="Program" or object=="Audit":
                    do.assertFalse(do.doesCreateNewExist(object), "Create New button exists for " + str(object))
                else:
                    do.assertTrue(do.doesCreateNewExist(object), "Create New button does not exist for " + str(object))
            
            # should be able to create an object that is not Program or Audit
            last_created_object_link = do.createObject("Contract")
            object_name = str(do.util.getTextFromXpathString(last_created_object_link)).strip()
            self.assertTrue(do.partialMatch("contract-auto-test", object_name), "Fail to match contract name.")
            
            if "localhost" in config.url:
                # Restore old login information
                do.changeUsernameEmail(aName, oldName, aEmail, oldEmail, absFilePath)
                do.selectMenuInTopRight("Logout")      
    def testCreatePersonReaderLogInOut(self):
        self.testname="TestCreatePersonReaderLogInOut"
        self.setup()
        util = WebdriverUtilities()
        util.setDriver(self.driver)
        element = Elements()
        do = Helpers(self)
        do.setUtils(util)
        do.login()

        # run this block of codes if run locally
        if "localhost" in config.url:
            print "Executing the block of codes locally ..."
            aEmail = "auto_email_" + str(do.getRandomNumber(65535)) + "@gmail.com"
            aName = do.getUniqueString("name")
            aCompany = do.getUniqueString("company")
      
            do.selectMenuInTopRight("Admin Dashboard")
            do.selectMenuItemInnerNavDashBoard("People") 
            do.addPersonInAdminDB(aName, aEmail, aCompany)
            self.assertTrue(do.searchPersonInAdminDB(aName), "Fail searching for newly created person in Admin Dashboard.")
      
              
            # edit person authorization
            do.selectMenuItemInnerNavDashBoard("People") # on the roles selection      
            do.clickOnEditAuthorization(aName)
            do.assignUserRole("Reader")
              
            # now log out and then log in with the new account and try to create a program
            oldEmail = "*****@*****.**"
            oldName = "Example User"
            absFilePath = expanduser("~") + "/ggrc-core/src/ggrc/login/noop.py"
            do.changeUsernameEmail(oldName, aName, oldEmail, aEmail, absFilePath)
            do.selectMenuInTopRight("Logout")
              
            # Refresh the page
            do.refresh()
              
            # Log in with new user
            do.login()
            print "Log in as : " + do.whoAmI()
            
            object_list = ["Vendor", "Regulation", "Policy", "Standard", "Contract", "Clause", "Section",
                           "Section", "Objective", "Control", "Person", "OrgGroup", "System","Process", "DataAsset",
                           "Product", "Project", "Facility", "Market", "Program", "Audit"]
            
            # since it's a reader role, the Create New button won't show
            for object in object_list:
                do.assertFalse(do.doesCreateNewExist(object), "Create New button exists for " + str(object))
     
            print "hi"
            
            # Restore old login information
            do.changeUsernameEmail(aName, oldName, aEmail, oldEmail, absFilePath)
            do.selectMenuInTopRight("Logout")
        else:
            print "Executing the block of codes for non-local ..."            
            aEmail = config.reader2
            aName = do.getUniqueString("name")
            aCompany = do.getUniqueString("company")
      
            do.selectMenuInTopRight("Admin Dashboard")
            do.selectMenuItemInnerNavDashBoard("People") 
            do.addPersonInAdminDB(aName, aEmail, aCompany)
            self.assertTrue(do.searchPersonInAdminDB(aName), "Fail searching for newly created person in Admin Dashboard.")
      
              
            # edit person authorization
            do.selectMenuItemInnerNavDashBoard("People") # on the roles selection      
            do.clickOnEditAuthorization(aName)
            do.assignUserRole("Reader")
              
            # now log out and then log in with the new account and try to create a program
            do.selectMenuInTopRight("Logout")
              
            # Refresh the page
            do.refresh()
              
            # Log in with new user
            do.login(aEmail, config.same_password)
            print "Log in as : " + do.whoAmI()
            
            # Workflow is left out on purpose because Create New is there but reader can't create object anyway
            object_list = ["Vendor", "Regulation", "Policy", "Standard", "Contract", "Clause", "Section",
                           "Section", "Objective", "Control", "Person", "OrgGroup", "System","Process", "DataAsset",
                           "Product", "Project", "Facility", "Market", "Program", "Audit"]
            
            # since it's a reader role, the Create New button won't show
            for object in object_list:
                do.ensureLHNSectionExpanded(object)
                do.assertFalse(do.doesCreateNewExist(object), "Create New button exists for " + str(object))