Exemplo n.º 1
0
    def test_save_configs(self, mock_get_tenants):
        """ Test Agave initialization
        """
        # Patch list_tenants function and input.
        mock_get_tenants.return_value = sample_tenants_list_response


        # Instantiate Agave objects and save configurations to cache dir.
        try:
            # create a tmp dir and use it as a cache dir.
            cache_dir = tempfile.mkdtemp()

            a = Agave(tenant_id="sd2e")
            a.init()
            a.client_name = "client-1"
            a.username = "******"
            a.save_configs(cache_dir)

            b = Agave(tenant_id="tacc.prod")
            b.init()
            b.client_name = "client-2"
            b.username = "******"
            b.save_configs(cache_dir)

            c = Agave(tenant_id="sd2e")
            c.init()
            c.client_name = "client-3"
            c.username = "******"
            c.save_configs(cache_dir)

            with open("{}/config.json".format(cache_dir), "r") as f:
                config = json.load(f)

            print(config)
            print()
            print(sample_config)
            assert config == sample_config 
        finally:
            shutil.rmtree(cache_dir)
Exemplo n.º 2
0
    def test_save_configs(self, mock_get_tenants):
        """ Test Agave initialization
        """
        # Patch list_tenants function and input.
        mock_get_tenants.return_value = sample_tenants_list_response

        # Instantiate Agave objects and save configurations to cache dir.
        try:
            # create a tmp dir and use it as a cache dir.
            cache_dir = tempfile.mkdtemp()

            a = Agave(tenant_id="sd2e")
            a.init()
            a.client_name = "client-1"
            a.username = "******"
            a.save_configs(cache_dir)

            b = Agave(tenant_id="tacc.prod")
            b.init()
            b.client_name = "client-2"
            b.username = "******"
            b.save_configs(cache_dir)

            c = Agave(tenant_id="sd2e")
            c.init()
            c.client_name = "client-3"
            c.username = "******"
            c.save_configs(cache_dir)

            with open("{}/config.json".format(cache_dir), "r") as f:
                config = json.load(f)

            print(config)
            print()
            print(sample_config)
            assert config == sample_config
        finally:
            shutil.rmtree(cache_dir)
Exemplo n.º 3
0
    def test_clients_subscribtions(self, mock_input, mock_pass, capfd):
        """ Test clients subscribtions
        """
        # Patch username and password.
        mock_input.return_value = "user"
        mock_pass.return_value = "pass"

        # Instantiate Agave object making reference to local mock server.
        local_uri = "http://localhost:{port}".format(
            port=self.mock_server_port)
        ag = Agave(api_server=local_uri)
        ag.client_name = "test"

        # List subscriptions.
        ag.clients_subscribtions()

        # Stdout should contain the putput from the command.
        # Stderr will contain logs from the mock http server.
        out, err = capfd.readouterr()
        assert "Apps" in out
        assert "200" in err
Exemplo n.º 4
0
    def test_client_delete(self, mock_input, mock_pass):
        """ Test clients_delete op

        Patch username and password from user to send a client create request
        to mock server.
        """
        # Patch username and password.
        mock_input.return_value = "user"
        mock_pass.return_value = "pass"

        # Instantiate Agave object making reference to local mock server.
        local_uri = "http://localhost:{port}/".format(
            port=self.mock_server_port)
        ag = Agave(api_server=local_uri)
        ag.client_name = "client-name"
        ag.api_key = "some api key"
        ag.api_secret = "some secret"

        # Create client.
        ag.clients_delete()

        assert ag.api_key == ""
        assert ag.api_secret == ""