Example #1
0
def createCampaignConfig(docContent, url=reqmgr_url):
    """
    Create a new campaign document in central CouchDB
    :param url: API URL
    :param docContent: dictionary with the campaign content
    :return: a boolean whether it succeeded (True) or not (False)
    """
    if isinstance(docContent, list) and len(docContent) > 1:
        print(
            "ERROR: createCampaignConfig expects a single campaign configuration, not a list of them!"
        )
        return False
    elif isinstance(docContent, list):
        docContent = docContent[0]
    outcome = True
    headers = {
        "Content-type": "application/json",
        "Accept": "application/json"
    }
    conn = make_x509_conn(url)
    url = '/reqmgr2/data/campaignconfig/%s' % docContent['CampaignName']
    json_args = json.dumps(docContent)
    conn.request("POST", url, json_args, headers=headers)
    resp = conn.getresponse()
    if resp.status >= 400:
        print(
            "FAILED to create campaign: %s. Response status: %s, response reason: %s"
            % (docContent['CampaignName'], resp.status, resp.reason))
        outcome = False
    conn.close()
    return outcome
Example #2
0
def getCampaignConfig(docName, url=reqmgr_url):
    """
    Retrieve campaign documents from central CouchDB
    :param url: API URL
    :param docName: string with the doc name (use "ALL_DOCS" to retrieve all docs)
    :return: a list of dictionaries
    """
    headers = {
        "Content-type": "application/json",
        "Accept": "application/json"
    }
    conn = make_x509_conn(url)
    url = '/reqmgr2/data/campaignconfig/%s' % docName
    conn.request("GET", url, headers=headers)
    r2 = conn.getresponse()
    data = json.loads(r2.read())
    return data['result']
Example #3
0
def deleteCampaignConfig(docName, url=reqmgr_url):
    """
    Delete an existent campaign document in central CouchDB
    :param url: API URL
    :param docName: string with the document name
    :return: a boolean whether it succeeded (True) or not (False)
    """
    outcome = True
    headers = {
        "Content-type": "application/json",
        "Accept": "application/json",
        "Content-Length": 0
    }  # this is required for DELETE calls
    conn = make_x509_conn(url)
    url = '/reqmgr2/data/campaignconfig/%s' % docName
    conn.request("DELETE", url, headers=headers)
    resp = conn.getresponse()
    if resp.status >= 400:
        print(
            "FAILED to delete campaign: %s. Response status: %s, response reason: %s"
            % (docName, resp.status, resp.reason))
        outcome = False
    conn.close()
    return outcome
Example #4
0
def updateCampaignConfig(docContent, url=reqmgr_url):
    """
    Update an existent campaign document in central CouchDB
    :param url: API URL
    :param docContent: full dictionary with the campaign content
    :return: a boolean whether it succeeded (True) or not (False)
    """
    outcome = True
    headers = {
        "Content-type": "application/json",
        "Accept": "application/json"
    }
    conn = make_x509_conn(url)
    url = '/reqmgr2/data/campaignconfig/%s' % docContent['CampaignName']
    json_args = json.dumps(docContent)
    conn.request("PUT", url, json_args, headers=headers)
    resp = conn.getresponse()
    if resp.status >= 400:
        print(
            "FAILED to update campaign: %s. Response status: %s, response reason: %s"
            % (docContent['CampaignName'], resp.status, resp.reason))
        outcome = False
    conn.close()
    return outcome