def attach_file_to_ticket(self, ticketid, data=None, tempfilename=None, description=None, replace=False, content_type=None): """Attaches a file to the given ticket id, with random data if none is provided. Assumes the ticket exists. """ if data is None: data = random_page() if description is None: description = random_sentence() if tempfilename is None: tempfilename = random_word() self.go_to_ticket(ticketid) # set the value to what it already is, so that twill will know we # want this form. tc.formvalue('attachfile', 'action', 'new') tc.submit() tc.url(self.url + "/attachment/ticket/" \ "%s/\\?action=new&attachfilebutton=Attach\\+file" % ticketid) fp = StringIO(data) tc.formfile('attachment', 'attachment', tempfilename, content_type=content_type, fp=fp) tc.formvalue('attachment', 'description', description) if replace: tc.formvalue('attachment', 'replace', True) tc.submit() tc.url(self.url + '/attachment/ticket/%s/$' % ticketid) return tempfilename
def _attach_file_to_resource(self, realm, name, data=None, filename=None, description=None, replace=False, content_type=None): """Attaches a file to a resource. Assumes the resource exists and has already been navigated to.""" if data is None: data = random_page() if description is None: description = random_sentence() if filename is None: filename = random_word() tc.submit('attachfilebutton', 'attachfile') tc.url(self.url + r'/attachment/%s/%s/\?action=new$' % (realm, name)) fp = io.BytesIO(data) tc.formfile('attachment', 'attachment', filename, content_type=content_type, fp=fp) tc.formvalue('attachment', 'description', description) if replace: tc.formvalue('attachment', 'replace', True) tc.submit() tc.url(self.url + r'/attachment/%s/%s/$' % (realm, name)) return filename
def _attach_file_to_resource(self, realm, name, data=None, filename=None, description=None, replace=False, content_type=None): """Attaches a file to a resource. Assumes the resource exists and has already been navigated to.""" if data is None: data = random_page() if description is None: description = random_sentence() if filename is None: filename = random_word() tc.submit('attachfilebutton', 'attachfile') tc.url(self.url + '/attachment/%s/%s/\\?action=new&' 'attachfilebutton=Attach\\+file$' % (realm, name)) fp = StringIO(data) tc.formfile('attachment', 'attachment', filename, content_type=content_type, fp=fp) tc.formvalue('attachment', 'description', description) if replace: tc.formvalue('attachment', 'replace', True) tc.submit() tc.url(self.url + '/attachment/%s/%s/$' % (realm, name)) return filename
def attach_file_to_ticket(self, ticketid, data=None, tempfilename=None, description=None, replace=False): """Attaches a file to the given ticket id, with random data if none is provided. Assumes the ticket exists. """ if data is None: data = random_page() if description is None: description = random_sentence() if tempfilename is None: tempfilename = random_word() self.go_to_ticket(ticketid) # set the value to what it already is, so that twill will know we # want this form. tc.formvalue('attachfile', 'action', 'new') tc.submit() tc.url(self.url + "/attachment/ticket/" \ "%s/\\?action=new&attachfilebutton=Attach\\+file" % ticketid) fp = StringIO(data) tc.formfile('attachment', 'attachment', tempfilename, fp=fp) tc.formvalue('attachment', 'description', description) if replace: tc.formvalue('attachment', 'replace', True) tc.submit() tc.url(self.url + '/attachment/ticket/%s/$' % ticketid) return tempfilename
def attach_file_to_wiki(self, name, data=None): """Attaches a file to the given wiki page, with random content if none is provided. Assumes the wiki page exists. """ if data == None: data = random_page() self.go_to_wiki(name) # set the value to what it already is, so that twill will know we # want this form. tc.formvalue('attachfile', 'action', 'new') tc.submit() tc.url(self.url + "/attachment/wiki/" \ "%s/\\?action=new&attachfilebutton=Attach\\+file" % name) tempfilename = random_word() fp = StringIO(data) tc.formfile('attachment', 'attachment', tempfilename, fp=fp) tc.formvalue('attachment', 'description', random_sentence()) tc.submit() tc.url(self.url + '/attachment/wiki/%s/$' % name)
def attach_file_to_wiki(self, name, data=None): """Attaches a file to the given wiki page, with random content if none is provided. Assumes the wiki page exists. """ if data == None: data = random_page() self.go_to_wiki(name) # set the value to what it already is, so that twill will know we # want this form. tc.formvalue('attachfile', 'action', 'new') tc.submit() tc.url(self.url + "/attachment/wiki/" \ "%s/\\?action=new&attachfilebutton=Attach\\+file" % name) tempfilename = random_word() fp = StringIO(data) tc.formfile('attachment', 'attachment', tempfilename, fp=fp) tc.formvalue('attachment', 'description', random_sentence()) tc.submit() tc.url(self.url + '/attachment/wiki/%s/$' % name) return tempfilename