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)
 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")
    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)
Beispiel #4
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())
Beispiel #5
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())