diff --git a/test/unit/modules/test_sfp_countryname.py b/test/unit/modules/test_sfp_countryname.py index 22658fc6f2..88778493ca 100644 --- a/test/unit/modules/test_sfp_countryname.py +++ b/test/unit/modules/test_sfp_countryname.py @@ -34,6 +34,47 @@ def test_producedEvents_should_return_list(self): module = sfp_countryname() self.assertIsInstance(module.producedEvents(), list) + def test_handleEvent_phone_number_event_data_containing_countrycode_should_create_country_name_event(self): + sf = SpiderFoot(self.default_options) + + module = sfp_countryname() + module.setup(sf, dict()) + + target_value = 'spiderfoot.net' + target_type = 'INTERNET_NAME' + target = SpiderFootTarget(target_value, target_type) + module.setTarget(target) + + def new_notifyListeners(self, event): + expected = 'COUNTRY_NAME' + if str(event.eventType) != expected: + raise Exception(f"{event.eventType} != {expected}") + + expected = "United States" + if str(event.data) != expected: + raise Exception(f"{event.data} != {expected}") + + raise Exception("OK") + + module.notifyListeners = new_notifyListeners.__get__(module, sfp_countryname) + + event_type = 'ROOT' + event_data = 'example data' + event_module = '' + source_event = '' + evt = SpiderFootEvent(event_type, event_data, event_module, source_event) + + event_type = 'PHONE_NUMBER' + event_data = '+12345678901' + event_module = 'example module' + source_event = evt + evt = SpiderFootEvent(event_type, event_data, event_module, source_event) + + with self.assertRaises(Exception) as cm: + module.handleEvent(evt) + + self.assertEqual("OK", str(cm.exception)) + def test_handleEvent_domain_whois_event_data_containing_countryname_string_should_create_country_name_event(self): sf = SpiderFoot(self.default_options)