From 558a02d18768bca445c8dad0510efef281f3bc44 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 9 May 2019 14:06:19 -0400 Subject: [PATCH] correctly format lat/long and fee amounts in JSON RPC response --- lbrynet/schema/attrs.py | 9 +++++++++ lbrynet/schema/claim.py | 4 +++- tests/integration/test_claim_commands.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lbrynet/schema/attrs.py b/lbrynet/schema/attrs.py index 9b4722ae6..c68060add 100644 --- a/lbrynet/schema/attrs.py +++ b/lbrynet/schema/attrs.py @@ -6,6 +6,7 @@ from typing import Tuple, List from string import ascii_letters from decimal import Decimal, ROUND_UP from binascii import hexlify, unhexlify +from google.protobuf.json_format import MessageToDict from torba.client.hash import Base58 from torba.client.constants import COIN @@ -446,6 +447,14 @@ class Location(Metadata): else: raise ValueError(f'Could not parse country value: {value}') + def to_dict(self): + d = MessageToDict(self.message) + if self.message.longitude: + d['longitude'] = self.longitude + if self.message.latitude: + d['latitude'] = self.latitude + return d + @property def country(self) -> str: if self.message.country: diff --git a/lbrynet/schema/claim.py b/lbrynet/schema/claim.py index d9732b408..c59e84269 100644 --- a/lbrynet/schema/claim.py +++ b/lbrynet/schema/claim.py @@ -115,6 +115,8 @@ class BaseClaim: claim.update(claim.pop(self.claim_type)) if 'languages' in claim: claim['languages'] = self.langtags + if 'locations' in claim: + claim['locations'] = [l.to_dict() for l in self.locations] return claim def update(self, **kwargs): @@ -197,7 +199,7 @@ class Stream(BaseClaim): if 'address' in fee: fee['address'] = self.fee.address if 'amount' in fee: - fee['amount'] = self.fee.amount + fee['amount'] = str(self.fee.amount) stream_type = self.message.WhichOneof('type') if stream_type: claim['stream_type'] = stream_type diff --git a/tests/integration/test_claim_commands.py b/tests/integration/test_claim_commands.py index 089221b67..3a0c7879c 100644 --- a/tests/integration/test_claim_commands.py +++ b/tests/integration/test_claim_commands.py @@ -317,7 +317,7 @@ class StreamCommands(CommandTestCase): 'thumbnail_url': "https://co.ol/thumbnail.png", 'tags': ["cool", "awesome"], 'languages': ["en"], - 'locations': ['{"country": "US"}'], + 'locations': ['US:NH:Manchester:03101:42.990605:-71.460989'], 'author': "Jules Verne", 'license': 'Public Domain', @@ -329,7 +329,14 @@ class StreamCommands(CommandTestCase): 'fee_address': 'mmCsWAiXMUVecFQ3fVzUwvpT9XFMXno2Ca', } fixed_values = values.copy() - fixed_values['locations'] = [{'country': 'US'}] + fixed_values['locations'] = [{ + 'country': 'US', + 'state': 'NH', + 'city': 'Manchester', + 'code': '03101', + 'latitude': '42.990605', + 'longitude': '-71.460989' + }] fixed_values['thumbnail'] = {'url': fixed_values.pop('thumbnail_url')} fixed_values['release_time'] = str(values['release_time']) fixed_values['source'] = { @@ -339,7 +346,7 @@ class StreamCommands(CommandTestCase): } fixed_values['fee'] = { 'address': fixed_values.pop('fee_address'), - 'amount': float(fixed_values.pop('fee_amount')), + 'amount': fixed_values.pop('fee_amount'), 'currency': fixed_values.pop('fee_currency').upper() }