コード例 #1
0
ファイル: mtapi.py プロジェクト: HermesCheng/moztrap-cli
def push(filename, credental):
    with open(filename, 'r') as f:
        # Determine its type (caseversion? suite?)
        rtype, rid = orm.parseURL(f.readline()) # TODO: do we need to extract the first line here? or in parse*

        if (rtype == 'caseversion'):
            caseversion = orm.parseCaseversion(''.join(f.readlines()))
            # Call forcePushCaseversion or forcePushSuite
            forcePushCaseversion(rid, caseversion, requests, credental)
        elif (rtype == 'suite'):
            suite = orm.parseSuite(''.join(f.readlines()))
            forcePushSuite(rid, suite, requests, credental)
コード例 #2
0
def push(filename, credental):
    with open(filename, 'r') as f:
        # Determine its type (caseversion? suite?)
        rtype, rid = orm.parseURL(f.readline(
        ))  # TODO: do we need to extract the first line here? or in parse*

        if (rtype == 'caseversion'):
            caseversion = orm.parseCaseversion(''.join(f.readlines()))
            # Call forcePushCaseversion or forcePushSuite
            forcePushCaseversion(rid, caseversion, requests, credental)
        elif (rtype == 'suite'):
            suite = orm.parseSuite(''.join(f.readlines()))
            forcePushSuite(rid, suite, requests, credental)
コード例 #3
0
ファイル: mtapi.py プロジェクト: HermesCheng/moztrap-cli
def forcePushSuite(sid, newsuite, requestlib, credental):
    oldsuite = downloadSuiteById(sid)
    if len(oldsuite['objects']) != len(newsuite['objects']):
        raise Exception("You can't add or remove cases from a suite yet. Remote version has {0} cases, local version has {1} cases".format(len(oldsuite['objects']), len(newsuite['objects'])))

    # FIXME: potential ordering problem, text is sorted by id
    for (oldcaseversion, newcaseversion) in map(None,
                                                sorted(oldsuite['objects'], key=lambda x: x['id']),
                                                newsuite['objects']):
        rtype, rid = orm.parseURL(oldcaseversion['resource_uri'])
        #print(newcaseversion['name'])
        oldcaseversionCmp = copy.deepcopy(oldcaseversion)
        oldcaseversionCmp.pop('resource_uri', None) #FIXME: don't do this after resource_uri is parsed
        if(orm.formatCaseversion(oldcaseversionCmp) == orm.formatCaseversion(newcaseversion)):
            logging.info("No change for caseversion {0}, skipping".format(oldcaseversion['id']))
        else:
            forcePushCaseversion(rid, newcaseversion, requestlib, credental)
コード例 #4
0
def forcePushSuite(sid, newsuite, requestlib, credental):
    oldsuite = downloadSuiteById(sid)
    if len(oldsuite['objects']) != len(newsuite['objects']):
        raise Exception(
            "You can't add or remove cases from a suite yet. Remote version has {0} cases, local version has {1} cases"
            .format(len(oldsuite['objects']), len(newsuite['objects'])))

    # FIXME: potential ordering problem, text is sorted by id
    for (oldcaseversion, newcaseversion) in map(
            None, sorted(oldsuite['objects'], key=lambda x: x['id']),
            newsuite['objects']):
        rtype, rid = orm.parseURL(oldcaseversion['resource_uri'])
        ##print(newcaseversion['name'])
        oldcaseversionCmp = copy.deepcopy(oldcaseversion)
        oldcaseversionCmp.pop(
            'resource_uri',
            None)  #FIXME: don't do this after resource_uri is parsed
        if (orm.formatCaseversion(oldcaseversionCmp) == orm.formatCaseversion(
                newcaseversion)):
            logging.info("No change for caseversion {0}, skipping".format(
                oldcaseversion['id']))
        else:
            forcePushCaseversion(rid, newcaseversion, requestlib, credental)
コード例 #5
0
def cloneByURL(url, dirname="./"):
    (resource_type, rid) = orm.parseURL(url)

    return clone(resource_type, rid, dirname)
コード例 #6
0
ファイル: mtapi.py プロジェクト: HermesCheng/moztrap-cli
def cloneByURL(url, dirname="./"):
    (resource_type, rid) = orm.parseURL(url)

    return clone(resource_type, rid, dirname)
