コード例 #1
0
def boilerplate_check_children(requester):

    children = AccountApis.get_children(requester)
    account = AccountApis.get_organization_account(requester)

    assert_equals(children.status_code, 200)
    assert_equals(account.status_code, 200)
    logging.info(json.dumps(account.json()["data"], indent=4))

    assert_equals(len(account.json()["data"]["child_account_idxs"]),
                  len(children.json()["data"]))
    assert_equals(account.json()["data"]["child_account_idxs"],
                  [e["parent_idx"] for e in children.json()["data"]])
    return
コード例 #2
0
def boilerplate_org_registeration(requester, account):
    ##it will try to create a float account, that what means to register
    ## an organization
    response = AccountApis.register_organization(requester, account)
        ##check duplicate entries

    if response == False:
        logging.error(f"The requester <{requester} may have not registered or may be\
            have a float_account which havent been claimed>")

    elif response.status_code == 200:
        logging.info(f"Registering org for the first time {account['org_name']}")
        pending_db_entry, pending_flag = db_find_on_key_pending(account["email"])
        assert_equals(pending_flag, True)
        assert_equals(pending_db_entry["claimed"], False)
        # If the request is sent successfully, then I expect a response to be returned.
        users_db_entry, user_flag = db_find_on_key(account["email"])
        assert_equals(user_flag, False)
        assert_equals(response.status_code, 200)


    elif response.status_code == 400:
        logging.error(response.json())


    else:
        logging.error(f"response is <{response.json()}> and error code {response.status_code}")


    return response
コード例 #3
0
def boilerplate_claim_account(requester):
    response = AccountApis.claim_account(requester)


    pending_db_entry, pending_flag = db_find_on_key_pending(requester["email"])
    db_entry, db_flag = db_find_on_key(requester["email"])


    if response.status_code == 200:
        logging.info(f"claiming org {requester['org_name']} for the first time")
        # If the request is sent successfully, then I expect a response to be returned.
        assert_equals(pending_flag, True)
        assert_equals(db_flag, True)
        assert_equals(pending_db_entry["claimed"], True)
        assert_equals(bool(pending_db_entry.get("create_asset_idxs")),
                bool(db_entry.get("create_asset_idxs")))



    elif response.status_code == 400:
        logging.error(response.json())

        assert_equals(pending_flag, True)
        assert_equals(db_flag, True)
        assert_true(pending_db_entry["claimed"])


    else:
        logging.error(f"response is <{response.json()}> and error code {response.status_code}")
    return
コード例 #4
0
def boilerplate_child_registeration(requester, child):
    response = AccountApis.register_child(requester, child)

    db_entry, user_flag = db_find_on_key(child["email"])
    parent_db_entry, parent_flag = db_find_on_key(requester["email"])

    assert_equals(user_flag, True)
    assert_equals(parent_flag, True)

    ##if requster is a child, check whether the account have child_zero_pub or not
    if response.status_code == 200:
        logging.info(
            f"Registering child child['first_name'] for the first time for org {requester['org_name']}"
        )
        # If the request is sent successfully, then I expect a response to be returned.
        assert_equals(user_flag, True)
        assert_equals(parent_flag, True)

    elif response.status_code == 400:
        logging.error(response.json())
        assert_equals(user_flag, True)

    else:
        logging.error(
            f"response is <{response.json()}> and error code {response.status_code}"
        )
コード例 #5
0
def boilerplate_check_assets(requester):

    assets = AssetApis.get_assets(requester)
    assert_equals(assets.status_code, 200)

    ##now deciphering ownership_received address in the assets transaction on
    ## blockchain
    asset_list = []
    for asset in assets.json()["data"]:
        issuer_asset_address = asset["ownership_received"]
        issuer_asset = AccountApis.get_address(issuer_asset_address)
        assert_equals(issuer_asset.status_code, 200)
        parent_account = AccountApis.get_address(asset["parent_address"])
        assert_equals(parent_account.status_code, 200)
        assert_equals(issuer_asset.status_code, 200)
        asset.update({
            "ownership_received": issuer_asset.json()["data"],
            "parent_account": parent_account.json()["data"]
        })

        asset_list.append(asset)
    logging.info(json.dumps(asset_list, indent=5))
コード例 #6
0
def boilerplate_get_float_accounts(requester):
    response = AccountApis.get_float_accounts(requester)
    assert_equals(response.status_code, 200)
    return response.json()["data"]
コード例 #7
0

# Third-party imports...
from nose.tools import assert_true, assert_false, assert_equals
from nose.tools import assert_is_not_none
import requests
from test_static import child_one, child_two, master_admin, master_one, master_two,\
        master_three, master_four, admin, conn, master_three_child_one, \
        master_three_child_two, master_four_child_one, master_four_child_two, \
        master_one_lab_one, master_two_lab_two, master_three_child_one_lab_three,\
        master_three_child_two_lab_four, master_four_child_one_lab_five, \
        master_four_child_two_lab_six, user_one
from test_apis import AccountApis
instance = AccountApis()
import json
import coloredlogs, logging
coloredlogs.install()

FRESH_START= False

import rethinkdb as ret

"""

"""

def db_find_on_key(email):
    try:
        result = ret.table("users").filter(ret.row["email"]==email).run(conn).items[0]
        return result, True
    except Exception as e: