def main():
    # Set up a domain to be modified below.
    domain = setup_domain()

    updated_domain = update_domain(domain)

    # Delete it now.
    api('config/domain_management/domains/' + str(updated_domain['id']),
        'DELETE')
Beispiel #2
0
def main():
    # Set up a domain to be modified below.
    domain = setup_domain()

    updated_domain = update_domain(domain)

    # Delete it now.
    api('config/domain_management/domains/' + str(updated_domain['id']),
        'DELETE')
Beispiel #3
0
def delete_domain(domain_id):
    """Deletes a domain using the given domain ID.

    If the domain with this ID has been already deleted,
    response code 404 is returned.
    """
    response = api("config/domain_management/domains/" + str(domain_id), "DELETE")
    pp_response(response)
Beispiel #4
0
def get_default_domain():
    """Retrieves the default domain from the list of all domains.

    The default domain always exists.
    Any other domain is retrieved the same way.
    """
    response = api('config/domain_management/domains/0', 'GET')
    pp_response(response)
Beispiel #5
0
def delete_domain(domain_id):
    """Deletes a domain using the given domain ID.

    If the domain with this ID has been already deleted,
    response code 404 is returned.
    """
    response = api('config/domain_management/domains/' + str(domain_id),
                   'DELETE')
    pp_response(response)
Beispiel #6
0
def get_non_existing_domain():
    """Tries to retrieve a domain that does not exist... and fails with code 404.
    """
    response = api('config/domain_management/domains/-1', 'GET')
    if response.code == 404:
        pp_response(response)
    else:
        print('ERROR: Response code 404 was expected', file=sys.stderr)
        sys.exit(1)
Beispiel #7
0
def get_all_domains():
    """Retrieves the list of all domains and prints their total number and
    the number of active domains.

    The number of the domains must be always greater than zero,
    since the default domain is always in the list of the returned domains.
    """
    response = api('config/domain_management/domains', 'GET')
    response_body = from_json(response)

    print('INFO: Number of all domains retrieved: ' + str(len(response_body)))

    # Now count only active domains.
    num = sum(map(lambda d: d['deleted'] is False, response_body))
    print('INFO: Number of active domains retrieved: ' + str(num))
Beispiel #8
0
def update_domain(domain):
    """Returns an updated domain.

    It is only the description of the domain which is changed from empty to
    'New Description'.
    """
    domain['description'] = 'New Description'
    response = api('config/domain_management/domains/' + str(domain['id']),
                   'POST', data=to_json(domain), json=True)
    if response.code == 200:
        updated_domain = from_json(response)
        if updated_domain['description'] == 'New Description':
            print('INFO: Domain successfully updated', file=sys.stderr)
            return domain

    print('ERROR: Domain update failed', file=sys.stderr)
    pp_response(response)
def update_domain(domain):
    """Returns an updated domain.

    It is only the description of the domain which is changed from empty to
    'New Description'.
    """
    domain['description'] = 'New Description'
    response = api('config/domain_management/domains/' + str(domain['id']),
                   'POST',
                   data=to_json(domain),
                   json=True)
    if response.code == 200:
        updated_domain = from_json(response)
        if updated_domain['description'] == 'New Description':
            print('INFO: Domain successfully updated', file=sys.stderr)
            return domain

    print('ERROR: Domain update failed', file=sys.stderr)
    pp_response(response)