Exemple #1
0
    def __init__(self,
                 max_length=1024,
                 special_chars=r"!@#$%^&*\/{}[]",
                 **kwargs):
        super().__init__(**kwargs)
        self.max_length = max_length
        self._sp_vals_positive = [
            's', special_chars, random_string(max_length)
        ]

        self._sp_vals_negative = [
            generate_json_from_schema(json_schema=None),
            PreparedFieldValue(
                value='some\nstring',
                f_type=self,
                error_messages=["New line symbols are not allowed"],
            ),
            PreparedFieldValue(
                value=random_string(max_length + 1),
                f_type=self,
                error_messages=[
                    f"Ensure this field has no more than {max_length} characters."
                ],
            ),
        ]
        self.error_message_invalid_data = "Not a valid string."
Exemple #2
0
def test_role_with_two_hierarchy_not_allowed(sdk_client_fs):
    """
    Test that we can not create a new role with childs from different hierarchy
    """
    application_role = {
        "id":
        sdk_client_fs.role(
            name=BusinessRoles.ViewClusterConfigurations.value.role_name).id
    }
    infrastructure_role = {
        "id":
        sdk_client_fs.role(
            name=BusinessRoles.ViewProviderConfigurations.value.role_name).id
    }
    generic_role = {
        "id":
        sdk_client_fs.role(
            name=BusinessRoles.ViewADCMSettings.value.role_name).id
    }
    with allure.step(
            "Assert that create role with different hierarchy is not possible"
    ), pytest.raises(ErrorMessage):
        sdk_client_fs.role_create(
            name=random_string(),
            display_name=random_string(),
            child=[application_role, infrastructure_role],
        )
    role = sdk_client_fs.role_create(
        name=random_string(),
        display_name=random_string(),
        child=[application_role],
    )
    with allure.step(
            "Assert that update role to different hierarchy is not possible"
    ), pytest.raises(ErrorMessage):
        role.update(child=[application_role, infrastructure_role])
    with allure.step(
            "Assert that cluster role can be mixed with not parametrized role"
    ):
        sdk_client_fs.role_create(
            name=random_string(),
            display_name=random_string(),
            child=[application_role, generic_role],
        )
    with allure.step(
            "Assert that host role can be mixed with not parametrized role"):
        sdk_client_fs.role_create(
            name=random_string(),
            display_name=random_string(),
            child=[infrastructure_role, generic_role],
        )
Exemple #3
0
def test_host_and_cluster_roles(sdk_client_fs):
    """
    Test that cluster and host roles is allowed to use together
    """
    cluster_role = {
        "id":
        sdk_client_fs.role(
            name=BusinessRoles.ViewClusterConfigurations.value.role_name).id
    }
    host_role = {
        "id":
        sdk_client_fs.role(name=BusinessRoles.RemoveHosts.value.role_name).id
    }
    with allure.step(
            "Assert that create role with cluster and host parametrization is allowed"
    ):
        sdk_client_fs.role_create(
            name=random_string(),
            display_name=random_string(),
            child=[cluster_role, host_role],
        )
Exemple #4
0
 def __init__(self, enum_values, **kwargs):
     super().__init__(**kwargs)
     self.enum_values = enum_values
     value = random_string()
     while True:
         if value not in self.enum_values:
             break
     self._sp_vals_negative = [
         PreparedFieldValue(
             value,
             f_type=Type[String],
             error_messages=[f'"{value}" is not a valid choice.'],
         )
     ]
Exemple #5
0
def gen_string(prop=None):
    """
    Generate String value
    :param prop: dict
    Examples: {'minLength': 10, 'maxLength': 154}
              {'pattern': '^\\d+\\w*$'}
    """
    if not prop:
        prop = {}
    min_length = prop.get("minLength", 1)
    max_length = prop.get("maxLength", 1024)
    pattern = prop.get("pattern", None)
    if pattern:
        if min_length or max_length:
            # TODO implement pattern with min/max length
            raise NotImplementedError
        return Xeger().xeger(pattern)
    return random_string(strlen=randint(min_length, max_length))
Exemple #6
0
def _gen_any_obj():
    return {random_string(): _gen_anything() for _ in range(randint(1, 10))}
Exemple #7
0
 def generate(self, **kwargs):
     return random_string(randint(64, 200))
Exemple #8
0
 def generate(self, **kwargs):
     return random_string()
Exemple #9
0
def random_json():
    """Generating json with random key values"""
    return {"int": randint(1, 100), "str": random_string()}
Exemple #10
0
 def generate(self, **kwargs):
     return random_string(randint(1, self.max_length))