Beispiel #1
0
 def testNoMatchIfArgumentFailsToSatisfyAnyOfManyOtherMatchers(self):
     self.assert_does_not_match(
         "all matchers",
         any_of(equal_to("bad"), equal_to("bad"), equal_to("bad"),
                equal_to("bad"), equal_to("bad")),
         "good",
     )
def step(context, state_name):
    current_Selection = context.rate_checker.get_location()
    # If the location tracker is not available then "Alabama" is set by default
    try:
        assert_that(current_Selection, equal_to('Alabama'))
    except:
        assert_that(current_Selection, equal_to(state_name))
Beispiel #3
0
 def testMatchesIfArgumentSatisfiesAnyOfManyOtherMatchers(self):
     self.assert_matches(
         "matcher in the middle",
         any_of(equal_to("bad"), equal_to("bad"), equal_to("good"),
                equal_to("bad"), equal_to("bad")),
         "good",
     )
def step(context, state_name):
    # Wait for the chart to load
    assert_that(context.rate_checker.is_chart_loaded(), equal_to(True))
    
    context.rate_checker.set_location(state_name)
    # Wait for the chart to load
    assert_that(context.rate_checker.is_chart_loaded(), equal_to(True))
Beispiel #5
0
    def test_validate_returns_error_for_invalid_type(self):
        url_field = UrlField(required=True)

        result = url_field.validate(None, 1212)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Expected type string'))
    def test_authentication_when_no_user(self):
        request = Request(user=None, request_params=None)

        response = default_authentication.authenticate(request)

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.AuthenticationFailed))
Beispiel #7
0
 def _assert_valid_default_entity(result,
                                  identifier="hbp/core/testschema/v0.0.1"):
     assert_that(result, instance_of(Schema))
     assert_that(result.data, not_none())
     assert_that(result.get_revision(), greater_than(0))
     assert_that(result.id, equal_to(identifier))
     assert_that(result.path, equal_to("/schemas/" + identifier))
def step(context, state_name):
    # Wait for the chart to load
    assert_that(context.rate_checker.is_chart_loaded(), equal_to("Chart is loaded"))

    context.rate_checker.set_location(state_name)
    # Wait for the chart to load
    assert_that(context.rate_checker.is_chart_loaded(), equal_to("Chart is loaded"))
Beispiel #9
0
 def testMismatchDescriptionOptionallyDescribesMultipleFailingMatches(self):
     self.assert_mismatch_description(
         "'bad' was 'indifferent' and 'good' was 'indifferent'",
         AllOf(equal_to('bad'),
               equal_to('indifferent'),
               equal_to('good'),
               describe_all_mismatches=True), 'indifferent')
Beispiel #10
0
    def test_stop_game_with_nogame_status(self):
        when(self.server_proxy_spy.move).then_return(("NoGame", 0))

        self.robot.start(max_moves=10)

        assert_that(self.robot.status, equal_to("NoGame"))
        assert_that(self.robot.total_moves, equal_to(1))
Beispiel #11
0
    def test_win_in_a_move(self):
        when(self.server_proxy_spy.move).then_return(("YouWin", 10))

        self.robot.start(max_moves=2)

        assert_that(self.robot.status, equal_to("YouWin"))
        assert_that(self.robot.total_moves, equal_to(1))
Beispiel #12
0
    def test_game_over_in_a_move(self):
        when(self.server_proxy_spy.move).then_return(("GameOver", 0))

        self.robot.start(max_moves=10)

        assert_that(self.robot.status, equal_to("GameOver"))
        assert_that(self.robot.total_moves, equal_to(1))
Beispiel #13
0
    def test_are_network_applications_equal_in_flow(self):
        assert_that(
            IsEqualToFlowComparisonLogic.
            are_network_applications_equal_in_flow(
                ["app1", "app2"],
                {"networkApplications": [{
                    "name": "app1"
                }, {
                    "name": "app2"
                }]}), is_(equal_to(True)))

        assert_that(
            IsEqualToFlowComparisonLogic.
            are_network_applications_equal_in_flow(
                ["app1", "app2", "app3"],
                {"networkApplications": [{
                    "name": "app1"
                }, {
                    "name": "app2"
                }]}), is_(equal_to(False)))

        # Test the case where the network applications are set to ANY on the server
        assert_that(
            IsEqualToFlowComparisonLogic.
            are_network_applications_equal_in_flow(
                [], {"networkApplications": [ANY_NETWORK_APPLICATION]}),
            is_(equal_to(True)))

        assert_that(
            IsEqualToFlowComparisonLogic.
            are_network_applications_equal_in_flow(
                ["app1"], {"networkApplications": [ANY_NETWORK_APPLICATION]}),
            is_(equal_to(False)))
