Skip to content

Commit

Permalink
INDY-2350: fixing tests
Browse files Browse the repository at this point in the history
Signed-off-by: ashcherbakov <[email protected]>
  • Loading branch information
ashcherbakov committed Mar 19, 2020
1 parent 5640899 commit fff3b8f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 150 deletions.
28 changes: 17 additions & 11 deletions indy_node/test/api/test_rich_schema_objects_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@
RICH_SCHEMA_MAPPING, RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, RS_MAPPING_TYPE_VALUE, \
RS_ENCODING_TYPE_VALUE, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE
from indy_node.test.api.helper import validate_write_reply, validate_rich_schema_txn, sdk_build_rich_schema_request
from indy_node.test.rich_schema.templates import RICH_SCHEMA_EX1, W3C_BASE_CONTEXT
from indy_node.test.rich_schema.templates import RICH_SCHEMA_EX1, W3C_BASE_CONTEXT, RICH_SCHEMA_ENCODING_EX1, \
RICH_SCHEMA_MAPPING_EX1, RICH_SCHEMA_CRED_DEF_EX1, RICH_SCHEMA_PRES_DEF_EX1
from plenum.common.util import randomString
from plenum.test.helper import sdk_get_reply, sdk_sign_and_submit_req


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
# The order of creation is essential as some rich schema object reference others by ID
# Encoding's id must be equal to the one used in RICH_SCHEMA_MAPPING_EX1

@pytest.mark.parametrize('txn_type, rs_type, content, rs_id',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT, randomString()),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1, RICH_SCHEMA_EX1['@id']),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, RICH_SCHEMA_ENCODING_EX1,
"did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD"),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, RICH_SCHEMA_MAPPING_EX1,
RICH_SCHEMA_MAPPING_EX1['@id']),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, RICH_SCHEMA_CRED_DEF_EX1, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, RICH_SCHEMA_PRES_DEF_EX1,
RICH_SCHEMA_PRES_DEF_EX1['@id'])])
def test_rich_schema_object_reply_is_valid(looper, sdk_pool_handle, sdk_wallet_steward,
txn_type, rs_type, content):
txn_type, rs_type, content, rs_id):
request = sdk_build_rich_schema_request(looper, sdk_wallet_steward,
txn_type, rs_id=randomString(), rs_name=randomString(),
txn_type=txn_type, rs_id=rs_id, rs_name=randomString(),
rs_version='1.0', rs_type=rs_type,
rs_content=json.dumps(content))
reply = sdk_get_reply(looper, sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_steward, request))[1]

validate_write_reply(reply)
validate_rich_schema_txn(reply['result']['txn'], txn_type)
20 changes: 10 additions & 10 deletions indy_node/test/rich_schema/templates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RICH_SCHEMA_CRED_DEF_EX1 = {
"signatureType": "CL",
"mapping": "did:sov:UVj5w8DRzcmPVDpUMr4AZhJ",
"schema": "did:sov:U5x5w8DRzcmPVDpUMr4AZhJ",
"mapping": "did:sov:8a9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"schema": "did:sov:3e9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"publicKey": {
"primary": "...",
"revocation": "..."
Expand All @@ -22,42 +22,42 @@
'@id': "did:sov:8a9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
'@context': "did:sov:2f9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
'@type': "rdfs:Class",
"schema": "did:sov:4e9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"schema": "did:sov:3e9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"attributes": {
"driver": [{
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 5
}],
"dateOfIssue": [{
"enc": "did:sov:2x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 4
}],
"issuingAuthority": [{
"enc": "did:sov:3x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 3
}],
"licenseNumber": [
{
"enc": "did:sov:4x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 1
},
{
"enc": "did:sov:5x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 2
},
],
"categoriesOfVehicles": {
"vehicleType": [{
"enc": "did:sov:6x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 6
}],
"dateOfIssue": [{
"enc": "did:sov:7x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 7
}],
},
"administrativeNumber": [{
"enc": "did:sov:8x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"enc": "did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD",
"rank": 8
}]
}
Expand Down
136 changes: 61 additions & 75 deletions indy_node/test/rich_schema/test_send_get_rich_schema_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,56 @@
GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID, GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME, RS_VERSION, RS_TYPE, \
RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE
from indy_node.test.api.helper import sdk_write_rich_schema_object_and_check
from indy_node.test.rich_schema.templates import RICH_SCHEMA_EX1, W3C_BASE_CONTEXT
from indy_node.test.rich_schema.templates import RICH_SCHEMA_EX1, W3C_BASE_CONTEXT, RICH_SCHEMA_PRES_DEF_EX1, \
RICH_SCHEMA_CRED_DEF_EX1, RICH_SCHEMA_MAPPING_EX1, RICH_SCHEMA_ENCODING_EX1
from indy_node.test.state_proof.helper import check_valid_proof, sdk_submit_operation_and_get_result
from plenum.common.constants import TXN_TYPE
from plenum.common.exceptions import RequestNackedException
from plenum.common.util import randomString, SortedDict


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
# The order of creation is essential as some rich schema object reference others by ID
# Encoding's id must be equal to the one used in RICH_SCHEMA_MAPPING_EX1

# txn_type, rs_type, content, rs_id, rs_name, rs_version:
PARAMS = [
(
JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT, randomString(), randomString(), '1.0'
),
(
RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1, RICH_SCHEMA_EX1['@id'], randomString(), '2.0'
),
(
RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, RICH_SCHEMA_ENCODING_EX1,
"did:sov:1x9F8ZmxuvDqRiqqY29x6dx9oU4qwFTkPbDpWtwGbdUsrCD", randomString(), '1.1'
),
(
RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, RICH_SCHEMA_MAPPING_EX1, RICH_SCHEMA_MAPPING_EX1['@id'],
randomString(),
'10.0'
),
(
RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, RICH_SCHEMA_CRED_DEF_EX1, randomString(),
randomString(), '1000.0'
),
(
RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, RICH_SCHEMA_PRES_DEF_EX1, RICH_SCHEMA_PRES_DEF_EX1['@id'],
randomString(), '1.1000.1'
)
]


@pytest.fixture(scope='module')
def write_rich_schema(looper, sdk_pool_handle, sdk_wallet_endorser):
for txn_type, rs_type, content, rs_id, rs_name, rs_version in PARAMS:
sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle,
txn_type=txn_type, rs_id=rs_id, rs_name=rs_name,
rs_version=rs_version, rs_type=rs_type, rs_content=content)


@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
def test_send_get_rich_schema_obj_by_id(looper, sdk_pool_handle, sdk_wallet_endorser,
txn_type, rs_type, content):
rs_id = randomString()
rs_name = randomString()
rs_version = '1.0'

sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle,
txn_type=txn_type, rs_id=rs_id, rs_name=rs_name,
rs_version=rs_version, rs_type=rs_type, rs_content=content)

