Skip to content

Commit 9e998d7

Browse files
fred-yu-2013stiartsly
authored andcommitted
CU-3ewjcba - Refine the API getAppStats.
1 parent 1737b71 commit 9e998d7

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Diff for: src/modules/subscription/subscription.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from src.modules.subscription.vault import VaultManager
1717
from src.utils.consts import VAULT_SERVICE_START_TIME, VAULT_SERVICE_END_TIME, VAULT_SERVICE_MODIFY_TIME, VAULT_SERVICE_PRICING_USING, COL_APPLICATION_APP_DID, \
1818
COL_APPLICATION_ACCESS_COUNT, COL_APPLICATION_ACCESS_AMOUNT, COL_APPLICATION_ACCESS_LAST_TIME
19-
from src.utils.did.eladid_wrapper import DID, DIDDocument
19+
from src.utils.did.eladid_wrapper import DID, DIDDocument, DIDURL
2020
from src.utils.payment_config import PaymentConfig
2121
from src.utils.http_exception import BadRequestException, ApplicationNotFoundException
2222
from src.utils.singleton import Singleton
@@ -132,7 +132,7 @@ def __get_appdid_info_by_did(did_str: str):
132132
if not did_str:
133133
raise BadRequestException('get_appdid_info: did must provide.')
134134

135-
did: DID = DID.from_string(did_str)
135+
did: DID = DID.create_from_str(did_str)
136136
doc: DIDDocument = did.resolve()
137137

138138
def get_appinfo_props(vc_json: dict) -> dict:
@@ -150,12 +150,19 @@ def get_developer_props(vc_json: dict):
150150

151151
def get_info_from_credential(fragment: str, props_callback: t.Callable[[dict], dict]) -> dict:
152152
""" Get the information from the credential. """
153-
vc = doc.get_credential(did, fragment)
153+
vc = doc.get_credential(DIDURL.create_from_did(did, fragment))
154154
if not vc.is_valid():
155155
logging.error('The credential is not valid.')
156156
return {}
157157
return props_callback(json.loads(vc.to_json()))
158158

159-
info = get_info_from_credential('appinfo', get_appinfo_props)
160-
info.update(get_info_from_credential('developer', get_developer_props))
159+
info = {}
160+
try:
161+
info.update(get_info_from_credential('appinfo', get_appinfo_props))
162+
except Exception as e:
163+
logging.error(f'Failed to get "appinfo" of the app did: {e}')
164+
try:
165+
info.update(get_info_from_credential('developer', get_developer_props))
166+
except Exception as e:
167+
logging.error(f'Failed to get "developer" of the app did: {e}')
161168
return info

Diff for: tests/subscription_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import unittest
88

9-
from tests.utils.http_client import HttpClient
9+
from tests.utils.http_client import HttpClient, AppDID
1010
from tests import init_test, test_log, RA, HttpCode
1111

1212

@@ -36,7 +36,11 @@ def test03_vault_get_info(self):
3636

3737
def test04_vault_get_app_stats(self):
3838
response = self.cli.get('/subscription/vault/app_stats')
39-
self.assertTrue(response.status_code in [200, 404])
39+
RA(response).assert_status(200)
40+
apps = RA(response).body().get('apps', list)
41+
apps = list(filter(lambda a: a['app_did'] == AppDID.app_did, apps))
42+
self.assertEqual(len(apps), 1)
43+
self.assertTrue(apps[0]['name']) # resolve app did successfully.
4044

4145
def test05_vault_deactivate(self):
4246
response = self.cli.post('/subscription/vault?op=deactivation')

Diff for: tests/utils/http_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_owner_credential(self, owner_did: DID) -> str:
3535

3636
class AppDID(Entity):
3737
access_token = "123"
38-
app_did = "did:elastos:ienWaA6sfWETz6gVzX78SNytx8VUwDzxai"
38+
app_did = "did:elastos:ic8pRXyAT3JqEXo4PzHQHv5rsoYyEyDwpB" # can resolve, and from ionic sample of hive js.
3939

4040
def __init__(self, name, mnemonic=None, passphrase=None):
4141
Entity.__init__(self, name, mnemonic=mnemonic, passphrase=passphrase, need_resolve=False)

0 commit comments

Comments
 (0)