コード例 #1
0
def step_impl(context, element, attribute):
    parsed = et.fromstring(str(context.response.text))
    # get elements:
    elementlist = parsed.findall('.//'+str(get_UwsName(element)))
    for elem in elementlist:
        # check if attribute exists in list of attributes:
        ensure(attribute).is_in(elem.attrib)
コード例 #2
0
def step_impl(context, element, values):
    values = [value.strip() for value in values.split(',')]
    parsed = et.fromstring(str(context.response.text))
    # find all elements, anywhere in the tree
    elementlist = parsed.findall('.//'+str(get_UwsName(element)))
    #raise NotImplementedError('%r, %r' % (elementlist, uwselement))
    for elem in elementlist:
        ensure(elem.text).is_in(values)
コード例 #3
0
def step_impl(context):
    parsed = et.fromstring(str(context.response.text))
    elementlist = parsed.findall(".//" + str(get_UwsName("jobref")))
    if len(elementlist) < 2:
        raise NotImplementedError("Job list contains only %d jobs. Cannot test using this step." % len(elementlist))
    # also cannot test this, if there are no creation times!!
    # Problem: there is not even any kind of ordering in the job list that I could assume,
    # so just search for the first two jobs that have a creationTime that is not exactly the same

    i = 0
    job_creationTimes = []
    while len(job_creationTimes) < 2:
        creationTime = None
        while creationTime is None and i < len(elementlist):
            jobref = elementlist[-i]  # use -i here, since I expect descending ordering, if any
            refId = jobref.get("id")
            link = jobref.get(get_XlinkName("href"))
            joblink = get_joblink(context.server, link, refId)
            response = requests.get(joblink, headers=context.headers, auth=context.auth)
            parsed = et.fromstring(str(response.text))
            creationTime = parsed.find(get_UwsName("creationTime")).text
            i = i + 1

        if creationTime is not None:
            # convert creationTime to UTC, in case it has a timezone attached:
            date = dateutil.parser.parse(creationTime)
            if date.utcoffset() is not None:
                utz = pytz.timezone("UTC")
                date = date.astimezone(utz).replace(tzinfo=None)
                date = date.isoformat()
            # check if it is not exactly the same as previous ones,
            # since we need different times for AFTER condition to work:
            if date not in job_creationTimes:
                job_creationTimes.append(date)
        else:
            raise NotImplementedError(
                "Cannot find enough jobs with a creationTime, thus cannot test Scenarios using this. %r %r"
                % (link, creationTime)
            )

    # store the smallest creationTime of these to ensure that I will get at
    # least one result returned when filtering by this creationTime
    context.creationTime_filter = min(job_creationTimes)
コード例 #4
0
def step_impl(context, jobtype):
    when_step = u"""When I make a POST request to base URL with\n"""
    paramtext = u"""| key | value |\n"""
    for key, value in context.job_parameters[jobtype].items():
        paramtext = paramtext + u"""| {key}  | {value} |\n""".format(key=key, value=value)

    context.execute_steps(when_step + paramtext)
    # print ("response: ", context.response)

    # look for jobId immediately and store it
    parsed = et.fromstring(str(context.response.text))
    # print ("parsed: ", parsed)
    jobId = parsed.find(get_UwsName("jobId")).text

    context.job = uws.Job()
    context.job.set_jobId(jobId)
    context.created_jobs.append(jobId)
コード例 #5
0
def step_impl(context, timestamp):
    parsed = et.fromstring(str(context.response.text))
    element = "jobref"
    jobreflist = parsed.findall(get_UwsName(element))
    for jobref in jobreflist:
        refId = jobref.get("id")
        link = jobref.get(get_XlinkName("href"))
        joblink = get_joblink(context.server, link, refId)
        # make a get request and compare the creationTime
        #raise NotImplementedError("joblink", joblink)
        context.joblink = joblink
        context.execute_steps(u'''
            When I make a GET request to URL "{url}"
            Then the response status should be "200"
            And the UWS job creationTime should be later than "{timestamp}"
            '''.format(url=joblink, timestamp=timestamp)
        )
コード例 #6
0
def step_impl(context, timestamp):
    parsed = et.fromstring(str(context.response.text))
    creationTime = parsed.find(get_UwsName("creationTime")).text
    check(creationTime).is_not_none().or_raise(Exception, "Error with creationTime: {msg}. Job link is %s. The http response was: %r" % (context.joblink, context.response))

    # convert creationTime to UTC, in case it has a timezone attached:
    date = dateutil.parser.parse(creationTime)
    if date.utcoffset() is not None:
        utz = pytz.timezone('UTC')
        date = date.astimezone(utz).replace(tzinfo=None)
    date = date.isoformat()
    context.job = uws.Job()
    context.job.creationTime = date

    # also convert timestamp to a useful format for comparison (not helping with format like 2015-W01 though)
    timestamp = dateutil.parser.parse(timestamp).isoformat()

    ensure(date).is_less_than_or_equal_to(timestamp)
