예제 #1
0
    def test_service_endpoint(self):
        exonum_public_base = EXONUM_URL_BASE.format(EXONUM_PROTO, EXONUM_IP,
                                                    EXONUM_PUBLIC_PORT)
        exonum_private_base = EXONUM_URL_BASE.format(EXONUM_PROTO, EXONUM_IP,
                                                     EXONUM_PRIVATE_PORT)

        client = ExonumClient(hostname=EXONUM_IP,
                              public_api_port=EXONUM_PUBLIC_PORT,
                              private_api_port=EXONUM_PRIVATE_PORT)
        service = "service"
        endpoint = "endpoint"

        # Test a public endpoint generation:
        got_endpoint = client.service_endpoint(service, endpoint)

        expected_public_endpoint = exonum_public_base + SERVICE_ENDPOINT_POSTFIX.format(
            service, endpoint)

        self.assertEqual(got_endpoint, expected_public_endpoint)

        # Test a private endpoint generation:
        got_endpoint = client.service_endpoint(service, endpoint, private=True)

        expected_private_endpoint = exonum_private_base + SERVICE_ENDPOINT_POSTFIX.format(
            service, endpoint)

        self.assertEqual(got_endpoint, expected_private_endpoint)
예제 #2
0
    def test_main_sources_download(self):
        client = ExonumClient(hostname=EXONUM_IP,
                              public_api_port=EXONUM_PUBLIC_PORT,
                              private_api_port=EXONUM_PRIVATE_PORT)
        with client.protobuf_loader() as loader:
            loader.load_main_proto_files()

            _runtime_mod = ModuleManager.import_main_module("runtime")
예제 #3
0
    def test_service_sources_download(self):
        client = ExonumClient(hostname=EXONUM_IP,
                              public_api_port=EXONUM_PUBLIC_PORT,
                              private_api_port=EXONUM_PRIVATE_PORT)
        with client.protobuf_loader() as loader:
            loader.load_main_proto_files()
            loader.load_service_proto_files(0, "exonum-supervisor:0.11.0")

            _service_module = ModuleManager.import_service_module(
                "exonum-supervisor:0.11.0", "service")
예제 #4
0
    def test_protobuf_loader_created_twice(self):
        # Test that if we try to create more than one ProtobufLoader entity,
        # in fact only one entity is created:

        client = ExonumClient(hostname=EXONUM_IP,
                              public_api_port=EXONUM_PUBLIC_PORT,
                              private_api_port=EXONUM_PRIVATE_PORT)

        with client.protobuf_loader() as loader_1:
            with client.protobuf_loader() as loader_2:
                self.assertEqual(loader_1, loader_2)
예제 #5
0
    def test_protobuf_loader_created_twice_different_client(self):
        # Test that if we try to create more than one ProtobufLoader entity
        # with different clients, an exception is raised:

        client_2 = ExonumClient(hostname="127.0.0.2",
                                public_api_port=EXONUM_PUBLIC_PORT,
                                private_api_port=EXONUM_PRIVATE_PORT)

        with self.client.protobuf_loader() as _loader:
            with self.assertRaises(ValueError):
                client_2.protobuf_loader()
예제 #6
0
    def test_protobuf_loader_creates_temp_folder(self):
        # Test that the proto directory is created and added to sys.path:
        proto_dir = None

        client = ExonumClient(hostname=EXONUM_IP,
                              public_api_port=EXONUM_PUBLIC_PORT,
                              private_api_port=EXONUM_PRIVATE_PORT)

        with client.protobuf_loader() as loader:
            proto_dir = loader._proto_dir
            self.assertTrue(os.path.isdir(proto_dir))
            self.assertTrue(os.path.exists(proto_dir))
            self.assertTrue(proto_dir in sys.path)

        # Test that everything is cleaned up after use:
        self.assertFalse(os.path.isdir(proto_dir))
        self.assertFalse(os.path.exists(proto_dir))
        self.assertFalse(proto_dir in sys.path)
