def test_serialise_mesage():
    tx = "AU"
    rx = "CN"
    s = str(uuid.uuid4())
    t = str(uuid.uuid4())
    p = str(uuid.uuid4())

    msg = gd.Message(sender=c.Country(tx),
                     receiver=c.Country(rx),
                     subject=u.URI(s),
                     obj=u.URI(t),
                     predicate=u.URI(p))

    expected_json = """
       {{
            "sender": "{}",
            "receiver": "{}",
            "subject": "{}",
            "obj": "{}",
            "predicate": "{}"
       }}
    """.format(tx, rx, s, t, p)

    msg_json = json.dumps(msg, cls=ser.MessageJSONEncoder)

    assert json.loads(msg_json) == json.loads(expected_json)
예제 #2
0
def _generate_message_params():
    msg_dict = _generate_msg_dict()

    A = c.Country(msg_dict["sender"])
    B = c.Country(msg_dict["receiver"])
    subject = u.URI(msg_dict["subject"])
    obj = u.URI(msg_dict["obj"])
    predicate = u.URI(msg_dict["predicate"])

    return (A, B, subject, obj, predicate)
예제 #3
0
def test_is_valid_fqn():
    for fqnstr in (
            "AU.fbe4ad86-8000-497d-a341-78ecd324fd6f.15502b9c-0cc3-4347-ab73-3ab9f93b91d5",
            "UN.CEFACT.Trade.CertificateOfOrigin.created",
            "1.2.3.4.5.6.7.8.9.10.11.12"):
        uri = u.URI(fqnstr)
        assert uri.is_valid_fqn()
예제 #4
0
def test_is_valid_multihash():
    for mhstr in ("QmQtYtUS7K1AdKjbuMsmPmPGDLaKL38M5HYwqxW9RKW49n",
                  "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4"):
        # TODO: should the following string pass?
        # "zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"
        uri = u.URI(mhstr)
        assert uri.is_valid_multihash()
예제 #5
0
def test_is_not_valid_fqn():
    for fqnstr in (
            "AUfbe4ad86-8000-497d-a341-78ecd324fd6f15502b9c-0cc3-4347-ab73-3ab9f93b91d5",
            "UN.CEFACT", 1,
            "AU:fbe4ad86-8000-497d-a341-78ecd324fd6f:15502b9c-0cc3-4347-ab73-3ab9f93b91d5",
            b"AU.fbe4ad86-8000-497d-a341-78ecd324fd6f.15502b9c-0cc3-4347-ab73-3ab9f93b91d5"
    ):
        uri = u.URI(fqnstr)
        assert not uri.is_valid_fqn()
예제 #6
0
def test_URI_validation_OK():
    '''
    A URI can be:
    * a valid URL
    * a fully qualified discoverable name
    * an ipfs multihash or ipfs address
    '''
    for uristr in _generate_OK_URI_list():
        uri = u.URI(uristr)
        print(uri, uristr)
        assert uri.is_valid()
예제 #7
0
def test_is_valid_ipfs():
    for ipfsstr in ("/ipfs/QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4",
                    "/ipfs/zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"):
        uri = u.URI(ipfsstr)
        assert uri.is_valid_ipfs()
예제 #8
0
def test_is_valid_url():
    urlstr = "http://foo.com/bar"
    uri = u.URI(urlstr)
    assert uri.is_valid_url()
예제 #9
0
def test_URI_validation_bad():
    for uristr in _generate_bad_URI_list():
        uri = u.URI(uristr)
        print(uri, uristr)
        assert not uri.is_valid()