def test_logfile_equals_size(self): src = RdsLogFile(self.logfile_name, self.rds_instance.name) dst = self.lfh.copy(src) src.fetch_size() dst.fetch_size() self.assertEqual(src, dst) self.assertEqual(src.size, dst.size)
def test_logfile_not_equals_size(self): src = RdsLogFile(self.logfile_name, self.rds_instance.name) dst = self.lfh.get_s3logfile(self.logfile_name) dst.write('') src.fetch_size() dst.fetch_size() self.assertNotEqual(src, dst) self.assertNotEqual(src.size, dst.size)
def test_not_equals__differ_size(self): log_file = S3LogFile('foo', 'bucket', 'prefix') rds_file = RdsLogFile('foo', 'instance') log_file.size = 1 rds_file.size = 2 self.assertTrue(log_file != rds_file) self.assertTrue(rds_file != log_file) self.assertFalse(log_file == rds_file) self.assertFalse(rds_file == log_file)
def discover_logfiles_in_rds(self): return { RdsLogFile(e['LogFileName'], self.rds_instance.name, size=e['Size']) for e in rds.describe_logfiles_of_instance(self.rds_instance.name) }
def test_discover_rds_logfiles(self, describe_logfiles_of_instance): # emulate response of AWS api call part DescribeDBLogFiles describe_logfiles_of_instance.return_value = [{ 'LogFileName': 'file1', 'LastWritten': 123, 'Size': 124 }, { 'LogFileName': 'file2', 'LastWritten': 123, 'Size': 124 }] logfilehandler = LogFileHandler(self.rds_instance, 'foo', 'bar') result = logfilehandler.discover_logfiles_in_rds() describe_logfiles_of_instance.assert_called_with( self.rds_instance.name) self.assertEqual( { RdsLogFile('file1', '', size=124), RdsLogFile('file2', '', size=124) }, result)
def test_logfiles_to_copy_size_diff(self): src = {RdsLogFile('foo', '', size=123)} dst = {S3LogFile('foo', '', '', size=0)} self.assertEqual({LogFile('foo', size=123)}, LogFileHandler.logfiles_to_copy(src, dst))
def test_logfiles_to_copy_new_files_on_src_old_on_dst(self): src = {RdsLogFile('foo', ''), RdsLogFile('bar', '')} dst = {S3LogFile('foo', '', ''), S3LogFile('xyz', '', '')} self.assertEqual({LogFile('bar')}, LogFileHandler.logfiles_to_copy(src, dst))
def test_logfiles_to_copy_empty_dst(self): dst = set() src = {RdsLogFile('foo', '')} self.assertEqual(src, LogFileHandler.logfiles_to_copy(src, dst)) src = {RdsLogFile('foo', ''), RdsLogFile('bar', '')} self.assertEqual(src, LogFileHandler.logfiles_to_copy(src, dst))
def test_logfile_rds_has_same_size_in_local(self): src = RdsLogFile(self.logfile_name, self.rds_instance.name)
def test_equals__w_size(self): log_file = S3LogFile('foo', 'bucket', 'prefix') rds_file = RdsLogFile('foo', 'instance') log_file.size = 1 rds_file.size = 1 self.assertEqual(log_file, rds_file)
def test_not_equals__wo_size(self): log_file = S3LogFile('foo', 'bucket', 'prefix') rds_file = RdsLogFile('bar', 'instance') self.assertNotEqual(log_file, rds_file)
def test_fetch_size_rds__calls(self, s3_get_size, rds_get_size): rds = RdsLogFile('foo', 'instance') rds.fetch_size() self.assertFalse(s3_get_size.called) self.assertTrue(rds_get_size.called)
def test_fetch_size_rds(self, get_size): rds_log = RdsLogFile('foo', 'instance') get_size.return_value = 23 rds_log.fetch_size() get_size.assert_called_with('instance', 'foo') self.assertEqual(23, rds_log.size)
def test_rds_download(self, download): rds_log = RdsLogFile('foofile', 'instance') with NamedTemporaryFile() as tempfile: rds_log.download(tempfile) download.assert_called_with('instance', 'foofile', tempfile)
def test_rds_log_file_init(self): rds_log = RdsLogFile('foo', 'instance') self.assertEqual('foo', rds_log.name) self.assertEqual('instance', rds_log.instance_name)