def testNo(self): # Establish that this upload() call actually changes the return from # SCPFileExists(). assert not self.scpconn.SCPFileExists(self.upno_archive) # Let dry_run default to False uploaded = upload([self.upno_archive], False) # Should claim to have uploaded exactly one file assert_equals(len(uploaded), 1) self.scp_verify(self.upno_archive, uploaded[0]) # Now detect a duplicate upload attempt. Because we take pains to try # to give each new archive a unique name, we don't consider that an # already existing file is an error; we assume we're retrying an # upload already performed earlier. upload() indicates that it didn't # perform any actual uploading in a couple ways, though. # capture print output oldout, sys.stdout = sys.stdout, StringIO() try: # Try to upload the same file uploaded = upload([self.upno_archive], False) finally: testout, sys.stdout = sys.stdout, oldout assert not uploaded, "dup scp-only upload returned %s" % uploaded testmsg = testout.getvalue().lower() assert_in("already exists", testmsg) assert_in("not uploading", testmsg)
def testNoDry(self): # Capture print output oldout, sys.stdout = sys.stdout, StringIO() try: uploaded = upload([self.upno_archive], False, dry_run=True) finally: testout, sys.stdout = sys.stdout, oldout # We shouldn't have talked about S3 assert_not_in("amazonaws", testout.getvalue()) # We should have claimed to upload to exactly one dest, with an scp: URL assert_equals(len(uploaded), 1) assert_startswith(uploaded[0], "scp:") # But in fact we should NOT have actually uploaded the file there. assert not self.scpconn.SCPFileExists(self.upno_archive)
def testYes(self): # Want to change the state of both servers. assert not self.scpconn.SCPFileExists(self.upyes_archive), \ "file already exists on install-packages %s" % self.upyes_archive assert not self.s3conn.S3FileExists(self.upyes_archive), \ "file already exists on s3 %r" % self.s3conn._get_key(self.upyes_archive) # Let dry_run default to False uploaded = upload([self.upyes_archive], True) # One file, two servers, should get two URLs back assert_equals(len(uploaded), 2) # Sort URLs so we're sure they're ["http:...", "scp:..."] uploaded.sort() self.scp_verify(self.upyes_archive, uploaded[1]) self.s3_verify(self.upyes_archive, uploaded[0]) # Try to upload same file again, should result in info messges with no # new URLs. oldout, sys.stdout = sys.stdout, StringIO() try: uploaded = upload([self.upyes_archive], True) finally: testout, sys.stdout = sys.stdout, oldout assert not uploaded, "dup scp+s3 upload returned %s" % uploaded testmsg = testout.getvalue().lower() assert_in("already exists on s3", testmsg)
def testYesDry(self): # Capture print output oldout, sys.stdout = sys.stdout, StringIO() try: uploaded = upload([self.upyes_archive], True, dry_run=True) finally: testout, sys.stdout = sys.stdout, oldout # We should have talked about S3 assert_in("amazonaws", testout.getvalue()) # We should have claimed to upload to both dests assert_equals(len(uploaded), 2) # We're sure one of these should start with "http:" while the other # should start with "scp:", but we don't want to have to know which is # which. sort() to order them. uploaded.sort() assert_startswith(uploaded[0], "http:") assert_startswith(uploaded[1], "scp:") # But in fact we should NOT have actually uploaded to either. assert not self.scpconn.SCPFileExists(self.upyes_archive) assert not self.s3conn.S3FileExists(self.upyes_archive)
def testBadFile(self): raise SkipTest() upload(["bogus>filename"], "autobuild.xml", dry_run=True)
def testNoFiles(self): raise SkipTest() upload([], "autobuild.xml", dry_run=True)