Beispiel #14
0
    def test_validate_returns_error_if_max_length_exceeds(self):
        string_field = StringField(max_length=1, required=True)

        result = string_field.validate(None, '1212')

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Maxlength of 1 exceeded'))
Beispiel #15
0
    def test_authentication_when_no_user(self):
        request = Request(user=None, request_params=None)

        response = default_authentication.authenticate(request)

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.AuthenticationFailed))
Beispiel #16
0
 def testDelegatesMatchingToNestedMatcher(self):
     self.assert_matches('should match', is_(equal_to(True)), True)
     self.assert_matches('should match', is_(equal_to(False)), False)
     self.assert_does_not_match('should not match', is_(equal_to(True)),
                                False)
     self.assert_does_not_match('should not match', is_(equal_to(False)),
                                True)
Beispiel #17
0
    def test_validate_returns_error_if_required_and_value_is_default(self):
        url_field = UrlField(required=True)

        result = url_field.validate(None, DEFAULT_FIELD_VALUE)

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('This field is required'))
Beispiel #18
0
    def test_validate_returns_error_if_max_length_exceeds(self):
        string_field = StringField(max_length=1, required=True)

        result = string_field.validate(None, '1212')

        assert_that(result.is_success, equal_to(False))
        assert_that(result.reason, equal_to('Maxlength of 1 exceeded'))
Beispiel #19
0
    def test_rewrite_user_settings(self):
        product_csv_mtime = datetime.utcnow().replace(microsecond=0)
        expected_user_settings = \
            UserSettings(
                magento_store_url='http://localhost/magento/',
                product_csv_mtime=product_csv_mtime
            )
        self.__user_settings_service.put_current_user_settings(
            expected_user_settings)
        user_settings = self.__user_settings_service.get_current_user_settings(
        )
        assert_that(user_settings, equal_to(expected_user_settings))
        assert_that(user_settings.product_csv_mtime,
                    equal_to(product_csv_mtime))

        sleep(1.0)

        new_product_csv_mtime = datetime.utcnow().replace(microsecond=0)
        expected_user_settings = user_settings.replace(
            product_csv_mtime=new_product_csv_mtime)
        # UserSettings.Builder().update(user_settings).set_product_csv_mtime(datetime.utcnow().replace(microsecond=0)).build()
        self.__user_settings_service.put_current_user_settings(
            expected_user_settings)
        user_settings = self.__user_settings_service.get_current_user_settings(
        )
        assert_that(user_settings, equal_to(expected_user_settings))
        assert_that(user_settings.product_csv_mtime,
                    equal_to(new_product_csv_mtime))
Beispiel #20
0
    def test_are_network_users_equal_in_flow(self):
        assert_that(
            IsEqualToFlowComparisonLogic.are_network_users_equal_in_flow(
                ["user1", "user2"],
                {"networkUsers": [{
                    "name": "user1"
                }, {
                    "name": "user2"
                }]}), is_(equal_to(True)))

        assert_that(
            IsEqualToFlowComparisonLogic.are_network_users_equal_in_flow(
                ["user1", "UnknownUser"],
                {"networkUsers": [{
                    "name": "user1"
                }, {
                    "name": "user2"
                }]}), is_(equal_to(False)))

        # Test the case where the network users are set to ANY on the server
        assert_that(
            IsEqualToFlowComparisonLogic.are_network_users_equal_in_flow(
                ["user1"], {"networkUsers": [ANY_OBJECT]}),
            is_(equal_to(False)))

        assert_that(
            IsEqualToFlowComparisonLogic.are_network_users_equal_in_flow(
                [], {"networkUsers": [ANY_OBJECT]}), is_(equal_to(True)))
 def testMatchesDictionaryContainingSingleKeyWithMatchingValue(self):
     target = {'a': 1, 'b': 2}
     self.assert_matches('has a:1', has_entries('a', equal_to(1)), target)
     self.assert_matches('has b:2', has_entries('b', equal_to(2)), target)
     self.assert_does_not_match('no b:3', has_entries('b', equal_to(3)),
                                target)
     self.assert_does_not_match('no c:2', has_entries('c', equal_to(2)),
                                target)
Beispiel #22
0
 def testMatchesIfArgumentSatisfiesAnyOfManyOtherMatchers(self):
     self.assert_matches('matcher in the middle',
                         any_of(equal_to('bad'),
                                equal_to('bad'),
                                equal_to('good'),
                                equal_to('bad'),
                                equal_to('bad')),
                         'good')
