コード例 #1
0
def matches_when_properties_all_match():
    matcher = has_attrs(
        username=equal_to("bob"),
        email_address=equal_to("*****@*****.**"),
    )
    
    assert_equal(matched(), matcher.match(User("bob", "*****@*****.**")))
コード例 #2
0
def test_app_update_rollback():
    """Tests that an updated app can be rolled back to its initial version."""

    app_def = apps.readiness_and_health_app("app-update-rollback")
    app_id = app_def["id"]

    # First deployment
    client = marathon.create_client()
    client.add_app(app_def)
    deployment_wait(service_id=app_id)

    tasks = client.get_tasks(app_id)
    assert_that(tasks, has_len(equal_to(1)))

    # Second deployment
    app_def['instances'] = 2
    client.update_app(app_id, app_def)
    deployment_wait(service_id=app_id)

    tasks = client.get_tasks(app_id)
    assert_that(tasks, has_len(equal_to(2)))

    # Third deployment with rollback
    # provides a testing delay to rollback in the meantime
    app_def['readinessChecks'][0]['intervalSeconds'] = 30
    app_def['instances'] = 1
    deployment_id = client.update_app(app_id, app_def)
    client.rollback_deployment(deployment_id)
    deployment_wait(service_id=app_id)

    # update to 1 instance is rollback to 2
    tasks = client.get_tasks(app_id)
    assert_that(tasks, has_len(equal_to(2)))
コード例 #3
0
def description_contains_descriptions_of_submatchers():
    matcher = contains_exactly(equal_to("apple"), equal_to("banana"))
    
    assert_equal(
        "iterable containing these 2 elements in any order:\n * 'apple'\n * 'banana'",
        matcher.describe()
    )
コード例 #4
0
def mismatches_when_duplicate_is_missing():
    matcher = includes(equal_to("apple"), equal_to("apple"))

    assert_equal(
        unmatched("was missing element:\n * 'apple'\nThese elements were in the iterable, but did not match the missing element:\n * 'apple': already matched"),
        matcher.match(["apple"])
    )
コード例 #5
0
def mismatches_when_item_is_missing():
    matcher = includes(equal_to("apple"), equal_to("banana"), equal_to("coconut"))

    assert_equal(
        unmatched("was missing element:\n * 'banana'\nThese elements were in the iterable, but did not match the missing element:\n * 'coconut': was 'coconut'\n * 'apple': already matched"),
        matcher.match(["coconut", "apple"])
    )
コード例 #6
0
def mismatches_when_item_is_missing():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"), equal_to("coconut"))
    
    assert_equal(
        unmatched("element at index 2 was missing"),
        matcher.match(["apple", "banana"])
    )
コード例 #7
0
def description_contains_descriptions_of_submatchers():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"))
    
    assert_equal(
        "iterable containing in order:\n 0: 'apple'\n 1: 'banana'",
        matcher.describe()
    )
コード例 #8
0
def mismatches_when_items_are_in_wrong_order():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"))
    
    assert_equal(
        unmatched("element at index 0 mismatched:\n * was 'banana'"),
        matcher.match(["banana", "apple"])
    )
コード例 #9
0
def description_contains_descriptions_of_submatchers():
    matcher = includes(equal_to("apple"), equal_to("banana"))

    assert_equal(
        "iterable including elements:\n * 'apple'\n * 'banana'",
        matcher.describe()
    )
コード例 #10
0
def matches_when_submatchers_all_match():
    matcher = any_of(
        has_attr("username", equal_to("bob")),
        has_attr("email_address", equal_to("*****@*****.**")),
    )
    
    assert_equal(matched(), matcher.match(User("bob", "*****@*****.**")))
コード例 #11
0
def description_contains_descriptions_of_submatchers():
    matcher = any_of(
        has_attr("username", equal_to("bob")),
        has_attr("email_address", equal_to("*****@*****.**")),
    )
    
    assert_equal(
        "any of:\n * object with attribute username: '******'\n * object with attribute email_address: '*****@*****.**'",
        matcher.describe()
    )
コード例 #12
0
def mismatches_when_property_is_missing():
    matcher = has_attrs(
        ("username", equal_to("bob")),
        ("email_address", equal_to("*****@*****.**")),
    )
    
    assert_equal(
        unmatched("was missing attribute username"),
        matcher.match("bobbity")
    )
コード例 #13
0
def matches_when_any_submatchers_match():
    matcher = any_of(
        equal_to("bob"),
        equal_to("jim"),
    )
    
    assert_equal(
        matched(),
        matcher.match("bob"),
    )
コード例 #14
0
def can_pass_properties_as_list_of_tuples():
    matcher = has_attrs(
        ("username", equal_to("bob")),
        ("email_address", equal_to("*****@*****.**")),
    )
    
    assert_equal(
        "object with attributes:\n * username: '******'\n * email_address: '*****@*****.**'",
        matcher.describe()
    )