예제 #7
0
 def test_user_agent(self):
     client = ExonumClient(hostname=EXONUM_IP,
                           public_api_port=EXONUM_PUBLIC_PORT,
                           private_api_port=EXONUM_PRIVATE_PORT)
     resp = client.user_agent()
     self.assertEqual(resp.status_code, 200)
예제 #8
0
 def test_helthcheck(self):
     client = ExonumClient(hostname=EXONUM_IP,
                           public_api_port=EXONUM_PUBLIC_PORT,
                           private_api_port=EXONUM_PRIVATE_PORT)
     resp = client.health_info()
     self.assertEqual(resp.status_code, 200)
 def setUp(self):
     self.client = ExonumClient(hostname=EXONUM_IP,
                                public_api_port=EXONUM_PUBLIC_PORT,
                                private_api_port=EXONUM_PRIVATE_PORT)
예제 #10
0
class TestProtobufLoader(unittest.TestCase):
    def setUp(self):
        self.client = ExonumClient(hostname=EXONUM_IP,
                                   public_api_port=EXONUM_PUBLIC_PORT,
                                   private_api_port=EXONUM_PRIVATE_PORT)

    def test_protobuf_loader_creates_temp_folder(self):
        # Test that the proto directory is created and added to sys.path:
        proto_dir = None

        with self.client.protobuf_loader() as loader:
            proto_dir = loader._proto_dir
            self.assertTrue(os.path.isdir(proto_dir))
            self.assertTrue(os.path.exists(proto_dir))
            self.assertTrue(proto_dir in sys.path)

        # Test that everything is cleaned up after use:
        self.assertFalse(os.path.isdir(proto_dir))
        self.assertFalse(os.path.exists(proto_dir))
        self.assertFalse(proto_dir in sys.path)

    def test_protobuf_loader_creates_temp_folder_manual_init(self):
        # Test that the proto directory is created and added to sys.path:

        loader = self.client.protobuf_loader()
        loader.initialize()

        proto_dir = loader._proto_dir

        self.assertTrue(os.path.isdir(proto_dir))
        self.assertTrue(os.path.exists(proto_dir))
        self.assertTrue(proto_dir in sys.path)

        loader.deinitialize()

        # Test that everything is cleaned up after use:
        self.assertFalse(os.path.isdir(proto_dir))
        self.assertFalse(os.path.exists(proto_dir))
        self.assertFalse(proto_dir in sys.path)

    def test_protobuf_loader_no_client(self):
        # Test that if we try to create ProtobufLoader without client,
        # an exception is raised:

        with self.assertRaises(ValueError):
            ProtobufLoader()

    def test_protobuf_loader_created_twice(self):
        # Test that if we try to create more than one ProtobufLoader entity,
        # in fact only one entity is created:

        with self.client.protobuf_loader() as loader_1:
            with self.client.protobuf_loader() as loader_2:
                self.assertEqual(loader_1, loader_2)

    def test_protobuf_loader_created_twice_different_client(self):
        # Test that if we try to create more than one ProtobufLoader entity
        # with different clients, an exception is raised:

        client_2 = ExonumClient(hostname="127.0.0.2",
                                public_api_port=EXONUM_PUBLIC_PORT,
                                private_api_port=EXONUM_PRIVATE_PORT)

        with self.client.protobuf_loader() as _loader:
            with self.assertRaises(ValueError):
                client_2.protobuf_loader()

    @patch("exonum_client.protobuf_provider.ExonumApiProvider.get",
           new=mock_requests_get)
    def test_main_sources_download(self):
        with self.client.protobuf_loader() as loader:
            loader.load_main_proto_files()

            _blockchain_mod = ModuleManager.import_main_module(
                "exonum.blockchain")

    @patch("exonum_client.protobuf_provider.ExonumApiProvider.get",
           new=mock_requests_get)
    def test_service_sources_download(self):
        with self.client.protobuf_loader() as loader:
            loader.load_main_proto_files()
            loader.load_service_proto_files(0, "exonum-supervisor", "1.0.0")

            _service_module = ModuleManager.import_service_module(
                "exonum-supervisor", "1.0.0", "service")