Beispiel #23
0
 def testNoMatchIfArgumentFailsToSatisfyAnyOfManyOtherMatchers(self):
     self.assert_does_not_match('all matchers',
                                any_of(equal_to('bad'),
                                       equal_to('bad'),
                                       equal_to('bad'),
                                       equal_to('bad'),
                                       equal_to('bad')),
                               'good')
 def test_create_and_deprecate(self):
     random_name = "{}".format(uuid.uuid4()).replace("-", "")
     entity = Schema.create_new(self.default_prefix, "core", random_name, "v0.0.1", self.test_schema)
     result = self.repository.create(entity)
     assert_that(result, equal_to(entity))
     self._assert_valid_default_entity(result, self.default_prefix+"/core/"+random_name+"/v0.0.1")
     assert_that(result.get_revision(), equal_to(1))
     self._test_deprecate(entity)
Beispiel #25
0
    def test_with_equals_filter(self, mock_view):
        mock_view.return_value = {'name': 'foo'}
        request = request_factory.get_request(user=object(), request_params={'foo': 'bar'})
        response = DummyResource().read(request=request)

        assert_that(response.is_success, equal_to(True))
        assert_that(response.data, equal_to({'name': 'foo'}))
        mock_view.assert_called_once_with(request, **({'foo': 'bar'}))
 def test_create_and_deprecate(self):
     entity = Instance.create_new(self.default_prefix, "core", "schematest",
                                  "v0.0.1", self.test_instance)
     result = self.repository.create(entity)
     assert_that(result, equal_to(entity))
     self._assert_valid_default_entity(result, entity.id)
     assert_that(result.get_revision(), equal_to(1))
     self._test_deprecate(entity)
 def testMatchesDictionaryContainingSingleKeyWithMatchingValue(self):
     target = {"a": 1, "b": 2}
     self.assert_matches("has a:1", has_entries("a", equal_to(1)), target)
     self.assert_matches("has b:2", has_entries("b", equal_to(2)), target)
     self.assert_does_not_match("no b:3", has_entries("b", equal_to(3)),
                                target)
     self.assert_does_not_match("no c:2", has_entries("c", equal_to(2)),
                                target)
Beispiel #28
0
 def testMatchesIfArgumentSatisfiesAllOfManyOtherMatchers(self):
     self.assert_matches('all matchers',
                         all_of(equal_to('good'),
                                equal_to('good'),
                                equal_to('good'),
                                equal_to('good'),
                                equal_to('good')),
                         'good')
Beispiel #29
0
def step(context, state_name):
    # Get the location state displayed on page
    actual_text = context.rate_checker.get_chart_location()
    # If the location tracker is not available then "Alabama" is set by default
    try:
        assert_that(actual_text, equal_to('Alabama'))
    # Verify that displayed location matches the expected state
    except AssertionError:
        assert_that(actual_text, equal_to(state_name))
def step(context, state_name):
    # Get the location state displayed on page
    actual_text = context.rate_checker.get_chart_location()
    # If the location tracker is not available then "Alabama" is set by default
    try:
        assert_that(actual_text, equal_to("Alabama"))
    # Verify that displayed location matches the expected state
    except AssertionError:
        assert_that(actual_text, equal_to(state_name))
    def test_input_data_is_not_a_dict(self):
        data = 'stupid random data'
        request = request_factory.get_request(
            data=data,
            context_params={'crud_action': CrudActions.UPDATE_DETAIL})

        response = self.validation.validate_request_data(request)

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.InvalidData))
Beispiel #32
0
    def test_when_authentication_fails(self, mocked_authenticate):
        mocked_authenticate.return_value = Response(is_success=False,
                                                    reason=error_types.AuthenticationFailed,
                                                    data={'foo': 'bar'})

        response = DummyResource().read(request=request_factory.get_request(user=object()))

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.AuthenticationFailed))
        assert_that(response.data, equal_to({'foo': 'bar'}))
Beispiel #33
0
    def test_validate_returns_error_if_url_is_invalid(self):
        url_field = UrlField(required=True)

        result_1 = url_field.validate(None, 'hhhhh')
        result_2 = url_field.validate(None, 'gggg,gggg')

        assert_that(result_1.is_success, equal_to(False))
        assert_that(result_1.reason, equal_to('The url is not valid'))
        assert_that(result_2.is_success, equal_to(False))
        assert_that(result_2.reason, equal_to('The url is not valid'))
