github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/rest_api/tests/unit/test_peers_request.py (about)

     1  # Copyright 2017 Intel Corporation
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  # ------------------------------------------------------------------------------
    15  
    16  from aiohttp.test_utils import unittest_run_loop
    17  
    18  from components import BaseApiTest
    19  from sawtooth_rest_api.protobuf.validator_pb2 import Message
    20  from sawtooth_rest_api.protobuf import client_peers_pb2
    21  
    22  
    23  class PeersGetRequestTests(BaseApiTest):
    24      async def get_application(self):
    25          self.set_status_and_connection(
    26              Message.CLIENT_PEERS_GET_REQUEST,
    27              client_peers_pb2.ClientPeersGetRequest,
    28              client_peers_pb2.ClientPeersGetResponse)
    29  
    30          handlers = self.build_handlers(self.loop, self.connection)
    31          return self.build_app(self.loop, '/peers', handlers.fetch_peers)
    32  
    33      @unittest_run_loop
    34      async def test_peers_request(self):
    35          """Verifies a GET /peers works proberly.
    36  
    37          It will receive a Protobuf response with:
    38              - list of peer endoints
    39  
    40          It should send an empty Protobuf request.
    41  
    42          It should send back a JSON response with:
    43              - a response status of 200
    44              - a link property that ends in '/peers'
    45              - a data property matching the peers
    46          """
    47          self.connection.preset_response(
    48              peers=["Peer1", "Peer2"],
    49              status=self.status.OK)
    50  
    51          response = await self.get_assert_200('/peers')
    52          self.connection.assert_valid_request_sent()
    53  
    54          self.assert_has_valid_link(response, '/peers')
    55          self.assertEqual(["Peer1", "Peer2"], response['data'])