def test_capture_stdout(allured_testdir, capture):
    """
    >>> import pytest
    >>> import allure

    >>> @pytest.fixture
    ... def fixture(request):
    ...     print ("Start fixture")
    ...     def finalizer():
    ...         print ("Stop fixture")
    ...     request.addfinalizer(finalizer)

    >>> def test_capture_stdout_example(fixture):
    ...     print ("Start test")
    ...     with allure.step("Step"):
    ...         print ("Start step")
    """

    allured_testdir.parse_docstring_source()
    allured_testdir.run_with_allure("--capture={capture}".format(capture=capture))

    if_pytest_capture_ = is_not if capture == "no" else is_

    assert_that(allured_testdir.allure_report,
                has_property("attachments",
                             all_of(
                                 if_pytest_capture_(has_value(contains_string("Start fixture"))),
                                 if_pytest_capture_(has_value(contains_string("Stop fixture"))),
                                 if_pytest_capture_(has_value(contains_string("Start test"))),
                                 if_pytest_capture_(has_value(contains_string("Start step")))
                             )
                             )
                )
    def test_shouldRemoveTheHookingAndCallbackFromDBWhenWorkflowObjectIsDeleted(
            self):
        workflow_object = BasicTestModelObjectFactory().model

        hooking_hash = '%s.%s_object%s_field_name%s' % (
            PostTransitionHooking.__module__, PostTransitionHooking.__name__,
            workflow_object.pk, self.field_name)

        assert_that(self.handler_backend.callbacks,
                    is_not(has_key(hooking_hash)))
        assert_that(
            self.handler_backend.callbacks,
            is_not(has_value(has_property("__name__",
                                          test_callback.__name__))))

        self.handler_backend.register(PostTransitionHooking, test_callback,
                                      workflow_object, self.field_name)

        assert_that(self.handler_backend.callbacks, has_key(hooking_hash))
        assert_that(
            self.handler_backend.callbacks,
            has_value(has_property("__name__", test_callback.__name__)))
        assert_that(Callback.objects.filter(hash=hooking_hash), has_length(1))

        workflow_object.delete()

        assert_that(self.handler_backend.callbacks,
                    is_not(has_key(hooking_hash)))
        assert_that(
            self.handler_backend.callbacks,
            is_not(has_value(has_property("__name__",
                                          test_callback.__name__))))

        assert_that(Callback.objects.filter(hash=hooking_hash), has_length(0))
Example #3
0
def test_capture_stdout(allured_testdir, capture):
    """
    >>> import pytest
    >>> import allure

    >>> @pytest.fixture
    ... def fixture(request):
    ...     print ("Start fixture")
    ...     def finalizer():
    ...         print ("Stop fixture")
    ...     request.addfinalizer(finalizer)

    >>> def test_capture_stdout_example(fixture):
    ...     print ("Start test")
    ...     with allure.step("Step"):
    ...         print ("Start step")
    """

    allured_testdir.parse_docstring_source()
    allured_testdir.run_with_allure(
        "--capture={capture}".format(capture=capture))

    if_pytest_capture_ = is_not if capture == "no" else is_

    assert_that(
        allured_testdir.allure_report,
        has_property(
            "attachments",
            all_of(
                if_pytest_capture_(has_value(
                    contains_string("Start fixture"))),
                if_pytest_capture_(has_value(contains_string("Stop fixture"))),
                if_pytest_capture_(has_value(contains_string("Start test"))),
                if_pytest_capture_(has_value(contains_string("Start step"))))))
    def test_shouldUnregisterAHooking(self):
        workflow_objects = BasicTestModelObjectFactory.create_batch(2)

        hooking_hash = '%s.%s_object%s_field_name%s' % (
            PostTransitionHooking.__module__, PostTransitionHooking.__name__,
            workflow_objects[1].pk, self.field_name)

        assert_that(self.handler_backend.callbacks,
                    is_not(has_key(hooking_hash)))

        self.handler_backend.register(PostTransitionHooking, test_callback,
                                      workflow_objects[1], self.field_name)

        assert_that(self.handler_backend.callbacks, has_key(hooking_hash))
        assert_that(
            self.handler_backend.callbacks,
            has_value(has_property("__name__", test_callback.__name__)))

        self.handler_backend.unregister(PostTransitionHooking,
                                        workflow_objects[1], self.field_name)

        assert_that(self.handler_backend.callbacks,
                    is_not(has_key(hooking_hash)))
        assert_that(
            self.handler_backend.callbacks,
            is_not(has_value(has_property("__name__",
                                          test_callback.__name__))))
def check_packets_on_iface(os_faults_steps,
                           node,
                           iface,
                           filters,
                           should_be=True):
    with calc_packets_count(os_faults_steps, node, iface,
                            filters) as tcp_counts:
        time.sleep(1)
    if should_be:
        matcher = greater_than(0)
    else:
        matcher = is_(0)
    assert_that(tcp_counts, has_value(matcher), 'Wrong packets count')
def test_capture_log(allured_testdir, logging):
    """
    >>> import logging
    >>> import pytest
    >>> import allure

    >>> logger = logging.getLogger(__name__)

    >>> @pytest.fixture
    ... def fixture(request):
    ...     logger.info("Start fixture")
    ...     def finalizer():
    ...         logger.info("Stop fixture")
    ...     request.addfinalizer(finalizer)

    >>> def test_capture_log_example(fixture):
    ...     logger.info("Start test")
    ...     with allure.step("Step"):
    ...         logger.info("Start step")
    """

    allured_testdir.parse_docstring_source()

    params = [] if logging else ["-p", "no:logging"]
    if_logging_ = is_ if logging else is_not

    allured_testdir.run_with_allure("--log-cli-level=INFO", *params)

    assert_that(allured_testdir.allure_report,
                has_property("attachments",
                             all_of(
                                 if_logging_(has_value(contains_string("Start fixture"))),
                                 if_logging_(has_value(contains_string("Stop fixture"))),
                                 if_logging_(has_value(contains_string("Start test"))),
                                 if_logging_(has_value(contains_string("Start step")))
                             )
                             )
                )