write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version):
get_rich_schema_by_id_operation = {
TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID,
RS_ID: rs_id,
Expand All @@ -57,23 +83,10 @@ def test_send_get_rich_schema_obj_by_id(looper, sdk_pool_handle, sdk_wallet_endo
check_valid_proof(result)


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
def test_send_get_rich_schema_obj_by_metadata(looper, sdk_pool_handle, sdk_wallet_endorser, sdk_wallet_client,
txn_type, rs_type, content):
rs_id = randomString()
rs_name = randomString()
rs_version = '1.0'

sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle,
txn_type=txn_type, rs_id=rs_id, rs_name=rs_name,
rs_version=rs_version, rs_type=rs_type, rs_content=content)

write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version):
get_rich_schema_by_metadata_operation = {
TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA,
RS_NAME: rs_name,
Expand Down Expand Up @@ -101,23 +114,10 @@ def test_send_get_rich_schema_obj_by_metadata(looper, sdk_pool_handle, sdk_walle
check_valid_proof(result)


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
def test_send_get_rich_schema_obj_by_invalid_id(looper, sdk_pool_handle, sdk_wallet_endorser,
txn_type, rs_type, content):
rs_id = randomString()
rs_name = randomString()
rs_version = '1.0'

sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle,
txn_type=txn_type, rs_id=rs_id, rs_name=rs_name,
rs_version=rs_version, rs_type=rs_type, rs_content=content)

write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version):
get_rich_schema_by_id_operation = {
TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID,
RS_ID: randomString(),
Expand All @@ -133,18 +133,13 @@ def test_send_get_rich_schema_obj_by_invalid_id(looper, sdk_pool_handle, sdk_wal
check_valid_proof(result)


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
@pytest.mark.parametrize('invalid_meta_name, invalid_meta_value', [(RS_NAME, randomString()),
(RS_VERSION, "100.3"),
(RS_TYPE, randomString())])
def test_send_get_rich_schema_obj_by_invalid_metadata(looper, sdk_pool_handle, sdk_wallet_endorser,
txn_type, rs_type, content,
write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version,
invalid_meta_name, invalid_meta_value):
rs_id = randomString()
rs_name = randomString()
Expand All @@ -171,15 +166,11 @@ def test_send_get_rich_schema_obj_by_invalid_metadata(looper, sdk_pool_handle, s
assert result['state_proof']
check_valid_proof(result)

@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])

@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
def test_send_get_rich_schema_obj_by_no_id(looper, sdk_pool_handle, sdk_wallet_endorser,
txn_type, rs_type, content):
write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version):
rs_id = randomString()
rs_name = randomString()
rs_version = '1.0'
Expand All @@ -198,17 +189,12 @@ def test_send_get_rich_schema_obj_by_no_id(looper, sdk_pool_handle, sdk_wallet_e
get_rich_schema_by_id_operation)


@pytest.mark.parametrize('txn_type, rs_type, content',
[(JSON_LD_CONTEXT, RS_CONTEXT_TYPE_VALUE, W3C_BASE_CONTEXT),
(RICH_SCHEMA, RS_SCHEMA_TYPE_VALUE, RICH_SCHEMA_EX1),
(RICH_SCHEMA_ENCODING, RS_ENCODING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE, randomString()),
(RICH_SCHEMA_CRED_DEF, RS_CRED_DEF_TYPE_VALUE, randomString()),
(RICH_SCHEMA_PRES_DEF, RS_PRES_DEF_TYPE_VALUE, randomString())])
@pytest.mark.parametrize('txn_type, rs_type, content, rs_id, rs_name, rs_version', PARAMS)
@pytest.mark.parametrize('absent_meta', [RS_NAME, RS_VERSION, RS_TYPE])
def test_send_get_rich_schema_obj_by_no_metadata(looper, sdk_pool_handle, sdk_wallet_endorser,
txn_type, rs_type, content,
absent_meta):
write_rich_schema,
txn_type, rs_type, content, rs_id, rs_name, rs_version,
absent_meta):
rs_id = randomString()
rs_name = randomString()
rs_version = '1.0'
Expand Down
Loading

0 comments on commit fff3b8f

Please sign in to comment.