예제 #1
0
    def test_update(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        addon_id = str(db.addon1.id)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_addon_present") as publish_method:

            new_addon = self.build_addon(db)

            res = testapp.put_json(
                f"{api_version}/capsules/{capsule_id}/addons/{addon_id}",
                new_addon,
                status=200).json
            publish_method.assert_called_once()
            dict_contains(res, new_addon)
예제 #2
0
    def test_get_all(self, testapp, db):
        sshkeys_output = self.build_output(db)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user):

            res = testapp.get(api_version + "/sshkeys", status=200).json
            assert dict_contains(res, sshkeys_output)
예제 #3
0
    def test_get(self, testapp, db):
        apptokens_output = self.build_output(db)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user3):

            res = testapp.get(api_version + "/apptokens", status=200).json
            assert dict_contains(apptokens_output[0], res[0])
예제 #4
0
    def test_update_unexisting_runtime(self, testapp, db):
        with patch.object(oidc, 'validate_token', return_value=True), \
             patch("utils.check_user_role", return_value=db.superadmin_user):

            res = testapp.put_json(api_version + '/runtimes/' + unexisting_id,
                                   self._runtime_input,
                                   status=201).json
            assert dict_contains(res, self._runtime_input)
예제 #5
0
    def test_create(self, testapp, db):
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.post_json(api_version + "/apptokens",
                                    self._apptoken_input,
                                    status=201).json
            assert dict_contains(res, self._apptoken_input)
예제 #6
0
    def test_create(self, testapp, db):
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            res = testapp.post_json(api_version + "/sshkeys",
                                    self._sshkey_input,
                                    status=201).json
            publish_method.assert_called_once()
            assert dict_contains(res, self._sshkey_input)
예제 #7
0
    def test_get_self_user(self, testapp, db):
        user_output = user_schema.dump(db.user1)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.get(
                api_version + "/users",
                status=200
            ).json
            assert dict_contains(res[0], user_output)
예제 #8
0
    def test_get_verbose(self, testapp, db):
        capsule_output = self.build_verbose_output(db)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.get(
                api_version + "/capsules?verbose=True",
                status=200
            ).json
            assert dict_contains(res[0], capsule_output)
예제 #9
0
    def test_create_without_rules(self, testapp, db):
        with patch.object(oidc, 'validate_token', return_value=True), \
             patch("utils.check_user_role", return_value=db.superadmin_user):

            new_runtime = dict(self._runtime_input)
            new_runtime['available_opts'][0].pop('validation_rules')

            res = testapp.post_json(api_version + '/runtimes',
                                    new_runtime,
                                    status=201).json
            assert dict_contains(res, new_runtime)
예제 #10
0
    def test_get(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        owners_output = self.build_output(db)

        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.get(api_version + "/capsules/" + capsule_id +
                              "/owners",
                              status=200).json
            assert dict_contains(res, owners_output)
예제 #11
0
    def test_get(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        cron_output = self.build_output(db)

        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.get(
                f"{api_version}/capsules/{capsule_id}/webapp/crons",
                status=200).json
            assert dict_contains(res[0], cron_output)
예제 #12
0
    def test_get_runtime(self, testapp, db):
        runtime_output = runtime_schema.dump(db.runtime1)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.fake_user):

            # Get the runtime id
            runtime_id = str(db.runtime1.id)

            # Get this runtime by id
            runtime = testapp.get(api_version + "/runtimes/" + runtime_id,
                                  status=200).json
            assert dict_contains(runtime, runtime_output)
예제 #13
0
    def test_get_user(self, testapp, db):
        user_output = user_schema.dump(db.user1)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user):

            user_id = db.user1.name
            # Get this user by id
            user = testapp.get(
                api_version + "/users/" + user_id,
                status=200
            ).json
            assert dict_contains(user, user_output)
예제 #14
0
    def test_get_capsule_verbose(self, testapp, db):
        capsule_output = self.build_verbose_output(db)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            # Get the capsule id
            capsule_id = str(db.capsule1.id)
            # Get this capsule by id
            capsule = testapp.get(
                api_version + "/capsules/" + capsule_id + '?verbose=True',
                status=200,
            ).json
            assert dict_contains(capsule, capsule_output)
예제 #15
0
    def test_get(self, testapp, db):
        from pprint import pprint
        pprint(db.runtime1)

        runtime_output = [
            runtime_schema.dump(db.runtime1),
            runtime_schema.dump(db.runtime2),
        ]
        with patch.object(oidc, 'validate_token', return_value=True), \
             patch("utils.check_user_role", return_value=db.user1):

            res = testapp.get(api_version + '/runtimes', status=200).json
            assert dict_contains(res, runtime_output)
