def test_request(self, send_sms_patch, phone_call_patch): print('***** Test request script ***') from hook import configure, load_button, handle_button, delete_room settings = configure('settings.yaml') context = load_button(settings, name='request') self.assertTrue(isinstance(context, dict)) self.assertEqual(context['count'], 0) try: handle_button(context) self.assertEqual(context['count'], 1) handle_button(context) self.assertEqual(context['count'], 2) delete_room(context) except ConnectionError: pass context['count'] = 0
def test_push_details(self): print('***** Test push details ***') from hook import configure, load_button, get_push_details settings = configure('settings.yaml') context = load_button(settings, name='incident') self.assertTrue(isinstance(context, dict)) context['count'] = 1 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['files', 'text', 'markdown']) self.assertEqual(phone.keys(), []) context['count'] = 2 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['files', 'text', 'markdown']) self.assertEqual(phone.keys(), ['sms']) context['count'] = 3 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['text', 'markdown']) self.assertEqual(phone.keys(), ['call']) context['count'] = 4 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['files', 'text']) self.assertEqual(phone.keys(), []) context['count'] = 5 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['files', 'text']) self.assertEqual(phone.keys(), []) context['count'] = 6 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['text']) self.assertEqual(phone.keys(), []) context['count'] = 0 context = load_button(settings, name='request') self.assertTrue(isinstance(context, dict)) self.assertEqual(context['count'], 0) context['count'] = 1 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['files', 'text', 'markdown']) self.assertEqual(phone.keys(), ['sms']) context['count'] = 2 update, phone = get_push_details(context) self.assertEqual(update.keys(), ['text', 'markdown']) self.assertEqual(phone.keys(), ['call']) context['count'] = 0
def test_load_button(self): print('***** Test load button ***') from hook import configure, load_button settings = configure('settings.yaml') context = load_button(settings) context['count'] = 0 self.assertTrue(isinstance(context, dict)) self.assertEqual(context['count'], 0) self.assertTrue(isinstance(context['bt.tn'], list)) self.assertTrue(len(context['spark']['room']) > 1) self.assertTrue(len(context['spark']['CISCO_SPARK_BTTN_BOT']) > 5) self.assertTrue(len(context['twilio']['customer_service_number']) > 5) self.assertTrue(len(context['twilio']['TWILIO_ACCOUNT_SID']) > 5) self.assertTrue(len(context['twilio']['TWILIO_AUTH_TOKEN']) > 5) self.assertTrue(context['server']['default'] == 'incident') context = load_button(settings, name='incident') self.assertTrue(isinstance(context, dict)) self.assertEqual(context['name'], 'incident') self.assertEqual(context['count'], 0) self.assertTrue(isinstance(context['bt.tn'], list)) self.assertTrue(len(context['spark']['room']) > 1) self.assertTrue(len(context['spark']['CISCO_SPARK_BTTN_BOT']) > 5) self.assertTrue(len(context['twilio']['customer_service_number']) > 5) self.assertTrue(len(context['twilio']['TWILIO_ACCOUNT_SID']) > 5) self.assertTrue(len(context['twilio']['TWILIO_AUTH_TOKEN']) > 5) self.assertTrue(context['server']['default'] == 'incident') context = load_button(settings, name='request') self.assertTrue(isinstance(context, dict)) self.assertEqual(context['name'], 'request') self.assertEqual(context['count'], 0) self.assertTrue(isinstance(context['bt.tn'], list)) self.assertTrue(len(context['spark']['room']) > 1) self.assertTrue(len(context['spark']['CISCO_SPARK_BTTN_BOT']) > 5) self.assertTrue(len(context['twilio']['customer_service_number']) > 5) self.assertTrue(len(context['twilio']['TWILIO_ACCOUNT_SID']) > 5) self.assertTrue(len(context['twilio']['TWILIO_AUTH_TOKEN']) > 5) self.assertTrue(context['server']['default'] == 'incident')
def test_configure(self): print('***** Test configure ***') from hook import configure settings = configure() self.assertTrue(isinstance(settings, dict)) settings = configure('settings.yaml') self.assertTrue(isinstance(settings, dict)) self.assertTrue(len(settings['spark']['CISCO_SPARK_BTTN_BOT']) > 5) self.assertTrue(len(settings['twilio']['customer_service_number']) > 5) self.assertTrue(len(settings['twilio']['TWILIO_ACCOUNT_SID']) > 5) self.assertTrue(len(settings['twilio']['TWILIO_AUTH_TOKEN']) > 5) self.assertTrue(settings['server']['default'] == 'incident')
def test_load_buttons(self): print('***** Test load buttons ***') from hook import configure, load_buttons settings = configure('settings.yaml') buttons = load_buttons(settings) keys = buttons.keys() self.assertTrue('incident' in keys) self.assertTrue('request' in keys)
def test_get_room(self): print('***** Test get room ***') from hook import configure, load_button, get_room settings = configure('settings.yaml') context = load_button(settings, name='request') self.assertTrue(isinstance(context, dict)) try: get_room(context) except ConnectionError: pass
def test_temporary_button(self): print('***** Test temporary button ***') from hook import configure, load_buttons, load_button, generate_tokens settings = configure('settings.yaml') settings['server']['key'] = 'a_secret' buttons = load_buttons(settings) keys = buttons.keys() self.assertTrue('incident' in keys) self.assertTrue('request' in keys) with open( os.path.abspath(os.path.dirname(__file__)) + '/../buttons/temporary.yaml', 'w') as handle: handle.write(my_button) context = load_button(settings, 'temporary') buttons = load_buttons(settings) keys = buttons.keys() self.assertTrue('incident' in keys) self.assertTrue('request' in keys) self.assertTrue('temporary' in keys) with open( os.path.abspath(os.path.dirname(__file__)) + '/../.tokens', 'r') as handle: tokens = yaml.load(handle) keys = tokens.keys() self.assertTrue('incident' in keys) self.assertTrue('request' in keys) self.assertTrue('temporary' in keys) os.remove( os.path.abspath(os.path.dirname(__file__)) + '/../buttons/temporary.yaml')
def test_process_push(self, send_sms_patch, phone_call_patch): print('***** Test process push ***') from hook import configure, load_button, process_push, get_room, delete_room settings = configure('settings.yaml') context = load_button(settings, name='incident') self.assertTrue(isinstance(context, dict)) self.assertEqual(context['count'], 0) try: context['spark']['id'] = get_room(context) process_push(context) self.assertEqual(context['count'], 1) process_push(context) self.assertEqual(context['count'], 2) context['time'] = 0 process_push(context) self.assertEqual(context['count'], 1) process_push(context) self.assertEqual(context['count'], 2) delete_room(context) except ConnectionError: pass context['count'] = 0
#!/usr/bin/env python from hook import configure, load_buttons, generate_tokens settings = configure('settings.yaml') buttons = load_buttons(settings) if 'key' in settings['server']: tokens = generate_tokens(settings, buttons.keys()) for key in tokens: print('{}: {}'.format(key, tokens[key])) else: print('Add a secret key to settings.yaml if you want security') print('No security token has been generated')