コード例 #15
0
def explanation_of_mismatch_contains_mismatch_of_property():
    matcher = has_attrs(
        username=equal_to("bob"),
        email_address=equal_to("*****@*****.**"),
    )
    
    assert_equal(
        unmatched("attribute email_address was '*****@*****.**'"),
        matcher.match(User("bob", "*****@*****.**"))
    )
コード例 #16
0
def mismatches_when_no_submatchers_match():
    matcher = any_of(
        equal_to("bob"),
        equal_to("jim"),
    )
    
    assert_equal(
        unmatched("did not match any of:\n * 'bob' [was 'alice']\n * 'jim' [was 'alice']"),
        matcher.match("alice"),
    )
コード例 #17
0
def test_launch_docker_grace_period(marathon_service_name):
    """Tests 'taskKillGracePeriodSeconds' option using a Docker container in a Marathon environment.
       Read more details about this test in `test_root_marathon.py::test_launch_mesos_root_marathon_grace_period`
    """

    app_id = '/launch-docker-grace-period-app'
    app_def = apps.docker_http_server(app_id)
    app_def['container']['docker']['image'] = 'kensipe/python-test'

    default_grace_period = 3
    grace_period = 20
    app_def['taskKillGracePeriodSeconds'] = grace_period
    app_def['cmd'] = 'python test.py'
    task_name = app_id.lstrip('/')

    client = marathon.create_client()
    client.add_app(app_def)
    deployment_wait(service_id=app_id)

    tasks = get_service_task(marathon_service_name, task_name)
    assert tasks is not None

    client.scale_app(app_id, 0)
    tasks = get_service_task(marathon_service_name, task_name)
    assert tasks is not None

    # tasks should still be here after the default_graceperiod
    time.sleep(default_grace_period + 1)
    tasks = get_service_task(marathon_service_name, task_name)
    assert tasks is not None

    # but not after the set grace_period
    time.sleep(grace_period)
    assert_that(lambda: get_service_task(marathon_service_name, task_name),
                eventually(equal_to(None), max_attempts=30))
コード例 #18
0
ファイル: service.py プロジェクト: mesosphere/marathon
def wait_for_service_endpoint(service_name, timeout_sec=120, path=""):
    """
    Checks the service url. Waits for exhibitor to start up (up to 20 minutes) and then checks the url on all masters.

    if available it returns true,
    on expiration throws an exception
    """

    def master_service_status_code(url):
        logger.info('Querying %s', url)
        auth = DCOSAcsAuth(dcos_acs_token())

        response = requests.get(
            url=url,
            timeout=5,
            auth=auth,
            verify=verify_ssl())

        return response.status_code

    schema = 'https' if ee_version() == 'strict' or ee_version() == 'permissive' else 'http'
    logger.info('Waiting for service /service/{}/{} to become available on all masters'.format(service_name, path))

    for ip in dcos_masters_public_ips():
        url = "{}://{}/service/{}/{}".format(schema, ip, service_name, path)
        assert_that(lambda: master_service_status_code(url), eventually(equal_to(200), max_attempts=timeout_sec/5))
コード例 #19
0
def mismatches_when_contains_extra_item():
    matcher = contains_exactly(equal_to("apple"))
    
    assert_equal(
        unmatched("had extra elements:\n * 'coconut'"),
        matcher.match(["coconut", "apple"])
    )
コード例 #20
0
def mismatches_when_item_is_expected_but_iterable_is_empty():
    matcher = includes(equal_to("apple"))

    assert_equal(
        unmatched("iterable was empty"),
        matcher.match([])
    )
コード例 #21
0
def description_uses_singular_when_there_is_one_submatcher():
    matcher = contains_exactly(equal_to("apple"))

    assert_equal(
        "iterable containing 1 element:\n * 'apple'",
        matcher.describe()
    )
コード例 #22
0
def mismatches_when_actual_is_not_iterable():
    matcher = includes(equal_to("apple"))

    assert_equal(
        unmatched("was not iterable\nwas 0"),
        matcher.match(0)
    )
コード例 #23
0
ファイル: package.py プロジェクト: mesosphere/marathon
def add_package_repo(
        repo_name,
        repo_url,
        index=None,
        wait_for_package=None,
        expect_prev_version=None):
    """ Add a repository to the list of package sources

        :param repo_name: name of the repository to add
        :type repo_name: str
        :param repo_url: location of the repository to add
        :type repo_url: str
        :param index: index (precedence) for this repository
        :type index: int
        :param wait_for_package: the package whose version should change after the repo is added
        :type wait_for_package: str, or None

        :return: True if successful, False otherwise
        :rtype: bool
    """

    package_manager = _get_package_manager()
    if wait_for_package:
        prev_version = package_manager.get_package_version(wait_for_package, None)
    if not package_manager.add_repo(repo_name, repo_url, index):
        return False
    if wait_for_package:
        try:
            assert_that(lambda: package_version_changed_predicate(package_manager, wait_for_package, prev_version),
                        eventually(equal_to(True)))
        except AssertionError:
            return False
    return True
