def test_complains_if_restore_from_doesnt_exist(self): with a_temp_file() as restore_from: if os.path.exists(restore_from): os.remove(restore_from) with self.assertRaisesRegexp(CommandError, "Specified backup file \({0}\) doesn't exist".format(restore_from)): self.command.handle(restore_from=restore_from)
def test_it_complains_if_given_something_that_isnt_an_ssh_key(self): with a_temp_file() as filename: with open(filename, 'w') as fle: fle.write("blah") res = self.data.norm.post(self.detail_url, {"ssh_key": open(filename)}) self.assertEqual(res.status_code, 500) self.assertEqual(res.content, "not a valid RSA private key file")
def test_send_from_does_send_to_s3_if_has_storage(self): contents = """ Stuff and things blah """ bucket_name = str(uuid.uuid1()) conn = boto.connect_s3() conn.create_bucket(bucket_name) with a_temp_file(contents) as source: with override_settings(BACKUP_S3_BUCKET=bucket_name): self.storage.validate_destination() self.storage.send_from(source, os.path.dirname(source)) self.assertEqual(boto.connect_s3().get_bucket(bucket_name).get_key(os.path.basename(source)).get_contents_as_string(), contents)
def test_send_from_does_send_to_s3_if_has_storage(self): contents = """ Stuff and things blah """ bucket_name = str(uuid.uuid1()) conn = boto.connect_s3() conn.create_bucket(bucket_name) with a_temp_file(contents) as source: with override_settings(BACKUP_S3_BUCKET=bucket_name): self.storage.validate_destination() self.storage.send_from(source, os.path.dirname(source)) self.assertEqual( boto.connect_s3().get_bucket(bucket_name).get_key( os.path.basename(source)).get_contents_as_string(), contents)
def test_getting_from_s3(self): contents = """ Stuff and things blah """ key_name = str(uuid.uuid1()) bucket_name = str(uuid.uuid1()) conn = boto.connect_s3() conn.create_bucket(bucket_name) key = boto.s3.key.Key(conn.get_bucket(bucket_name)) key.key = key_name key.set_contents_from_string(contents) with a_temp_file() as location: self.storage.get_from_s3(key_name, boto.connect_s3().get_bucket(bucket_name), location) with open(location) as fle: self.assertEqual(fle.read(), contents)
def test_restore_location_returns_location_as_is_if_not_s3_and_exists( self): with a_temp_file() as filename: with self.command.restore_location(filename) as result: self.assertIs(result, filename)
def test_restore_location_returns_location_as_is_if_not_s3_and_exists(self): with a_temp_file() as filename: with self.command.restore_location(filename) as result: self.assertIs(result, filename)
def test_restore_location_complains_if_location_doesnt_exist(self): with a_temp_file() as filename: os.remove(filename) with self.assertRaisesRegexp(CommandError, "Specified backup file \([^\)]+\) doesn't exist"): with self.command.restore_location(filename): assert False, "Should have complained"