Beispiel #34
0
    def test_validate_returns_true_for_valid_url(self):
        url_field = UrlField(required=True)

        result_1 = url_field.validate(None, 'something.com')
        result_2 = url_field.validate(None, 'http://ffff.com')
        result_3 = url_field.validate(None, 'https://fsdfsdf.com')

        assert_that(result_1.is_success, equal_to(True))
        assert_that(result_2.is_success, equal_to(True))
        assert_that(result_3.is_success, equal_to(True))
Beispiel #35
0
 def test_create_and_deprecate(self):
     random_name = "{}".format(uuid.uuid4()).replace("-", "")
     entity = Domain.create_new(self.default_prefix, random_name,
                                "Test driven creation of a domain")
     result = self.repository.create(entity)
     assert_that(result, equal_to(entity))
     self._assert_valid_default_entity(
         result, self.default_prefix + "/" + random_name)
     assert_that(result.get_revision(), equal_to(1))
     self._test_deprecate(entity)
    def test_view_resource(self):
        url = 'dummy'
        user = DummyUser()

        http_request = MagicMock(user=user, method='GET')

        response = self.handler(http_request, url)

        assert_that(response.status_code, equal_to(200))
        assert_that(json.loads(response.content), equal_to({'name': 'dummy'}))
    def test_crud_resource_get_list(self):
        url = 'dummy'
        user = DummyUser()

        http_request = MagicMock(user=user, method='GET')

        response = self.handler(http_request, url)

        assert_that(response.status_code, equal_to(200))
        assert_that(json.loads(response.content), equal_to(
            {"objects": [{"name": "dummy"}], "meta": {"total": 1, "limit": 20, "offset": 0}}))
Beispiel #38
0
    def testHonorsArgumentEqImplementationEvenWithNone(self):
        class AlwaysEqual:
            def __eq__(self, obj):
                return True

        class NeverEqual:
            def __eq__(self, obj):
                return False

        self.assert_matches("always equal", equal_to(None), AlwaysEqual())
        self.assert_does_not_match("never equal", equal_to(None), NeverEqual())
Beispiel #39
0
 def testMatchesIfArgumentSatisfiesAllOfManyOtherMatchers(self):
     self.assert_matches(
         "all matchers",
         all_of(
             equal_to("good"),
             equal_to("good"),
             equal_to("good"),
             equal_to("good"),
             equal_to("good"),
         ),
         "good",
     )
    def test_raises_bad_request_if_required_data_is_missing(self):
        data = {}
        request = request_factory.get_request(
            data=data,
            context_params={'crud_action': CrudActions.CREATE_DETAIL})

        response = self.validation.validate_request_data(request)

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.InvalidData))
        assert_that(len(response.data), equal_to(2))
        assert_that(response.data, has_items('name', 'is_active'))
    def test_raises_bad_request_if_required_data_is_missing(self):
        data = {}
        request = request_factory.get_request(
            data=data,
            context_params={'crud_action': CrudActions.CREATE_DETAIL})

        response = self.validation.validate_request_data(request)

        assert_that(response.is_success, equal_to(False))
        assert_that(response.reason, equal_to(error_types.InvalidData))
        assert_that(len(response.data), equal_to(2))
        assert_that(response.data, has_items('name', 'is_active'))
 def test_raises_bad_request_if_field_greater_than_max_length(self):
     data = {
         'name': 'John Smith',
         'is_active': True,
         'country': 'United States'
     }
     request = request_factory.get_request(
         data=data,
         context_params={'crud_action': CrudActions.UPDATE_DETAIL})
     response = self.validation.validate_request_data(request)
     assert_that(response.is_success, equal_to(False))
     assert_that(response.reason, equal_to(error_types.InvalidData))
     assert_that(len(response.data), equal_to(2))
     assert_that(response.data, has_items('name', 'country'))
