Exemplo n.º 1
0
 def test_set_cors_http_request(self, get_auth_mock):
     b = Bogus()
     url = b.serve()
     get_auth_mock.return_value = ("{}/v1/AUTH_user".format(url), "AUTH_t0k3n")
     with patch("swiftsuru.swift_client.AUTH_URL", new_callable=lambda: url):
         cli = SwiftClient()
         cli.set_cors("my_container", "http://localhost")
         self.assertIn("/v1/AUTH_user/my_container", b.called_paths)
Exemplo n.º 2
0
 def test_create_account(self, get_auth_mock):
     b = Bogus()
     url = b.serve()
     get_auth_mock.return_value = ("{}/v1/AUTH_user".format(url), "AUTH_t0k3n")
     with patch("swiftsuru.swift_client.AUTH_URL", new_callable=lambda: url):
         cli = SwiftClient()
         cli.create_account({"X-Account-Meta-Book": "MobyDick", "X-Account-Meta-Subject": "Literature"})
         self.assertIn("/v1/AUTH_user", Bogus.called_paths)
Exemplo n.º 3
0
 def test_remove_container(self, get_auth_mock):
     b = Bogus()
     url = b.serve()
     get_auth_mock.return_value = ("{}/v1/AUTH_user".format(url), "AUTH_t0k3n")
     with patch("swiftsuru.swift_client.AUTH_URL", new_callable=lambda: url):
         cli = SwiftClient()
         cli.remove_container("my_container", {"X-Container-Meta-something": "some metadata"})
         self.assertIn("/v1/AUTH_user/my_container", b.called_paths)
Exemplo n.º 4
0
 def test_remove_account(self, get_auth_mock):
     b = Bogus()
     url = b.serve()
     get_auth_mock.return_value = ("{}/v1/AUTH_user".format(url), "AUTH_t0k3n")
     with patch("swiftsuru.swift_client.AUTH_URL", new_callable=lambda: url):
         cli = SwiftClient()
         cli.remove_account("MobyDick")
         self.assertIn("/v1/AUTH_user", Bogus.called_paths)
Exemplo n.º 5
0
 def test_should_have_called_paths(self):
     b = Bogus()
     url = b.serve()
     response = requests.get("{}/something".format(url))
     self.assertTrue(hasattr(Bogus, "called_paths"))
     response = requests.get("{}/something-else".format(url))
     self.assertIn("/something", Bogus.called_paths)
     self.assertIn("/something-else", Bogus.called_paths)
Exemplo n.º 6
0
 def test_serve_should_start_server_and_respond_to_any_request(self):
     b = Bogus()
     url = b.serve()
     response = requests.get("{}/something".format(url))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, "")
     response = requests.get("{}/something-else".format(url))
     self.assertEqual(response.status_code, 200)
Exemplo n.º 7
0
 def test_should_have_set_headers_and_return_them(self):
     b = Bogus()
     handler = ("/headers", lambda: ('[{"foo":"bar"}]', 201))
     handler_dict = {"handler": handler, "headers": {"Location": "/foo/bar"}}
     b.register(handler, method="POST", headers={"Location": "/foo/bar"})
     self.assertIn(handler_dict, BogusHandler.handlers["POST"])
     url = b.serve()
     response = requests.post("{}/headers".format(url))
     self.assertEqual(response.headers.get("Location"), "/foo/bar")
Exemplo n.º 8
0
 def test_should_register_a_handler_and_request_it(self):
     b = Bogus()
     handler = ("/json", lambda: ('[{"foo":"bar"}]', 201))
     handler_dict = {"handler": handler, "headers": None}
     b.register(handler, method="POST")
     self.assertIn(handler_dict, BogusHandler.handlers["POST"])
     url = b.serve()
     response = requests.post("{}/json".format(url))
     self.assertEqual('[{"foo":"bar"}]', response.content)
