def to_json_dict(self): return { "id": self.id, "name": self.name, "gpx_timestamp": utils.datetime_to_string(self.gpx_timestamp), "parsed_time": utils.datetime_to_string(self.parsed_time), "points": [u.to_json_dict() for u in self.points], "user_id": self.user_id, "hash": self.hash }
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 test_str(self): now = point_utils.now() print(now) now_string = point_utils.datetime_to_string(now) now_time = point_utils.string_to_datetime(now_string) print(now_string) self.assertEqual(now, now_time, "expected dates to parse and un-parse")
def test_parse_gpx_timestamp(self): value = "2018-07-17T13:59:21Z" ts = utils.string_to_datetime(value) self.assertIsNotNone(ts, "gpx time stamp should not be null") ts_str = utils.datetime_to_string(ts) ts_copy = utils.string_to_datetime(ts_str) self.assertEqual(ts, ts_copy)
def to_json_dict(self) -> typing.Dict: return { "file_id": self.file_id, "file_name": self.file_name, "file_gpx_timestamp": utils.datetime_to_string(self.file_gpx_timestamp), "file_parsed_time": utils.datetime_to_string(self.file_parsed_time), "file_hash": self.file_hash, "file_user_id": self.file_user_id, "id": self.id, "latitude": self.latitude, "longitude": self.longitude, "elevation": self.elevation, "course": self.course, "time": utils.datetime_to_string(self.time) }
def to_json_dict(self): created_at_string = p_utils.datetime_to_string(self.created) data = { "name": self.name, "id": self.id, "created": created_at_string, "points": [x.to_json_dict() for x in self.points] } return data
def to_json_dict(self): return { "id": self.id, "latitude": self.latitude, "longitude": self.longitude, "elevation": self.elevation, "course": self.course, "time": utils.datetime_to_string(self.time), "gpx_file_id": self.gpx_file_id, }
def test_from_dict(self): d = { "id": 35, "elevation": 35.35, "longitude": 98.4, "latitude": 98.2, "course": 998.2, "time": utils.datetime_to_string(utils.now()), "gpx_file_id": 5, } p = map_point.GpxPoint.from_dict(d) self.assertDictEqual(d, p.to_json_dict())
def test_point_set_from_dict(self): now = point_utils.now() dict_data = { "id": 34, "created": point_utils.datetime_to_string(now), "name": "Test Case Point Set Is Fantastic", "points": [{ "x": 3.4, "y": 4.2, "z": 54.3, "point_set_id": 34 }, { "x": 3.6, "y": 4.3, "z": 54.5, "point_set_id": 34 }] } ps = point_set.PointSet.from_dict(dict_data) self.assertEqual(ps.id, 34, "expected id to match") self.assertEqual(ps.name, "Test Case Point Set Is Fantastic", "expected name to match") self.assertEqual(ps.created, now, "expected created to match") self.assertEqual(ps.number_of_points(), 2, "expected point count to match") self.assertEqual([p.point_set_id for p in ps.points], [34, 34], "expected the point set ids to match") self.assertEqual([p.x for p in ps.points], [3.4, 3.6], "expected the x values to match") self.assertEqual([p.y for p in ps.points], [4.2, 4.3], "expected the y values to match") self.assertEqual([p.z for p in ps.points], [54.3, 54.5], "expected the z values to match")