コード例 #24
0
def mismatches_when_item_in_iterable_does_not_match():
    matcher = all_elements(equal_to("apple"))

    assert_equal(
        unmatched("element at index 1 mismatched: was 'orange'"),
        matcher.match(["apple", "orange"])
    )
コード例 #25
0
def description_contains_descriptions_of_submatcher():
    matcher = all_elements(equal_to("apple"))

    assert_equal(
        "all elements of iterable match: 'apple'",
        matcher.describe()
    )
コード例 #26
0
ファイル: task.py プロジェクト: mesosphere/marathon
def wait_for_task_completion(task_id):
    """ Block until the task completes

        :param task_id: task ID
        :type task_id: str

        :rtype: None
    """
    assert_that(lambda: task_completed(task_id), eventually(equal_to(True)))
コード例 #27
0
def can_pass_properties_as_dictionary():
    matcher = has_attrs({
        "username": equal_to("bob"),
    })
    
    assert_equal(
        "object with attributes:\n * username: '******'",
        matcher.describe()
    )
コード例 #28
0
def description_contains_descriptions_of_properties():
    matcher = has_attrs(
        username=equal_to("bob"),
    )
    
    assert_equal(
        "object with attributes:\n * username: '******'",
        matcher.describe()
    )
コード例 #29
0
ファイル: test_funk.py プロジェクト: mwilliamson/funk
def test_can_use_matchers_instead_of_values_for_keyword_arguments(mocks):
    return_value = "Whoopee!"
    mock = mocks.mock()
    expects(mock).save.with_args(value=equal_to("Blah")).returns(return_value)
    
    assert_raises(UnexpectedInvocationError, lambda: mock.save())
    assert_raises(UnexpectedInvocationError, lambda: mock.save(key="word"))
    assert_raises(UnexpectedInvocationError, lambda: mock.save("positional"))
    assert_raises(UnexpectedInvocationError, lambda: mock.save("positional", key="word"))
    
    assert mock.save(value="Blah") is return_value
コード例 #30
0
def test_launch_mesos_container_with_docker_image():
    """Launches a Mesos container with a Docker image."""

    app_def = apps.ucr_docker_http_server(app_id='/launch-mesos-container-with-docker-image-app')
    app_id = app_def["id"]

    client = marathon.create_client()
    client.add_app(app_def)
    deployment_wait(service_id=app_id)

    assert_that(lambda: client.get_tasks(app_id),
                eventually(has_len(equal_to(1)), max_attempts=30))

    app = client.get_app(app_id)
    assert app['container']['type'] == 'MESOS', "The container type is not MESOS"
コード例 #31
0
def mismatches_when_contains_extra_item():
    matcher = contains_exactly(equal_to("apple"))

    assert_equal(unmatched("had extra elements:\n * 'coconut'"),
                 matcher.match(["coconut", "apple"]))
コード例 #32
0
 def test_string_is_unchanged(self):
     query = schema.String()
     assert_that(query.to_json_value("42"), equal_to("42"))
コード例 #33
0
def matches_when_all_submatchers_match_one_item_with_no_items_leftover():
    matcher = includes(equal_to("apple"), equal_to("banana"))

    assert_equal(matched(), matcher.match(["apple", "banana"]))
    assert_equal(matched(), matcher.match(["apple", "banana", "coconut"]))
コード例 #34
0
def wait_for_service_endpoint_removal(service_name, timeout_sec=120):
    wait_fixed = timeout_sec * 1000 / 24
    return assert_that(
        lambda: service_unavailable_predicate(service_name),
        eventually(equal_to(True), wait_fixed=wait_fixed, max_attempts=24))
コード例 #35
0
def mismatches_when_item_is_expected_but_iterable_is_empty():
    matcher = includes(equal_to("apple"))

    assert_equal(unmatched("iterable was empty"), matcher.match([]))
コード例 #36
0
def mismatches_when_item_is_missing():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"),
                          equal_to("coconut"))

    assert_equal(unmatched("element at index 2 was missing"),
                 matcher.match(["apple", "banana"]))
コード例 #37
0
def description_contains_descriptions_of_submatchers():
    matcher = contains_exactly(equal_to("apple"), equal_to("banana"))

    assert_equal(
        "iterable containing these 2 elements in any order:\n * 'apple'\n * 'banana'",
        matcher.describe())
