Skip to content

Commit 3ccede0

Browse files
GrapeBaBaJonathanLevi
authored andcommitted
Add rest api bddtests
Init rest api bddtests, first cover GetTransactionCert(). Fix Github issue #2363 Change-Id: I55c23eb25d1d6caac06ad6893fd5eef1e35e2d3b Signed-off-by: grapebaba <[email protected]>
1 parent 27e7db7 commit 3ccede0

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

bddtests/docker-compose-rest.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
membersrvc0:
2+
extends:
3+
file: compose-defaults.yml
4+
service: membersrvc
5+
6+
vp0:
7+
extends:
8+
file: compose-defaults.yml
9+
service: vp
10+
environment:
11+
- CORE_PEER_ID=vp0
12+
- CORE_SECURITY_ENABLED=true
13+
- CORE_PEER_PKI_ECA_PADDR=membersrvc0:7054
14+
- CORE_PEER_PKI_TCA_PADDR=membersrvc0:7054
15+
- CORE_PEER_PKI_TLSCA_PADDR=membersrvc0:7054
16+
links:
17+
- membersrvc0

bddtests/peer_rest.feature

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Test REST API Features of Peers
3+
#
4+
# Tags that can be used and will affect test internals:
5+
# @doNotDecompose will NOT decompose the named compose_yaml after scenario ends. Useful for setting up environment and reviewing after scenario.
6+
# @chaincodeImagesUpToDate use this if all scenarios chaincode images are up to date, and do NOT require building. BE SURE!!!
7+
8+
Feature: Peer REST API
9+
As a Fabric developer
10+
I want to verify REST API behavior
11+
12+
Scenario: 1 peer and 1 membersrvc, query transaction certs with query parameter count
13+
Given we compose "docker-compose-rest.yml"
14+
And I use the following credentials for querying peers:
15+
| peer | username | secret |
16+
| vp0 | test_user0 | MS9qrN8hFjlE |
17+
And I register with CA supplying username "test_user0" and secret "MS9qrN8hFjlE" on peers:
18+
| vp0 |
19+
20+
When I request transaction certs with query parameters on "vp0"
21+
| key | value |
22+
| count | 1 |
23+
Then I should get a JSON response with "1" different transaction certs

bddtests/steps/peer_basic_impl.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
import time
2121
import copy
22+
from behave import *
2223
from datetime import datetime, timedelta
2324

2425
import sys, requests, json

bddtests/steps/peer_rest_impl.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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)))

0 commit comments

Comments
 (0)