Exemplo n.º 9
0
    def test_account_containers(self, get_auth_mock):
        b = Bogus()
        handler = ("/v1/AUTH_user?format=json", lambda: ('[{"count": 0, "bytes": 0, "name": "mycontainer"}]', 200))
        b.register(handler, method="GET")
        url = b.serve()
        get_auth_mock.return_value = ("{}/v1/AUTH_user?format=json".format(url), "AUTH_t0k3n")

        with patch("swiftsuru.swift_client.AUTH_URL", new_callable=lambda: url):
            cli = SwiftClient()
            containers = cli.account_containers()

        expected = [{"count": 0, "bytes": 0, "name": "mycontainer"}]
        self.assertListEqual(expected, containers)
Exemplo n.º 10
0
    def test_bind_app_export_swift_enviroments_and_returns_201(self, conf_mock, dbclient_mock, keystoneclient_mock, swiftclient_mock):
        bog = Bogus()
        bog.register(("/api/ipv4/acl/10.4.3.2/24", lambda: ("{}", 200)),
                     method="PUT",
                     headers={"Location": "/api/jobs/1"})
        url = bog.serve()
        self._mock_confs(url, conf_mock)
        dbclient_mock.return_value.get_instance.return_value = {"name": 'instance_name',
                                                                "team": 'instance_team',
                                                                "container": 'instance_container',
                                                                "plan": 'instance_plan',
                                                                "user": '******',
                                                                "password": '******'}

        dbclient_mock.return_value.get_instance.return_value = {"name": 'plan_name',
                                                                "tenant": 'plan_tenant',
                                                                "description": 'plan_desc'}

        self._keystoneclient_mock(keystoneclient_mock)

        data = "app-host=myapp.cloud.tsuru.io&unit-host=10.4.3.2"
        response = self.client.post("/resources/instance_name/bind-app",
                                    data=data,
                                    content_type=self.content_type)

        self.assertEqual(response.status_code, 201)

        expected_keys = ["SWIFT_ADMIN_URL",
                         "SWIFT_PUBLIC_URL",
                         "SWIFT_INTERNAL_URL",
                         "SWIFT_AUTH_URL",
                         "SWIFT_CONTAINER",
                         "SWIFT_TENANT",
                         "SWIFT_USER",
                         "SWIFT_PASSWORD"]

        computed = json.loads(response.get_data())

        self.assertEquals(len(computed), len(expected_keys))

        for key in expected_keys:
            self.assertIn(key, computed.keys())
Exemplo n.º 11
0
    def test_bind_app_export_swift_enviroments_and_returns_201(self, conf_mock, dbclient_mock, keystoneclient_mock, swiftclient_mock):
        bog = Bogus()
        bog.register(("/api/ipv4/acl/10.4.3.2/24", lambda: ("{}", 200)),
                     method="PUT",
                     headers={"Location": "/api/jobs/1"})
        url = bog.serve()
        self._mock_confs(url, conf_mock)

        dbclient_mock.return_value.get_plan.return_value = {'tenant': 'tenant_name'}
        dbclient_mock.return_value.get_instance.return_value = {"name": 'instance_name',
                                                                "team": 'instance_team',
                                                                "container": 'instance_container',
                                                                "plan": 'instance_plan',
                                                                "user": '******',
                                                                "password": '******'}

        self._keystoneclient_mock(keystoneclient_mock)

        data = "app-host=myapp.cloud.tsuru.io&unit-host=10.4.3.2"
        response = self.client.post("/resources/instance_name/bind-app",
                                    data=data,
                                    content_type=self.content_type)

        self.assertEqual(response.status_code, 201)

        expected_keys = ["SWIFT_ADMIN_URL",
                         "SWIFT_PUBLIC_URL",
                         "SWIFT_INTERNAL_URL",
                         "SWIFT_AUTH_URL",
                         "SWIFT_CONTAINER",
                         "SWIFT_TENANT",
                         "SWIFT_USER",
                         "SWIFT_PASSWORD"]

        computed = json.loads(response.get_data())

        self.assertEquals(len(computed), len(expected_keys))

        for key in expected_keys:
            self.assertIn(key, computed.keys())
Exemplo n.º 12
0
 def test_serve_should_return_and_store_url(self):
     b = Bogus()
     url = b.serve()
     self.assertEqual(url, b.url)