コード例 #38
0
def description_contains_description_of_property():
    matcher = has_feature("name", lambda user: user.username, equal_to("bob"))
    assert_equal("name: 'bob'", matcher.describe())
コード例 #39
0
def mismatches_when_items_are_in_wrong_order():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"))

    assert_equal(unmatched("element at index 0 mismatched:\n  * was 'banana'"),
                 matcher.match(["banana", "apple"]))
コード例 #40
0
def explanation_of_mismatch_contains_mismatch_of_feature():
    matcher = has_feature("name", lambda user: user.username, equal_to("bob"))
    assert_equal(unmatched("name: was 'bobbity'"),
                 matcher.match(User("bobbity")))
コード例 #41
0
def mismatches_when_feature_extraction_fails():
    # TODO:
    return
    matcher = has_feature("name", lambda user: user.username, equal_to("bob"))
    assert_equal(unmatched(""), matcher.match("bobbity"))
コード例 #42
0
def matches_when_feature_has_correct_value():
    matcher = has_feature("name", lambda user: user.username, equal_to("bob"))
    assert_equal(matched(), matcher.match(User("bob")))
コード例 #43
0
def matches_when_all_submatchers_match_one_item_with_no_items_leftover():
    matcher = contains_exactly(equal_to("apple"), equal_to("banana"))

    assert_equal(matched(), matcher.match(["banana", "apple"]))
コード例 #44
0
def description_contains_descriptions_of_submatchers():
    matcher = is_sequence(equal_to("apple"), equal_to("banana"))

    assert_equal("iterable containing in order:\n  0: 'apple'\n  1: 'banana'",
                 matcher.describe())
コード例 #45
0
def description_uses_singular_when_there_is_one_submatcher():
    matcher = contains_exactly(equal_to("apple"))

    assert_equal("iterable containing 1 element:\n * 'apple'",
                 matcher.describe())
コード例 #46
0
def test_when_param_does_not_exist_on_params_then_error_is_raised():
    params = schema.Params("book", {})
    
    error = pytest.raises(ValueError, lambda: params.author)
    
    assert_that(str(error.value), equal_to("book has no param author"))
コード例 #47
0
def wait_for_mesos_task_removal(task_name, timeout_sec=120):
    wait_fixed = timeout_sec * 1000 / 24
    assert_that(
        lambda: mesos_task_not_present_predicate(task_name),
        eventually(equal_to(True), wait_fixed=wait_fixed, max_attempts=24))
コード例 #48
0
 def test_bool_is_unchanged(self):
     query = schema.Boolean()
     assert_that(query.to_json_value(True), equal_to(True))
コード例 #49
0
def mismatches_when_actual_is_not_iterable():
    matcher = includes(equal_to("apple"))

    assert_equal(unmatched("was not iterable\nwas 0"), matcher.match(0))
コード例 #50
0
 def test_float_is_unchanged(self):
     query = schema.Float()
     assert_that(query.to_json_value(4.2), equal_to(4.2))
コード例 #51
0
def matches_when_there_are_extra_items():
    matcher = includes(equal_to("apple"))

    assert_equal(matched(), matcher.match(["coconut", "apple"]))
コード例 #52
0
 def test_int_is_unchanged(self):
     query = schema.Int()
     assert_that(query.to_json_value(42), equal_to(42))
コード例 #53
0
def matches_when_property_has_correct_value():
    assert_equal(matched(),
                 has_attr("username", equal_to("bob")).match(User("bob")))
コード例 #54
0
def description_includes_description_of_negated_matcher():
    assert_equal("not: 'hello'", not_(equal_to("hello")).describe())
コード例 #55
0
def description_contains_descriptions_of_submatchers():
    matcher = includes(equal_to("apple"), equal_to("banana"))

    assert_equal("iterable including elements:\n  * 'apple'\n  * 'banana'",
                 matcher.describe())
コード例 #56
0
def mismatches_when_property_is_missing():
    assert_equal(unmatched("was missing attribute username"),
                 has_attr("username", equal_to("bob")).match("bobbity"))
コード例 #57
0
def does_not_match_when_negated_matcher_matches():
    assert_equal(unmatched("matched: 1"), not_(equal_to(1)).match(1))
コード例 #58
0
def explanation_of_mismatch_contains_mismatch_of_property():
    assert_equal(unmatched("attribute username was 'bobbity'"),
                 has_attr("username", equal_to("bob")).match(User("bobbity")))
コード例 #59
0
def matches_when_negated_matcher_does_not_match():
    assert_equal(matched(), not_(equal_to(1)).match(2))
コード例 #60
0
def description_contains_description_of_property():
    assert_equal("object with attribute username: '******'",
                 has_attr("username", equal_to("bob")).describe())