Example #7
0
def test_capture_log(allured_testdir, logging):
    """
    >>> import logging
    >>> import pytest
    >>> import allure

    >>> logger = logging.getLogger(__name__)

    >>> @pytest.fixture
    ... def fixture(request):
    ...     logger.info("Start fixture")
    ...     def finalizer():
    ...         logger.info("Stop fixture")
    ...     request.addfinalizer(finalizer)

    >>> def test_capture_log_example(fixture):
    ...     logger.info("Start test")
    ...     with allure.step("Step"):
    ...         logger.info("Start step")
    """

    allured_testdir.parse_docstring_source()

    params = [] if logging else ["-p", "no:logging"]
    if_logging_ = is_ if logging else is_not

    allured_testdir.run_with_allure("--log-cli-level=INFO", *params)

    assert_that(
        allured_testdir.allure_report,
        has_property(
            "attachments",
            all_of(if_logging_(has_value(contains_string("Start fixture"))),
                   if_logging_(has_value(contains_string("Stop fixture"))),
                   if_logging_(has_value(contains_string("Start test"))),
                   if_logging_(has_value(contains_string("Start step"))))))
def test_parametrized_attachment(executed_docstring_source, param):
    """
    >>> import pytest
    >>> import allure

    >>> @pytest.mark.parametrize("param", ["first", "second"])
    ... def test_parametrized_attachment_example(param):
    ...     allure.attach(param)
    """

    assert_that(executed_docstring_source.allure_report,
                all_of(
                    has_test_case("test_parametrized_attachment_example[{param}]".format(param=param)),
                    has_property("attachments",
                                 has_value(contains_string(param))
                                 )
                ))
Example #9
0
def test_parametrized_attachment(executed_docstring_source, param):
    """
    >>> import pytest
    >>> import allure

    >>> @pytest.mark.parametrize("param", ["first", "second"])
    ... def test_parametrized_attachment_example(param):
    ...     allure.attach(param)
    """

    assert_that(
        executed_docstring_source.allure_report,
        all_of(
            has_test_case(
                "test_parametrized_attachment_example[{param}]".format(
                    param=param)),
            has_property("attachments", has_value(contains_string(param)))))
Example #10
0
    def test_that_tenant_with_invalid_domain_names_returns_400(
            self, TenantDetector):
        TenantDetector.autodetect.return_value = Mock(uuid=s.tenant_uuid)

        invalid_datas = [
            ('domain_names', {
                'domain_names': ['-wazo.io']
            }),
            ('domain_names', {
                'domain_names': [' wazo.io']
            }),
            ('domain_names', {
                'domain_names': ['#']
            }),
            ('domain_names', {
                'domain_names': ['123']
            }),
            ('domain_names', {
                'domain_names': ['wazo .io']
            }),
            ('domain_names', {
                'domain_names': ['wazo.io-']
            }),
            ('domain_names', {
                'domain_names': ['wazo']
            }),
            ('domain_names', {
                'domain_names': ['=wazo.io']
            }),
            ('domain_names', {
                'domain_names': ['+wazo.io']
            }),
            ('domain_names', {
                'domain_names': ['_wazo.io']
            }),
            ('domain_names', {
                'domain_names': ['wazo_io']
            }),
            ('domain_names', {
                'domain_names': ['wazo_io  ']
            }),
            ('domain_names', {
                'domain_names': ['']
            }),
        ]

        for field, invalid_data in invalid_datas:
            result = self.post(invalid_data)
            assert_that(result.status_code, equal_to(400), invalid_data)
            assert_that(
                result.json,
                has_entries(
                    error_id='invalid-data',
                    message=ANY,
                    resource='tenants',
                    details=has_entries(
                        field,
                        has_value(
                            has_entries(
                                constraint_id='regex',
                                constraint=ANY,
                                message=
                                'String does not match expected pattern.',
                            ), ),
                    ),
                ),
                invalid_data,
            )

        invalid_data = {'domain_names': [None]}
        result = self.post(invalid_data)
        assert_that(result.status_code, equal_to(400), invalid_data)
        assert_that(
            result.json,
            has_entries(
                error_id='invalid-data',
                resource='tenants',
                details=has_entries(domain_names=has_value(
                    has_entries(constraint_id='not_null')), ),
            ),
            invalid_data,
        )

        invalid_domains_types = [
            ('domain_names', {
                'domain_names': None
            }),
            ('domain_names', {
                'domain_names': True
            }),
            ('domain_names', {
                'domain_names': False
            }),
            ('domain_names', {
                'domain_names': 'wazo.community'
            }),
            ('domain_names', {
                'domain_names': 42
            }),
            ('domain_names', {
                'domain_names': {
                    'name': 'wazo.community'
                }
            }),
        ]

        for field, invalid_data in invalid_domains_types:
            result = self.post(invalid_data)
            assert_that(result.status_code, equal_to(400), invalid_data)
            assert_that(
                result.json,
                has_entries(
                    error_id='invalid-data',
                    message=ANY,
                    resource='tenants',
                    details=has_entries(
                        field,
                        has_entries(constraint_id=ANY, message=ANY),
                    ),
                ),
                invalid_data,
            )