コード例 #7
0
ファイル: mtapi.py プロジェクト: HermesCheng/moztrap-cli
def forcePushCaseversion(rid,  newcaseversion, requestlib, credental):
    # Make sure the number of steps equal
    oldcaseversion = downloadCaseversionById(rid)
    #if len(oldcaseversion['steps']) > len(newcaseversion['steps']):
        #raise Exception("You can't remove steps yet. The test case should have the same number or moreof steps as it remote one.")

    # Update each steps
    # map(None, ...) is a padding version of zip()
    number = 1
    for (oldstep, newstep) in map(None, oldcaseversion['steps'], newcaseversion['steps']):

        if oldstep is None:
            #rtype, rid = orm.parseURL(oldstep['resource_uri'])
            logging.info("Creating new step")

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                        origin=mtorigin, uri="/api/v1/casestep/",
                        username=credental['username'],
                        apikey=credental['api_key']
                    )
            logging.debug(puturl)
            newstep['caseversion'] = oldcaseversion['resource_uri'] # TODO: move this to orm::parseCaseversion?
            r = requestlib.post(puturl, data=json.dumps(newstep), headers=headers, timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)

        elif newstep is None:
            logging.info("Deleting old step")

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                        origin=mtorigin,
                        uri=oldstep['resource_uri'],
                        username=credental['username'],
                        apikey=credental['api_key']
                    )
            logging.debug(puturl)
            r = requestlib.delete(puturl, headers=headers, timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)

        else:
            rtype, rid = orm.parseURL(oldstep['resource_uri'])
            logging.info("Updating " + rtype + " " + rid)

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                        origin=mtorigin,
                        uri=oldstep['resource_uri'],
                        username=credental['username'],
                        apikey=credental['api_key']
                    )
            r = requestlib.put(puturl, data=json.dumps(newstep), headers=headers, timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)
        number += 1

    # Update case name and descriptions
    puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                    origin=mtorigin, uri=oldcaseversion['resource_uri'],
                    username=credental['username'],
                    apikey=credental['api_key']
                )
    logging.debug(puturl)
    # FIXME: 504 timeout, don't know why
    r = requestlib.put(puturl, data=json.dumps(newcaseversion), headers=headers, timeout=config.networktimeout)
    logging.info(r.status_code)
    logging.debug(r.text)
コード例 #8
0
ファイル: mtapi.py プロジェクト: HermesCheng/moztrap-cli
def forcePushCaseversion(rid, newcaseversion, requestlib, credental):
    # Make sure the number of steps equal
    oldcaseversion = downloadCaseversionById(rid)
    #if len(oldcaseversion['steps']) > len(newcaseversion['steps']):
    #raise Exception("You can't remove steps yet. The test case should have the same number or moreof steps as it remote one.")

    # Update each steps
    # map(None, ...) is a padding version of zip()
    number = 1
    for (oldstep, newstep) in map(None, oldcaseversion['steps'],
                                  newcaseversion['steps']):

        if oldstep is None:
            #rtype, rid = orm.parseURL(oldstep['resource_uri'])
            logging.info("Creating new step")

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                origin=mtorigin,
                uri="/api/v1/casestep/",
                username=credental['username'],
                apikey=credental['api_key'])
            logging.debug(puturl)
            newstep['caseversion'] = oldcaseversion[
                'resource_uri']  # TODO: move this to orm::parseCaseversion?
            r = requestlib.post(puturl,
                                data=json.dumps(newstep),
                                headers=headers,
                                timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)

        elif newstep is None:
            logging.info("Deleting old step")

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                origin=mtorigin,
                uri=oldstep['resource_uri'],
                username=credental['username'],
                apikey=credental['api_key'])
            logging.debug(puturl)
            r = requestlib.delete(puturl,
                                  headers=headers,
                                  timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)

        else:
            rtype, rid = orm.parseURL(oldstep['resource_uri'])
            logging.info("Updating " + rtype + " " + rid)

            puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
                origin=mtorigin,
                uri=oldstep['resource_uri'],
                username=credental['username'],
                apikey=credental['api_key'])
            r = requestlib.put(puturl,
                               data=json.dumps(newstep),
                               headers=headers,
                               timeout=config.networktimeout)
            logging.info(r.status_code)
            logging.debug(r.text)
        number += 1

    # Update case name and descriptions
    puturl = "{origin}{uri}?username={username}&api_key={apikey}".format(
        origin=mtorigin,
        uri=oldcaseversion['resource_uri'],
        username=credental['username'],
        apikey=credental['api_key'])
    logging.debug(puturl)
    # FIXME: 504 timeout, don't know why
    r = requestlib.put(puturl,
                       data=json.dumps(newcaseversion),
                       headers=headers,
                       timeout=config.networktimeout)
    logging.info(r.status_code)
    logging.debug(r.text)