def test_cityLanguage_system():
    """
    Performs a full system test, invoking a local instance of the H2 database.

    Set environment variable CI=true in continuous integration to skip.
    """
    if os.environ.get('CI'):
        return

    result = H2WorldServiceHandler().cityLanguage('Melbourne')
    assert_that(result, equal_to('English (81.2%)'))

    result = H2WorldServiceHandler().cityLanguage('Kandy')
    assert_that(result, equal_to('Singali (60.3%)'))
 def test_raises_bad_request_if_field_greater_than_max_length(self):
     data = {
         'name': 'John Smith',
         'is_active': True,
         'country': 'United States'
     }
     request = request_factory.get_request(
         data=data,
         context_params={'crud_action': CrudActions.UPDATE_DETAIL})
     response = self.validation.validate_request_data(request)
     assert_that(response.is_success, equal_to(False))
     assert_that(response.reason, equal_to(error_types.InvalidData))
     assert_that(len(response.data), equal_to(2))
     assert_that(response.data, has_items('name', 'country'))
    def test_put_products(self):
        if self.__catalog_service is None or self.__read_only:
            return

        self.__put_products()
        products = self.__catalog_service.get_products()
        assert_that(products, equal_to(self.__products))
    def test_authentication_for_a_valid_user(self):
        user = MagicMock()
        request = Request(user=user, request_params=None)

        returned_request = default_authentication.authenticate(request)

        assert_that(returned_request, equal_to(request))
 def test_read_revision_one(self):
     uuid = self._get_instance_uuid()
     result = self.repository.read(self.default_prefix, "core",
                                   "schematest", "v0.0.1", uuid, 1)
     self._assert_valid_default_entity(result,
                                       "hbp/core/schematest/v0.0.1/" + uuid)
     assert_that(result.get_revision(), equal_to(1))
Beispiel #48
0
 def test_get_mail_campaign_content(self):
     for campaign in self.__put_mail_campaigns(write_through=False):
         expected_content = self.__put_mail_campaign_content(
             campaign, write_through=False)
         content = self.__mail_service.get_mail_campaign_content(
             campaign.id)
         assert_that(content, equal_to(expected_content))
Beispiel #49
0
    def test_dont_move_to_bad_cell_score(self):
        self.next_cell_calculator.cell_scores = {2: 8, 3: 10}
        self.next_cell_calculator.seek = 1
        self.next_cell_calculator.min_cell_score_to_move = 12
        self.next_cell_calculator.last_cell = Cell(1, 5)

        assert_that(self.next_cell_calculator.next(), equal_to(4))
Beispiel #50
0
    def test_set_live_reload_status(self):
        ctimain = CtiMain(live_reload_conf=0)
        self.add_me(ctimain)

        dao.set_live_reload_status({'enabled': True})

        assert_that(ctimain.live_reload_conf, equal_to(1))
Beispiel #51
0
    def test_handle_api_call(self,
                             mock_is_valid_resource,
                             mock_resolve_action,
                             mock_build_response,
                             mock_build_request,
                             mock_build_request_data):
        mock_is_valid_resource.return_value = True
        mock_resolve_action.return_value = expected_action = MagicMock()
        expected_action.return_value = expected_response = MagicMock()
        mock_build_request.return_value = expected_request = MagicMock()
        mock_build_response.return_value = expected_http_response = MagicMock()
        mock_build_request_data.return_value = expected_request_data = {}
        mock_http_request = MagicMock()
        mock_http_request.read.return_value = request_body = MagicMock()
        mock_api = MagicMock()
        url = 'test_endpoint'

        http_response = django_http_handler.handle_api_call(
            mock_http_request, url, mock_api)

        mock_is_valid_resource.assert_called_once_with('test_endpoint',
                                                       mock_api)
        mock_resolve_action.assert_called_once_with(mock_http_request,
                                                    'test_endpoint',
                                                    mock_api)
        mock_build_request.assert_called_once_with(
            http_request=mock_http_request,
            url=url, api=mock_api, request_data=expected_request_data,
            request_body=request_body)
        expected_action.assert_called_once_with(expected_request)
        assert_that(http_response, equal_to(expected_http_response))
        mock_build_response.assert_called_once_with(mock_http_request,
                                                    expected_response)
    def test_delete_product_by_sku(self):
        if self.__catalog_service is None or self.__read_only:
            return

        self.__put_products()

        products = self.__catalog_service.get_products()
        assert_that(products, equal_to(self.__products))

        products = tuple(self.__products)
        deleted_product = products[0]
        remaining_products = products[1:]
        self.__catalog_service.delete_product_by_sku(deleted_product.magento_product.sku)

        products = self.__catalog_service.get_products()
        assert_that(products, equal_to(frozenset(remaining_products)))
def step(context, total_years, selection):
    if selection == "First":
        actual_text = context.rate_checker.get_secondary_interest_rate(0, total_years)
    if selection == "Second":
        actual_text = context.rate_checker.get_secondary_interest_rate(1, total_years)

    assert_that(actual_text, equal_to(total_years))
Beispiel #54
0
    def test_set_live_reload_status(self):
        ctimain = CtiMain(live_reload_conf=0)
        self.add_me(ctimain)

        dao.set_live_reload_status({'enabled': True})

        assert_that(ctimain.live_reload_conf, equal_to(1))