def test_get_latest_dweet_for(self): """`get_latest_dweet_for` should return a valid response. """ ts_dweepy.dweet_for(self.my_thing_id, test_data) dweets = ts_dweepy.get_latest_dweet_for(self.my_thing_id) check_valid_get_response(self, dweets)
def test_dweet_for_without_a_key(self): """`dweet_for` without a key should raise an exception. """ try: ts_dweepy.dweet_for(self.my_thing_id, test_data) except ts_dweepy.DweepyError as e: self.assertEqual(e.args[0], 'this thing is locked and requires a key') else: self.fail("shouldn't ever get called")
def test_dweet_for_with_an_invalid_key(self): """`dweet_for` with an invalid key should raise an exception. """ try: ts_dweepy.dweet_for(self.my_thing_id, test_data, key='badkey') except ts_dweepy.DweepyError as e: self.assertEqual( e.args[0], 'the key you provided doesn\'t work with this thing') else: self.fail("shouldn't ever get called")
def feature(self, mess): ts_dweepy.dweet_for( self.run_stamp["run-platform"], { "mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess }) #noqa print( json.dumps({ "mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess })) #noqa
def test_valid_dweet_for(self): """`dweet_for` should return a valid response. """ my_thing_id = str(uuid.uuid4()) dweet = ts_dweepy.dweet_for(my_thing_id, test_data) check_valid_dweet_response(self, dweet) self.assertEqual(dweet['thing'], my_thing_id)
def feature(self, mess): if self.trace_on is True: if self.run_stamp["verbose"] is True: print(json.dumps({"mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess})) else: print(json.dumps({"FEATURE": mess})) try: ts_dweepy.dweet_for(self.run_stamp["run-platform"], {"mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess}) except requests.exceptions.RequestException as e: #exc_info = sys.exc_info() print("Communication error within ts_dweepy")
def feature(self, mess, on=True): if on is True: if self.run_stamp["verbose"] is True: print( json.dumps({ "mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess })) else: print(json.dumps({"FEATURE": mess})) ts_dweepy.dweet_for( self.run_stamp["run-platform"], { "mess-type": "FEATURE", "run-id": self.run_stamp["run-id"], "mess-text": mess })
def test_dweet_for_alert(self): """`dweet_for` should not raise an exception no matter what alert condition is used """ ts_dweepy.set_alert( self.my_thing_id, ['*****@*****.**', '*****@*****.**'], test_alert_condition, test_key, ) dweet = ts_dweepy.dweet_for(self.my_thing_id, {'alertValue': 11}, key=test_key) check_valid_dweet_response(self, dweet, skip_content=True) dweet = ts_dweepy.dweet_for(self.my_thing_id, {'alertValue': 5}, key=test_key) check_valid_dweet_response(self, dweet, skip_content=True) dweet = ts_dweepy.dweet_for(self.my_thing_id, {'alertValue': 10}, key=test_key) check_valid_dweet_response(self, dweet, skip_content=True)
def heartbeat(self, mess): t = datetime.datetime.now() if (t - self.hb_time).total_seconds() > self.hb_freq: self.hb_time = t if self.trace_on is True: if self.run_stamp["verbose"] is True: print(json.dumps({"mess-type": "HEARTBEAT", "run-id": self.run_stamp["run-id"], "mess-text": mess})) else: print(json.dumps({"HEARTBEAT": mess})) try: ts_dweepy.dweet_for(self.run_stamp["run-platform"], {"mess-type": "HEARTBEAT", "run-id": self.run_stamp["run-id"], "mess-text": mess}) except requests.exceptions.RequestException as e: #exc_info = sys.exc_info() print("Communication error within ts_dweepy")
def test_get_latest_dweet_for_with_a_valid_key(self): """`get_latest_dweet_for` with a valid key should return a valid response. """ ts_dweepy.dweet_for(self.my_thing_id, test_data, key=test_key) dweets = ts_dweepy.get_latest_dweet_for(self.my_thing_id, key=test_key) check_valid_get_response(self, dweets)
def test_dweet_for_with_a_valid_key(self): """`dweet_for` with a valid key should return a valid response. """ dweet = ts_dweepy.dweet_for(self.my_thing_id, test_data, key=test_key) check_valid_dweet_response(self, dweet) self.assertEqual(dweet['thing'], self.my_thing_id)