def main(event: func.EventHubEvent): w = Widget.from_json(event.get_body().decode('utf-8')) c = Widget_Classification() c.classified_time = datetime.utcnow() c.mean = random.randrange(1, 100) c.std = random.randrange(1, 2) c.std_dist = random.randrange(1, 3) c.threshold = random.randrange(1, 100) w.classification = c (result, good) = c.is_good() assert result.success rowId = uuid.uuid4().hex if not good: sqlDao = WidgetSqlDAO(connectODBC) sqlDao.persistWidget(w, rowId) sqlDao.disconnect() # Create a sample entity to insert into the table tableDao = WidgetTableDAO(connectTable(), "Predictions") tableDao.persistWidget(w, rowId) result = w.to_json() logging.info('Python EventHub trigger processed an event: %s', result) return result
def test_widget(self): """ Tests to ensure the assembly object can be converted to json properly """ w = generate_widget() s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) assert w2.to_json() == s
def test_widget_no_classification(self): """ Tests to ensure the assembly object can be converted to json properly """ w = generate_widget() w.classification = None s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) assert w2.to_json() == s assert w2.line_id == "1"
def test_widget(self): """ Tests to ensure the object can be converted to json properly """ w = generate_widget() s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) w2_json = w2.to_json() assert (type(w2_json) is str) json_obj_version = json.loads(w2_json) assert (type(json_obj_version["classification"]["is_good"]) is bool)
def test_persist(self, mockConnection: pypyodbc.Connection, mockTableService: TableService): """ Tests to ensure the generator posts events to event hub """ input_widget = generate_widget() input_event = func.EventHubEvent(body=input_widget.to_json().encode()) ProcessTelemetry.connectTable = lambda: Mock(TableService) output_json = ProcessTelemetry.main(input_event) output_widget = Widget.from_json(output_json) assert output_widget.serial_number == input_widget.serial_number assert output_widget.classification.std_dist > 0