コード例 #7
0
def step_impl(context):
    parsed = et.fromstring(str(context.response.text))
    element = "jobref"
    jobreflist = parsed.findall(get_UwsName(element))
    timestamp = '2999-01-01T00:00:00'
    for jobref in jobreflist:
        refId = jobref.get("id")
        link = jobref.get(get_XlinkName("href"))
        joblink = get_joblink(context.server, link, refId)
        context.joblink = joblink;

        # make a get request and store the creationTime
        context.execute_steps(u'''
            When I make a GET request to URL "{url}"
            Then the UWS job creationTime should be earlier than or equal to "{timestamp}"
            '''.format(url=joblink, timestamp=timestamp)
        )
        timestamp = context.job.creationTime
コード例 #8
0
def step_impl(context):
    context.execute_steps(
        u"""
        When I make a GET request to base URL
        """
    )
    # find a job with phase COMPLETED, ERROR, ABORTED or ARCHIVED
    desired_phases = ["PENDING", "QUEUED", "EXECUTING"]
    parsed = et.fromstring(str(context.response.text))
    # find all elements, anywhere in the tree
    elementlist = parsed.findall(".//" + str(get_UwsName("phase")))
    for elem in elementlist:
        if elem.text in desired_phases:
            jobId = elem.getparent().get("id")
            context.job = uws.Job()
            context.job.set_jobId(jobId)
            # raise NotImplementedError("job Id %r" % jobId)
            return
    raise NotImplementedError("Could not find a matching job.")
コード例 #9
0
def step_impl(context, jobtype):
    when_step = u"""When I make a POST request to base URL with\n"""
    paramtext = u"""| key | value |\n"""
    for key, value in context.job_parameters[jobtype].items():
        paramtext = paramtext + u"""| {key}  | {value} |\n""".format(key=key, value=value)

    phasetext = u"""| PHASE  | RUN |\n"""
    context.execute_steps(when_step + paramtext + phasetext)

    # make sure that response was okay and did not return error
    if context.response.status_code != 200:
        raise NotImplementedError(
            "Response was not 200 OK, but %d, with the message:\n%r."
            % (context.response.status_code, context.response.text)
        )
    # look for jobId immediately and store it
    parsed = et.fromstring(str(context.response.text))
    jobId = parsed.find(get_UwsName("jobId")).text

    context.job = uws.Job()
    context.job.set_jobId(jobId)
    context.created_jobs.append(jobId)
コード例 #10
0
def step_impl(context, element, value):
    parsed = et.fromstring(str(context.response.text))
    # find all elements, anywhere in the tree
    elementlist = parsed.findall('.//'+str(get_UwsName(element)))
    for elem in elementlist:
        ensure(elem.text).equals(value)
コード例 #11
0
def step_impl(context, element, last):
    parsed = et.fromstring(str(context.response.text))
    count = len(parsed.findall(get_UwsName(element)))
    ensure(count).is_less_than_or_equal_to(int(last))
コード例 #12
0
def step_impl(context, element, child):
    parsed = et.fromstring(str(context.response.text))
    elementlist = parsed.findall('.//'+str(get_UwsName(element)))
    for elem in elementlist:
        subelement = elem.find(get_UwsName(child))
        ensure(subelement).is_not_none()
コード例 #13
0
def step_impl(context, child):
    parsed = et.fromstring(str(context.response.text))
    for subelement in parsed.iterchildren():
        ensure(subelement.tag).equals(get_UwsName(child))
コード例 #14
0
def step_impl(context, element, value):
    parsed = et.fromstring(str(context.response.text))
    foundvalue = parsed.find(get_UwsName(element)).text
    ensure(foundvalue).equals(value)
コード例 #15
0
def step_impl(context, element, values):
    #raise NotImplementedError('%r' %  context.response.text)
    parsed = et.fromstring(str(context.response.text))
    foundvalue = parsed.find(get_UwsName(element)).text
    ensure(foundvalue).is_in([value.strip() for value in values.split(',')])
コード例 #16
0
def step_impl(context, root):
    parsed = et.fromstring(str(context.response.text))
    foundroot = parsed.tag
    #raise NotImplementedError("%r" % foundroot)
    ensure(foundroot).equals(get_UwsName(root))
コード例 #17
0
def step_impl(context, element):
    parsed = et.fromstring(str(context.response.text))
    #raise NotImplementedError("%r" % parsed)
    foundvalue = parsed.find(get_UwsName(element)).text
    ensure(foundvalue).is_not_none()
コード例 #18
0
def step_impl(context, element, number):
    parsed = et.fromstring(str(context.response.text))
    count = len(parsed.findall(get_UwsName(element)))
    ensure(count).equals(int(number))