def testChownDir(self): self.assertTrue(os.path.exists('/home/user')) (status, output) = rt('mkdir /tmp/testdir') self.assertTrue(0 == status) self.assertTrue(os.path.exists('/tmp/testdir')) (status, output) = rt('touch /tmp/testdir/test') self.assertTrue(0 == status) self.assertTrue(os.path.exists('/tmp/testdir/test')) (status, output) = rt('ls -l /tmp/testdir/test') d_list = output.split() d_user = d_list[2] d_group = d_list[3] self.assertTrue(self.loginuser == d_user) self.assertTrue(self.loginuser == d_group) (status, output) = rt('sudo chown -R user.user /tmp/testdir') (status, output) = rt('ls -l /tmp/testdir/test') t_list = output.split() t_user = t_list[2] t_group = t_list[3] self.assertFalse(self.loginuser == t_user) self.assertFalse(self.loginuser == t_group) self.assertTrue('user' == t_user) self.assertTrue('user' == t_group)
def tearDownClass(cls): if os.path.exists('/tmp/testdir'): (status, output) = rt('sudo rm -rf /tmp/testdir') if os.path.exists('/tmp/testfile'): (status, output) = rt('sudo rm /tmp/testfile') if os.path.exists('/home/user'): (status, output) = rt('sudo deluser --remove-home user')
def setUpClass(cls): cls.loginuser = getpass.getuser() if not os.path.exists('/home/user'): (status, output) = rt('sudo useradd -m user') if os.path.exists('/tmp/testdir'): (status, output) = rt('sudo rm -rf /tmp/testdir') if os.path.exists('/tmp/testfile'): (status, output) = rt('sudo rm /tmp/testfile')
def testDateTwo(self): (status, tmp) = rt('date -s "2009/11/11 17:00:00"') self.assertFalse(0 == status) (status, output) = rt('date') self.assertTrue(0 == status) self.assertFalse(output.startswith('2009')) (status, tmp) = rt('sudo date -s "2009/11/11 17:00:00"') (status, output) = rt('date') self.assertTrue(0 == status) self.assertTrue(output.startswith('2009'), "output: %s" % output)
def testFileCommand(self): (status_ls, output_ls) = rt("which ls") self.assertTrue(0 == status_ls) self.assertTrue('/bin/ls' == output_ls) (status, output) = rt("file %s" % output_ls) self.assertTrue(0 == status) resultlist = output.split() self.assertEquals("/bin/ls:", resultlist[0]) self.assertEquals("ELF", resultlist[1]) self.assertEquals("64-bit", resultlist[2]) self.assertEquals("LSB", resultlist[3]) self.assertEquals("executable,", resultlist[4])
def testOpenFile_URL(self, fileName, windowName): self.fileName = fileName self.testFilePath = 'file://' + '/'.join( [self.pwd, self.data, self.fileName]) self.windowName = windowName args = { "eventType": self.eventType, "url": self.testFilePath, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) (status, output) = rt(cmdstring) docwin = window.findWindow(self.windowName) self.assertTrue(None != docwin) window.closeWindow(docwin) docwinclose = window.findWindow(self.windowName, mode="nowait") self.assertTrue(None == docwinclose) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testFindCommand(self): (status, output) = rt('find /bin -name \"[a-b]*\"') for line in output.split('\n'): linelist = line.split('/') if 2 == len(linelist): self.assertTrue(linelist[1].startswith(('a', 'b')))
def testOpenFileLocation_url(self): args = { "eventType": self.eventType, "url": self.testFilePath, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #run the test (status, output) = rt(cmdstring) sleep(2) docwin = window.findWindowByAppName(self.applicationName) self.assertTrue(None != docwin) window.closeWindow(docwin) docwinclose = window.findWindowByAppName(self.applicationName, mode="nowait") self.assertTrue(None == docwinclose)
def testRestoreFromTrash_urlList(self): args = {"eventType": self.eventType, "urlList": self.urllist(self.testFilePath), "mode": 2} cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #run the test (status, output) = rt(cmdstring) sleep(2) #list the name of dir='~/.local/share/Trash/files/' List_output_ls = os.listdir('/'.join([self.pwd, self.data])) print(List_output_ls) #judge whether the test successful? result = self.judge(self.fileName, List_output_ls) print(result) self.assertTrue( 1 == result) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testOpenINewWindow_urlList_force(self): args = {"eventType": self.eventType, "urlList": self.urllist(self.testFilePath), "force": True, "mode": 2} cmdstring = self.cmdline(args) print(cmdstring) #if opened dde-file-manager, close it docwin = window.findWindow(self.windowName) if docwin != None: window.closeWindow(docwin) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(1) #run the test (status, output) = rt(cmdstring) sleep(1) docwin = window.findWindow(self.windowName) self.assertTrue(None != docwin) window.closeWindow(docwin) docwinclose = window.findWindow(self.windowName, mode="nowait") self.assertTrue(None == docwinclose) print(child1.pid) child1.kill()
def testOpenInTerminal_url(self): args = { "eventType": self.eventType, "url": self.testFilePath, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #run the test (status, output) = rt(cmdstring) sleep(2) docwin = window.findWindow(self.windowName) self.assertTrue(None != docwin) window.closeWindow(docwin) docwinclose = window.findWindow(self.windowName, mode="nowait") self.assertTrue(None == docwinclose) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testPasteFile_urlList_action_targetUrl(self): args = {"eventType": self.eventType, "urlList": self.urllist(self.testFilePath), "action": 1, "targetUrl": self.targetUrl, "mode": 2} cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) (status, output) = rt(cmdstring) sleep(2) List_output_ls = os.listdir('/'.join([self.pwd, self.data, self.testdir])) ''' (status_ls, output_ls) = rt('ls ../data/testdir') List_output_ls = output_ls.split("\n") print(List_output_ls) ''' filename = self.judge(self.fileName, List_output_ls) print(filename) self.assertTrue( 1 == filename) removefile = os.remove(self.remove_pasteFile) self.assertTrue(None == removefile) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testDeleteFiles_urlList_silent(self): args = { "eventType": self.eventType, "urlList": self.urllist(self.testFilePath), "silent": True, "mode": 2 } print(args) cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) os.mknod(self.testFile) List_output_ls = os.listdir('/'.join([self.pwd, self.data])) filename = self.judge(self.fileName, List_output_ls) print(filename) self.assertTrue(1 == filename) (status, output) = rt(cmdstring) sleep(2) List_output_ls = os.listdir('/'.join([self.pwd, self.data])) filename = self.judge(self.fileName, List_output_ls) print(filename) self.assertTrue(None == filename) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testDecompressFile_URLLIST(self): args = { "eventType": self.eventType, "urlList": self.urllist(self.testFilePath), #"appName": self.appName, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) (status, output) = rt(cmdstring) docwin = window.findWindowByAppName(self.applicationName) #sleep(2) self.assertTrue(None != docwin) #sleep(2) window.closeWindow(docwin) docwinclose = window.findWindowByAppName(self.applicationName, mode="nowait") self.assertTrue(None == docwinclose) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testManFour(self): (status, output) = rt('man apt-get') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() self.assertTrue(linelist[0].startswith('APT-GET('), "linelist[0]: %s" % linelist[0]) break
def testManThree(self): (status, output) = rt('whereis apt-get') self.assertTrue(0 == status) linelist = output.split() self.assertTrue('apt-get:' == linelist[0]) self.assertTrue('/usr/bin/apt-get' == linelist[1]) self.assertTrue('' != linelist[2] and None != linelist[2])
def testManTwo(self): (status, output) = rt('man ssh_config') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() self.assertTrue(linelist[0].startswith('SSH_CONFIG('), "linelist[0]: %s" % linelist[0]) break
def testManOne(self): (status, output) = rt('man ls') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() self.assertTrue(linelist[0].startswith('LS('), "linelist[0]: %s" % linelist[0]) break
def testDateOne(self): (status, output) = rt('date') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() self.assertTrue('CST' == linelist[len(linelist) - 1]) break
def testWho(self): (status, output) = rt('who') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() self.assertTrue(self.loginuser == linelist[0]) self.assertTrue('tty7' == linelist[1]) break
def testFileShare_url_name_isWritable_allowGuest(self): args = { "eventType": self.eventType, "url": self.testFilePath, "name": self.sharename, "isWritable": True, "allowGuest": True, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #if there's a share file named "cherry_share",delete it dele = 'net usershare delete ' + self.sharename (status, output) = rt(dele) #run the test (status, output) = rt(cmdstring) sleep(2) #list the name of share for line in os.popen("net usershare list"): line = line.strip('\n') self.share_list.append(line) print(self.share_list) #judge whether the test successful? result = self.judge(self.sharename, self.share_list) print(result) self.assertTrue(1 == result) #delete the share file (status, output) = rt(dele) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testCal(self): (status, output) = rt('cal') self.assertTrue(0 == status) for line in output.split('\n'): linelist = line.split() month = getoutput('date "+%B"') year = getoutput('date "+%Y"') self.assertTrue(month == linelist[0]) self.assertTrue(year == linelist[1]) break
def setUpClass(cls): if os.path.exists('/home/test'): (status, output) = rt('sudo deluser --remove-home test') if os.getenv("LANG") == "en_US.UTF-8": cls.passwd_one = "UNIX password:"******"UNIX password:"******"Password:"******"LANG") == "zh_CN.UTF-8": cls.passwd_one = "UNIX 密码:" cls.passwd_two = "UNIX 密码:" cls.su_passwd = "密码:"
def testCloseDeepinScreenshot(self): time.sleep(1) rawinput.click(int(utils.resolution.width / 2), int(utils.resolution.height / 2), 3) time.sleep(1) rawinput.click(int(utils.resolution.width / 4), int(utils.resolution.height / 4)) time.sleep(1) (status, output) = rt( "ps -ef | grep /usr/bin/deepin-screenshot | grep -v grep | awk '{print $9}'" ) time.sleep(4) self.assertTrue('' == output, "output is %s" % output)
def testCancelFileShare_url(self): args = { "eventType": self.eventType, "url": self.testFilePath, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #Add a share file named "cherry_share" add_share = 'net usershare add ' + self.sharename + ' ' + self.testFile print(add_share) (status, output) = rt(add_share) sleep(2) #run the test (status, output) = rt(cmdstring) sleep(2) #list the name of share for line in os.popen("net usershare list"): line = line.strip('\n') self.share_list.append(line) print(self.share_list) #judge whether the test successful? result = self.judge(self.sharename, self.share_list) print(result) self.assertTrue(None == result) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testOpenFile_URL(self): args = { "eventType": self.eventType, "url": self.testFilePath, "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) (status, output) = rt(cmdstring) docwin = window.findWindow(self.windowName) self.assertTrue(None != docwin) window.closeWindow(docwin) docwinclose = window.findWindow(self.windowName, mode="nowait") self.assertTrue(None == docwinclose)
def testRedirect(self): (status, output) = rt('echo bbbb > /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb' == output) (status, output) = rt('echo aaaa >> /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb\naaaa' == output) (status, output) = rt('date -s aa > /tmp/testfile 2>&1') (status, output) = rt('cat /tmp/testfile') self.assertTrue(0 == status) self.assertTrue(output.startswith('date: invalid date'))
def testRedirect(self): (status, output) = rt('echo bbbb > /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb' == output) (status, output) = rt('echo aaaa >> /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb\naaaa' == output) (status, output) = rt('date -s aa > /tmp/testfile 2>&1') (status, output) = rt('cat /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('date: 无效的日期"aa"' == output)
def testMoveToTrash_urlList(self): args = { "eventType": self.eventType, "urlList": self.urllist(self.testFilePath), "mode": 2 } cmdstring = self.cmdline(args) print(cmdstring) child1 = subprocess.Popen("dde-file-manager -d >/dev/null 2>&1", shell=True) sleep(2) #create testfile List_output_ls = os.listdir('/'.join([self.pwd, self.data])) result_1 = self.judge(self.fileName, List_output_ls) #print(result_1) if 1 != result_1: os.mknod(self.testFile) List_output_ls = os.listdir('/'.join([self.pwd, self.data])) result_1 = self.judge(self.fileName, List_output_ls) self.assertTrue(1 == result_1) sleep(1) #run the test (status, output) = rt(cmdstring) sleep(2) #list the name of dir='$pwd/data' List_output_ls = os.listdir('/'.join([self.pwd, self.data])) print(List_output_ls) #judge whether the test successful? result = self.judge(self.fileName, List_output_ls) print(result) self.assertTrue(None == result) print(child1.pid) child1.kill() os.system('killall dde-file-manager')
def testMore(self): (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('' == output) (status, output) = rt('echo aaaa > /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('aaaa' == output) (status, output) = rt('echo bbbb > /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb' == output) (status, output) = rt('echo aaaa >> /tmp/testfile') (status, output) = rt('more /tmp/testfile') self.assertTrue(0 == status) self.assertTrue('bbbb\naaaa' == output)