def test_json(self): g = map_point.GpxFile() g.id = 34 g.gpx_timestamp = utils.now() g.parsed_time = utils.now() g.name = "fart" p = map_point.GpxPoint.from_dict({ "id": 35, "elevation": 35.35, "longitude": 98.4, "latitude": 98.2, "course": 998.2, "time": utils.datetime_to_string(utils.now()), }) g.points = [p] g2 = map_point.GpxFile.from_json_string(utils.to_json(g)) self.assertDictEqual(g.to_json_dict(), g2.to_json_dict())
def main(): config = dao_config.Config.from_env(os.environ) dao = dao_module.create_dao(config) ps = point_set.PointSet() ps.points = create_random_points(10, 10) ps.created = utils.now() ps.name = "Hello SQLAlchemy" ps = dao.save_or_update_point_set(ps) ps = dao.get_point_set_by_id(ps.id) print(utils.to_json(ps))
def test_user_json(self): p = user.User(id=1, first_name="Jeffrey", last_name="Keene", uuid=utils.create_uuid_str()) json_data = utils.to_json(p) self.assertTrue(json_data is not None) user2 = user.User.from_json(json_data) self.assertEqual(p.id, user2.id) self.assertEqual(p.first_name, user2.first_name) self.assertEqual(p.last_name, user2.last_name) self.assertEqual(p.uuid, user2.uuid)
def test_map_point_json(self): p = map_point.GpxPoint() p.id = 45 p.elevation = 34.54 p.gpx_file_id = 2 p.latitude = 534.55 p.longitude = 445.334 p.course = 34.43 p.time = utils.now() json = utils.to_json(p) p2 = map_point.GpxPoint.from_json_string(json) self.assertDictEqual(p.to_json_dict(), p2.to_json_dict())
def main(): point_set = ps.PointSet() point_set.name = "My Point Set" point_set.id = 40 point_set.created = point_utils.now() for i in range(0, 10): point = p.Point() point.point_set_id = point_set.id point.x = random.random() point.y = random.random() point.x = random.random() point_set.points.append(point) #sys.stdout.write(str(point_set)) sys.stdout.write(point_utils.to_json(point_set))
def test_json(self): n = utils.now() flat_point = map_point.GpxFlatPoint() flat_point.course = 1.0 flat_point.longitude = 33.2 flat_point.latitude = 228.3 flat_point.elevation = 23.2 flat_point.id = utils.create_uuid_str() flat_point.file_parsed_time = n flat_point.file_gpx_timestamp = n flat_point.time = n flat_point.file_id = 3 flat_point.file_user_id = utils.create_uuid_str() flat_point.file_hash = "file_hash" flat_point.file_name = "file_name" json_data = utils.to_json(flat_point) flat_point2 = map_point.GpxFlatPoint.from_json_string(json_data) self.assertDictEqual( flat_point.__dict__, flat_point2.__dict__, "expected flat point to serialize in and out of json as the same")