def test_update_report_to_send(self, fromConfig, fromOptions, getLogger): options = Mock() options.interval = 0 options.oneshot = True options.print_ = False options.log_dir = '' options.log_file = '' virtwho = VirtWho(self.logger, options, config_dir="/nonexistant") report = Mock() report.hash.return_value = "hash" config = Mock() report.config = config config.hash.return_value = "config_hash" config.name.return_value = "config_name" self.assertTrue(virtwho.update_report_to_send(report)) self.assertTrue(len(virtwho.configs_ready) == 1 and config in virtwho.configs_ready) self.assertTrue(virtwho.reports_to_send[config.hash].hash == report.hash) # Pretend we sent the report for that config virtwho.configs_ready = [] virtwho.reports[config.hash] = report.hash del virtwho.reports_to_send[config.hash] # if we receive the same report twice we should not send it self.assertFalse(virtwho.update_report_to_send(report)) self.assertFalse(virtwho.configs_ready) self.assertFalse(virtwho.reports_to_send)
def test_update_report_to_send(self, fromConfig, fromOptions, getLogger): options = Mock() options.interval = 0 options.oneshot = True options.print_ = False options.log_dir = '' options.log_file = '' virtwho = VirtWho(self.logger, options, config_dir="/nonexistant") report = Mock() report.hash.return_value = "hash" config = Mock() report.config = config config.hash.return_value = "config_hash" config.name.return_value = "config_name" self.assertTrue(virtwho.update_report_to_send(report)) self.assertTrue( len(virtwho.configs_ready) == 1 and config in virtwho.configs_ready) self.assertTrue( virtwho.reports_to_send[config.hash].hash == report.hash) # Pretend we sent the report for that config virtwho.configs_ready = [] virtwho.reports[config.hash] = report.hash del virtwho.reports_to_send[config.hash] # if we receive the same report twice we should not send it self.assertFalse(virtwho.update_report_to_send(report)) self.assertFalse(virtwho.configs_ready) self.assertFalse(virtwho.reports_to_send)