def test_store_data_from_json(): original_json = open(JSON_FILE).read().strip() json_dict = from_json(original_json) store_data = to_model(StoreData, json_dict) assert store_data.name == "Acme store" assert store_data.id == 982 assert store_data.data_from == datetime(2017, 12, 18, 0, 0) assert store_data.data_to == datetime(2017, 12, 19, 23, 59, 59) assert len(store_data.days) == 2 assert isinstance(store_data.days[0].open_at, time) assert store_data.days[0].date == datetime(2017, 12, 18).date() assert store_data.days[0].open_at == time(8, 0, 0) assert store_data.days[0].closed_on == time(19, 0, 0) assert store_data.days[0].customers == int(487) assert store_data.days[0].day_type == DayType.NORMAL assert store_data.days[0].sales == float(27223.65) assert store_data.days[1].date == datetime(2017, 12, 19).date() assert store_data.days[1].open_at == time(10, 30, 0) assert store_data.days[1].closed_on == time(17, 30, 0) assert store_data.days[1].customers == int(192) assert store_data.days[1].day_type == DayType.HOLIDAY assert store_data.days[1].sales is None generated_json = to_json(store_data, suppress_empty_values=True, suppress_map_key_values=True).replace(" ", "") print(original_json) print(generated_json) assert original_json.replace(" ", "") == generated_json
def run(self, json_msg, *args, **kwargs): msg = related.from_json(json_msg, EmailMessage) try: self.email_client.send(mail_msg=msg) except NotificationError: LOG.error('Failed to send email to %s in the background', msg.to_addr)
def test_self_reference(): root_node = related.from_json(original_json, Node) assert root_node.name == "root" assert root_node.node_list[0].name == "A" assert root_node.node_list[1].name == "B" assert root_node.node_child.name == "C" assert len(root_node.node_map) == 2 assert root_node.node_map["F"].name == "F" assert root_node.node_map["F"].node_child.name == "G"
def from_json(payload): base_detector = related.from_json(payload, Detector) return build_detector(base_detector.type, base_detector.config, enabled=base_detector.enabled, trusted=base_detector.trusted, last_updated=base_detector.last_updated, uuid=base_detector.uuid, created_by=base_detector.created_by, meta=base_detector.meta)
def list_detector_mappings(self, detector_uuid): response = requests.post( f"{self._url}/api/detectorMappings/search", json={"detectorUuid": detector_uuid}, timeout=30 ) response.raise_for_status() detector_mappings = list() for detector_mapping in response.json(): detector_mappings.append( related.from_json(json.dumps(detector_mapping), DetectorMapping) ) return detector_mappings
def main(): """ Error checking on command line arguments, expecting 1 argument, pathname to a postman collection file """ if len(sys.argv) > 2: logging.critical("Too many arguments provided, expecting 1") exit() elif len(sys.argv) < 2: logging.critical("Path to postman collection not provided") exit() """ Open the postman json file """ collection_json = open(sys.argv[1]).read().strip() """ Parse the json file into collection object """ json_dict = from_json(collection_json) collection_model = to_model(Collection, json_dict) create_class_template(json_dict)
def test_roundtrip_json(company): new_company = from_json(to_json(company), Company) assert new_company == company
def from_json(cls, stream: any): return related.from_json(stream, cls)