예제 #16
0
    def test_update_cron_with_only_command(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        cron_id = str(db.cron1.id)

        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            cron = {"command": "test"}
            base_uri = f"{api_version}/capsules/{capsule_id}/webapp/crons"
            res = testapp.put_json(f"{base_uri}/{cron_id}", cron,
                                   status=200).json
            publish_method.assert_called_once()
            assert dict_contains(res, cron)
예제 #17
0
    def test_create(self, testapp, db):
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user), \
             patch.object(NATS, "publish_webapp_present") as publish_method:
            capsule_id = str(db.capsule1.id)

            # Create fqdn
            res = testapp.post_json(api_version + '/capsules/' + capsule_id +
                                    '/fqdns',
                                    self._fqdn_input,
                                    status=201).json
            publish_method.assert_called_once()

            assert dict_contains(res, self._fqdn_input)
예제 #18
0
    def test_update_runtime(self, testapp, db):
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.superadmin_user):

            # Get the runtime id
            runtime_id = str(db.runtime2.id)

            # Update this runtime by id
            temp_runtime = dict(self._runtime_input)
            temp_runtime["name"] = "New runtime"

            runtime = testapp.put_json(api_version + "/runtimes/" + runtime_id,
                                       temp_runtime,
                                       status=200).json
            assert dict_contains(runtime, temp_runtime)
예제 #19
0
    def test_create(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_addon_present") as publish_method:

            # Create addon
            new_addon = self.build_addon(db)

            res = testapp.post_json(api_version + '/capsules/' + capsule_id +
                                    '/addons',
                                    new_addon,
                                    status=201).json
            publish_method.assert_called_once()
            assert dict_contains(res, new_addon)
예제 #20
0
    def test_patch(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            res = testapp.patch_json(api_version + "/capsules/" + capsule_id +
                                     "/tls",
                                     self._tls_input,
                                     status=200).json
            publish_method.assert_called_once()
            # crt and key are not displayed in result...
            input = dict(self._tls_input)
            input.pop('crt')
            input.pop('key')
            assert dict_contains(res, input)
예제 #21
0
    def test_create(self, testapp, db):
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user), \
             patch("api.capsules.check_owners_on_keycloak"):

            res = testapp.post_json(
                api_version + "/capsules",
                self._capsule_input,
                status=201
            ).json

            res.pop('authorized_keys')
            clean_input = dict(self._capsule_input)
            clean_input.pop('authorized_keys')

            assert dict_contains(res, clean_input)
예제 #22
0
    def test_update(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        fqdn_id = str(db.fqdn1.id)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            current_fqdn = self.build_output(db)
            current_fqdn['name'] = "new.fqdn.com"
            current_fqdn.pop('id')

            res = testapp.put_json(
                f'{api_version}/capsules/{capsule_id}/fqdns/{fqdn_id}',
                current_fqdn,
                status=200).json
            publish_method.assert_called_once()
            assert dict_contains(res, current_fqdn)
예제 #23
0
    def test_create(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        cron_id = str(db.cron1.id)

        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            # Remove existing cron (only one cron per webapp)
            testapp.delete(
                f"{api_version}/capsules/{capsule_id}/webapp/crons/{cron_id}",
                status=204)
            publish_method.assert_called_once()

            res = testapp.post_json(
                f"{api_version}/capsules/{capsule_id}/webapp/crons",
                self._cron_input,
                status=201).json
            assert dict_contains(res, self._cron_input)
예제 #24
0
    def test_update_unexisting_webapp(self, testapp, db):
        capsule_id = str(db.capsule1.id)

        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.user1), \
             patch.object(NATS, "publish_webapp_absent") as publish_method1, \
             patch.object(NATS, "publish_webapp_present") as publish_method2:

            # Remove existing webapp
            testapp.delete(api_version + '/capsules/' + capsule_id + '/webapp',
                           status=204)
            publish_method1.assert_called_once()

            new_webapp = self.build_webapp(db)

            res = testapp.put_json(api_version + '/capsules/' + capsule_id +
                                   '/webapp',
                                   new_webapp,
                                   status=201).json
            publish_method2.assert_called_once()

            assert dict_contains(res, new_webapp)
예제 #25
0
    def test_update(self, testapp, db):
        capsule_id = str(db.capsule1.id)
        with patch.object(oidc, "validate_token", return_value=True), \
             patch("utils.check_user_role", return_value=db.admin_user), \
             patch.object(NATS, "publish_webapp_present") as publish_method:

            current_webapp = self.build_output(db)
            current_webapp.pop('id')
            current_webapp.pop('created_at')
            current_webapp.pop('updated_at')
            current_webapp["env"] = {
                "HTTP_PROXY": "http://proxy.example.com:3128/",
                "HTTPS_PROXY": "http://proxy.example.com:3128/",
            }
            current_webapp["runtime_id"] = str(db.runtime4.id)
            current_webapp.pop('opts')

            res = testapp.put_json(api_version + '/capsules/' + capsule_id +
                                   '/webapp',
                                   current_webapp,
                                   status=200).json
            publish_method.assert_called_once()
            assert dict_contains(res, current_webapp)