def test_to_dict_decorator(self): # 2020/12/17 13:58:59 UTC+8 created_at_ts = 1608184739 test_model = _TestModel( name='test-model', token='test-token', created_at=datetime.fromtimestamp(created_at_ts) ) test_grpc_spec = common_pb2.GrpcSpec(egress_url='test-url', authority='test-authority') test_model.set_grpc_spec(test_grpc_spec) self._db.session.add(test_model) self._db.session.commit() models = _TestModel.query.all() self.assertEqual(len(models), 1) self.assertDictEqual(models[0].to_dict(), { 'id': 1, 'name': 'test-model', 'created_at': created_at_ts, 'extra_key': { 'egress_url': 'test-url', 'authority': 'test-authority', 'extra_headers': {}, } })
def test_to_dict_decorator(self): # 2020/12/17 13:58:59 UTC+8 created_at = datetime(2020, 12, 17, 13, 58, 59, tzinfo=timezone(timedelta(hours=8))) # datetime will be stored without timezone info created_at_ts = int(created_at.timestamp()) + 8 * 60 * 60 # 2021/04/23 10:42:01 UTC updated_at = datetime(2021, 4, 23, 10, 42, 1, tzinfo=timezone.utc) updated_at_ts = int(updated_at.timestamp()) test_model = _TestModel(name='test-model', token='test-token', created_at=created_at, updated_at=updated_at) test_grpc_spec = common_pb2.GrpcSpec(authority='test-authority') test_model.set_grpc_spec(test_grpc_spec) self._db.session.add(test_model) self._db.session.commit() models = _TestModel.query.all() self.assertEqual(len(models), 1) self.assertDictEqual( models[0].to_dict(), { 'id': 1, 'name': 'test-model', 'created_at': created_at_ts, 'updated_at': updated_at_ts, 'extra_key': { 'authority': 'test-authority', 'extra_headers': {}, } })
def get_grpc_spec(self): proto = common_pb2.GrpcSpec() proto.ParseFromString(self.grpc_spec) return proto