예제 #1
0
 def test_account_failure(self, dep: DEP, expected_status: int, expected_text: str):
     try:
         dep.fetch_token()
         dep.account()
     except DEPError as e:
         assert e.response.status_code == expected_status
         assert e.text == expected_text
예제 #2
0
def dep_sync_organization(app: Flask, dep: DEP):
    """Synchronise information from the DEP service to the local database.
    """
    with app.app_context():
        try:
            app.logger.debug(
                'Querying for DEP Account information from the database')
            dep_account: DEPAccount = db.session.query(DEPAccount).one()

            # Refresh organisation information if there is none
            if dep_account.server_name is None or dep_account.server_uuid is None:
                app.logger.debug(
                    'Refreshing information about organization from the DEP service'
                )
                account = dep.account()

                if account is not None:
                    dep_account.server_uuid = account.get('server_uuid', None)
                    dep_account.server_name = account.get('server_name', None)
                    dep_account.facilitator_id = account.get(
                        'facilitator_id', None)
                    dep_account.admin_id = account.get('admin_id', None)
                    dep_account.org_name = account.get('org_name', None)
                    dep_account.org_email = account.get('org_email', None)
                    dep_account.org_phone = account.get('org_phone', None)
                    dep_account.org_address = account.get('org_address', None)
                    dep_account.org_id = account.get('org_id', None)
                    dep_account.org_id_hash = account.get('org_id_hash', None)
                    if 'org_type' in account:
                        dep_account.org_type = DEPOrgType(account['org_type'])

                    if 'org_version' in account:
                        dep_account.org_version = DEPOrgVersion(
                            account['org_version'])

                    db.session.commit()
                    app.logger.info(
                        'Successfully fetched DEP Organization: %s',
                        dep_account.org_name)
                else:
                    app.logger.warn('Failed to fetch DEP Organization')
            else:
                app.logger.info('DEP Organization already fetched: %s',
                                dep_account.org_name)

        except sqlalchemy.orm.exc.NoResultFound:
            app.logger.info(
                'Not attempting to fetch DEP account information. No DEP account is configured.'
            )
예제 #3
0
    def test_account(self, dep_live: DEP):
        dep_live.fetch_token()
        account = dep_live.account()
        assert account is not None
        assert 'server_name' in account
        assert 'server_uuid' in account
        assert 'facilitator_id' in account
        assert 'admin_id' in account
        assert 'org_name' in account
        assert 'org_email' in account
        assert 'org_phone' in account
        assert 'org_address' in account

        # X-Server-Protocol 3
        assert 'org_id' in account
        assert 'org_id_hash' in account
        assert 'org_type' in account
        assert 'org_version' in account
예제 #4
0
 def test_account(self, dep: DEP):
     dep.fetch_token()
     account = dep.account()
     assert account is not None