github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/bddtests/steps/peer_rest_impl.py (about)

     1  #
     2  # Copyright IBM Corp. 2016 All Rights Reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  
    17  import requests
    18  from behave import *
    19  from peer_basic_impl import buildUrl
    20  from peer_basic_impl import getAttributeFromJSON
    21  
    22  import bdd_test_util
    23  
    24  
    25  @when(u'I request transaction certs with query parameters on "{containerName}"')
    26  def step_impl(context, containerName):
    27      assert 'table' in context, "table (of query parameters) not found in context"
    28      assert 'userName' in context, "userName not found in context"
    29      assert 'compose_containers' in context, "compose_containers not found in context"
    30  
    31      ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers)
    32      request_url = buildUrl(context, ipAddress, "/registrar/{0}/tcert".format(context.userName))
    33      print("Requesting path = {0}".format(request_url))
    34      queryParams = {}
    35      for row in context.table.rows:
    36          key, value = row['key'], row['value']
    37          queryParams[key] = value
    38  
    39      print("Query parameters = {0}".format(queryParams))
    40      resp = requests.get(request_url, params=queryParams, headers={'Accept': 'application/json'}, verify=False)
    41  
    42      assert resp.status_code == 200, "Failed to GET to %s:  %s" % (request_url, resp.text)
    43      context.response = resp
    44      print("")
    45  
    46  @then(u'I should get a JSON response with "{expectedValue}" different transaction certs')
    47  def step_impl(context, expectedValue):
    48      print(context.response.json())
    49      foundValue = getAttributeFromJSON("OK", context.response.json(), "Attribute not found in response (OK)")
    50      print(len(set(foundValue)))
    51      assert (len(set(foundValue)) == int(expectedValue)), "For attribute OK, expected different transaction cert of size (%s), instead found (%s)" % (expectedValue, len(set(foundValue)))