Example #1
0
 def test_check_key(self):
     alarm.KEY_FILE = os.path.dirname(
         os.path.realpath(__file__)) + "/key_file.1.txt"
     alarm.load_keys()
     self.assertTrue(alarm.keys_exist())
     self.assertTrue(alarm.check_key("abc123"))
     self.assertFalse(alarm.check_key("key_does_not_exist"))
Example #2
0
 def test_turn_on_with_no_keys(self):
     alarm.KEY_FILE = os.path.dirname(
         os.path.realpath(__file__)) + "/key_file.blank.txt"
     alarm.load_keys()
     resp = self.app.get('/alarm/on')
     json_data = json.loads(resp.data.decode("utf-8"))
     self.assertEqual(json_data["alarm"], "on")
Example #3
0
    def test_turn_on_off_3_users(self):
        alarm.KEY_FILE = os.path.dirname(
            os.path.realpath(__file__)) + "/key_file.3.txt"
        alarm.load_keys()
        alarm.ENABLE_LAUNCH_BROWSER = False
        resp = self.app.post('/alarm/on',
                             data=json.dumps(dict(access_key='abc123')),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "on")

        resp = self.app.post('/alarm/on',
                             data=json.dumps(dict(access_key='dfg456')),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "on")

        resp = self.app.post('/alarm/on',
                             data=json.dumps(dict(access_key='rti652')),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "on")

        self.assertTrue(len(alarm.timer_threads) == 1)

        resp = self.app.post('/alarm/off',
                             data=json.dumps(dict(access_key='abc123')),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "off")

        self.assertTrue(len(alarm.timer_threads) == 0)

        alarm.cleanup()
Example #4
0
 def test_missing_post_data(self):
     alarm.KEY_FILE = os.path.dirname(
         os.path.realpath(__file__)) + "/key_file.1.txt"
     alarm.load_keys()
     resp = self.app.get('/alarm/on')
     json_data = json.loads(resp.data.decode("utf-8"))
     self.assertEqual(json_data["status"], "error")
     self.assertEqual(resp.status_code, 400)
Example #5
0
 def test_invalid_key(self):
     alarm.KEY_FILE = os.path.dirname(
         os.path.realpath(__file__)) + "/key_file.1.txt"
     alarm.load_keys()
     resp = self.app.post('/alarm/on',
                          data=json.dumps(
                              dict(access_key='bad key', timeout=180)),
                          content_type='application/json')
     json_data = json.loads(resp.data.decode("utf-8"))
     self.assertEqual(json_data["status"], "error")
     self.assertEqual(resp.status_code, 403)
Example #6
0
    def test_turn_on_off_with_access_key(self):
        alarm.KEY_FILE = os.path.dirname(
            os.path.realpath(__file__)) + "/key_file.1.txt"
        alarm.load_keys()
        resp = self.app.post('/alarm/on',
                             data=json.dumps(
                                 dict(access_key='abc123', timeout=180)),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "on")

        resp = self.app.post('/alarm/off',
                             data=json.dumps(
                                 dict(access_key='abc123',
                                      url='http://t-mobile.com')),
                             content_type='application/json')
        json_data = json.loads(resp.data.decode("utf-8"))
        self.assertEqual(json_data["alarm"], "off")

        alarm.cleanup()
Example #7
0
 def test_no_keys(self):
     alarm.KEY_FILE = os.path.dirname(
         os.path.realpath(__file__)) + "/key_file.blank.txt"
     alarm.load_keys()
     self.assertFalse(alarm.keys_exist())