コード例 #1
0
class TestNamespaceClient:

    namespace_for_test = 'ns-for-test-{}'.format(generate_random_string(8))

    @pytest.fixture
    def common_patch(self):
        with mock.patch(
            'backend.resources.namespace.client.get_namespaces_by_cluster_id',
            new=lambda *args, **kwargs: [{'id': 1, 'name': 'default'}],
        ), mock.patch(
            'backend.resources.namespace.client.create_cc_namespace',
            new=lambda *args, **kwargs: {'id': 2, 'name': self.namespace_for_test},
        ):
            yield

    def test_get_existed(self, common_patch):
        """ 测试获取已经存在的命名空间 """
        client = Namespace(CtxCluster.create(TEST_CLUSTER_ID, TEST_PROJECT_ID, token='token'))
        ret = client.get_or_create_cc_namespace('default', 'admin')
        assert ret == {'name': 'default', 'namespace_id': 1}

    def test_create_nonexistent(self, common_patch):
        """ 测试获取不存在的命名空间(触发创建逻辑) """
        client = Namespace(CtxCluster.create(TEST_CLUSTER_ID, TEST_PROJECT_ID, token='token'))
        ret = client.get_or_create_cc_namespace(self.namespace_for_test, 'admin')
        assert ret == {'name': self.namespace_for_test, 'namespace_id': 2}
        client.delete(name=self.namespace_for_test)
コード例 #2
0
ファイル: conftest.py プロジェクト: ielgnaw/bk-bcs-saas
def template_id():
    """生成一个随机模板集 ID"""
    return generate_random_string(32)
コード例 #3
0
ファイル: conftest.py プロジェクト: ielgnaw/bk-bcs-saas
def namespace_name():
    return generate_random_string(16)
コード例 #4
0
 def get_clusters(self, request):
     return PermsResponse(
         cluster_data,
         iam_path_attrs={'project_id': generate_random_string(32)})
コード例 #5
0
ファイル: test_node.py プロジェクト: ielgnaw/bk-bcs-saas
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import time
from unittest import mock

import pytest

from backend.resources.node.client import Node, NodeObj
from backend.tests.testing_utils.base import generate_random_string
from backend.utils import FancyDict

from ..conftest import FakeBcsKubeConfigurationService

fake_inner_ip = "127.0.0.1"
fake_node_name = generate_random_string(8)
fake_labels = {"bcs-test": "test"}
fake_taints = {"key": "test", "value": "tet", "effect": "NoSchedule"}


class TestNodeObj:
    @pytest.fixture(autouse=True)
    def fake_node_data(self):
        self.data = FancyDict(
            metadata=FancyDict(labels=FancyDict()),
            spec=FancyDict(taints=[]),
            status=FancyDict(
                addresses=[
                    FancyDict(address=fake_inner_ip, type="InternalIP")
                ],
                conditions=[FancyDict(status="True", type="Ready")],
コード例 #6
0
ファイル: test_chart.py プロジェクト: ielgnaw/bk-bcs-saas
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from datetime import datetime

import pytest

from backend.helm.helm.models import chart, repo
from backend.helm.helm.serializers import ChartSLZ
from backend.helm.helm.utils.chart import ChartList
from backend.tests.testing_utils.base import generate_random_string

pytestmark = pytest.mark.django_db

name_or_version = generate_random_string(4)
project_id = generate_random_string(32)


@pytest.fixture(autouse=True)
def create_db_records():
    repo_obj = repo.Repository.objects.create(name=name_or_version, project_id=project_id)
    chart_obj = chart.Chart.objects.create(name=name_or_version, repository=repo_obj)
    version_obj = chart.ChartVersion.objects.create(
        name=name_or_version, version=name_or_version, created=datetime.now(), chart=chart_obj
    )
    chart_obj.defaultChartVersion = version_obj
    chart_obj.save(update_fields=["defaultChartVersion"])


class TestChartList: