Python hamcrest.equal_to() Examples

The following are 30 code examples of hamcrest.equal_to(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module hamcrest , or try the search function .
Example #1
Source File: device_skill_settings.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_response(context):
    response = context.response.json
    assert_that(len(response), equal_to(2))
    foo_skill, foo_settings_display = context.skills['foo']
    foo_skill_expected_result = dict(
        uuid=foo_skill.id,
        skill_gid=foo_skill.skill_gid,
        identifier=foo_settings_display.display_data['identifier']
    )
    assert_that(foo_skill_expected_result, is_in(response))

    bar_skill, bar_settings_display = context.skills['bar']
    section = bar_settings_display.display_data['skillMetadata']['sections'][0]
    text_field = section['fields'][1]
    text_field['value'] = 'Device text value'
    checkbox_field = section['fields'][2]
    checkbox_field['value'] = 'false'
    bar_skill_expected_result = dict(
        uuid=bar_skill.id,
        skill_gid=bar_skill.skill_gid,
        identifier=bar_settings_display.display_data['identifier'],
        skillMetadata=bar_settings_display.display_data['skillMetadata']
    )
    assert_that(bar_skill_expected_result, is_in(response)) 
Example #2
Source File: authentication.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def check_for_new_cookies(context):
    validate_token_cookies(context)
    assert_that(
        context.refresh_token,
        is_not(equal_to(context.old_refresh_token))
    )
    refresh_token = AuthenticationToken(
        context.client_config['REFRESH_SECRET'],
        0
    )
    refresh_token.jwt = context.refresh_token
    refresh_token.validate()
    assert_that(refresh_token.is_valid, equal_to(True))
    assert_that(refresh_token.is_expired, equal_to(False))
    assert_that(
        refresh_token.account_id,
        equal_to(context.accounts['foo'].id)) 
Example #3
Source File: test__instance_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test__shouldHandleUndefinedSecondWorkflowCase(self):
        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")

        content_type = ContentType.objects.get_for_model(ModelWithTwoStateFields)
        workflow = WorkflowFactory(initial_state=state1, content_type=content_type, field_name="status1")

        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta,
            priority=0,
        )

        workflow_object = ModelWithTwoStateFieldsObjectFactory()

        assert_that(workflow_object.model.status1, equal_to(state1))
        assert_that(workflow_object.model.status2, none()) 
Example #4
Source File: api.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_token_cookies(context, expired=False):
    for cookie in context.response.headers.getlist('Set-Cookie'):
        ingredients = _parse_cookie(cookie)
        ingredient_names = list(ingredients.keys())
        if ACCESS_TOKEN_COOKIE_KEY in ingredient_names:
            context.access_token = ingredients[ACCESS_TOKEN_COOKIE_KEY]
        elif REFRESH_TOKEN_COOKIE_KEY in ingredient_names:
            context.refresh_token = ingredients[REFRESH_TOKEN_COOKIE_KEY]
        for ingredient_name in ('Domain', 'Expires', 'Max-Age'):
            assert_that(ingredient_names, has_item(ingredient_name))
        if expired:
            assert_that(ingredients['Max-Age'], equal_to('0'))

    assert hasattr(context, 'access_token'), 'no access token in response'
    assert hasattr(context, 'refresh_token'), 'no refresh token in response'
    if expired:
        assert_that(context.access_token, equal_to(''))
        assert_that(context.refresh_token, equal_to('')) 
Example #5
Source File: profile.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_response(context):
    response_data = context.response.json
    account = context.accounts['foo']
    assert_that(
        response_data['emailAddress'],
        equal_to(account.email_address)
    )
    assert_that(
        response_data['membership']['type'],
        equal_to('Monthly Membership')
    )
    assert_that(response_data['membership']['duration'], none())
    assert_that(
        response_data['membership'], has_item('id')
    )

    assert_that(len(response_data['agreements']), equal_to(3))
    agreement = response_data['agreements'][0]
    assert_that(agreement['type'], equal_to(PRIVACY_POLICY))
    assert_that(
        agreement['acceptDate'],
        equal_to(str(date.today().strftime('%B %d, %Y')))
    )
    assert_that(agreement, has_item('id')) 
Example #6
Source File: conftest.py    From data.world-py with Apache License 2.0 6 votes vote down vote up
def validate_request_headers(token='token', user_agent=None):
        from datadotworld import __version__
        expected_ua_header = user_agent or 'data.world-py - {}'.format(
            __version__)
        expected_auth_header = 'Bearer {}'.format(token)

        def wrap(f):
            def wrapper(request):
                headers = request.headers
                assert_that(headers, has_entries(
                    {'Authorization': equal_to(expected_auth_header),
                     'User-Agent': equal_to(expected_ua_header)}))
                return f(request)

            return wrapper

        return wrap 
Example #7
Source File: get_utterance.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_response(context):
    assert_that(context.response.status_code, equal_to(HTTPStatus.OK))
    response_data = json.loads(context.response.data)
    expected_response = ['tell me a joke']
    assert_that(response_data, equal_to(expected_response))

    resources_dir = os.path.join(os.path.dirname(__file__), 'resources')
    with open(os.path.join(resources_dir, 'test_stt.flac'), 'rb') as input_file:
        input_file_content = input_file.read()
    flac_file_path = _get_stt_result_file(context.account.id, '.flac')
    assert_that(flac_file_path, not_none())
    with open(flac_file_path, 'rb') as output_file:
        output_file_content = output_file.read()
    assert_that(input_file_content, equal_to(output_file_content))

    stt_file_path = _get_stt_result_file(context.account.id, '.stt')
    assert_that(stt_file_path, not_none())
    with open(stt_file_path, 'rb') as output_file:
        output_file_content = output_file.read()
    assert_that(b'tell me a joke', equal_to(output_file_content)) 
Example #8
Source File: device_skill_settings.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_skill_setting_field_removed(context):
    _get_device_skill_settings(context)
    assert_that(len(context.device_skill_settings), equal_to(2))
    # The removed field should no longer be in the settings values but the
    # value of the field that was not deleted should remain
    assert_that(
        dict(checkboxfield='false'),
        is_in(context.device_settings_values)
    )

    new_section = dict(fields=None)
    for device_skill_setting in context.device_skill_settings:
        skill_gid = device_skill_setting.settings_display['skill_gid']
        if skill_gid.startswith('bar'):
            new_settings_display = device_skill_setting.settings_display
            new_skill_definition = new_settings_display['skillMetadata']
            new_section = new_skill_definition['sections'][0]
    # The removed field should no longer be in the settings values but the
    # value of the field that was not deleted should remain
    assert_that(context.removed_field, not is_in(new_section['fields']))
    assert_that(context.remaining_field, is_in(new_section['fields'])) 
Example #9
Source File: test__migrations.py    From django-river with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_shouldCreateAllMigrations(self):
        for f in os.listdir("river/migrations"):
            if f != "__init__.py" and f != "__pycache__" and not f.endswith(".pyc"):
                open(os.path.join("river/tests/volatile/river/", f), 'wb').write(open(os.path.join("river/migrations", f), 'rb').read())

        self.migrations_before = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river/')))

        out = StringIO()
        sys.stout = out

        call_command('makemigrations', 'river', stdout=out)

        self.migrations_after = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river/')))

        assert_that(out.getvalue(), equal_to("No changes detected in app 'river'\n"))
        assert_that(self.migrations_after, has_length(len(self.migrations_before))) 
Example #10
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_cache_dir(self):
        config = InlineConfig('inline_token')
        assert_that(config.cache_dir,
                    equal_to(path.expanduser('~/.dw/cache'))) 
Example #11
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_tmp_dir(self):
        assert_that(DefaultConfig().tmp_dir,
                    equal_to(path.expanduser(tempfile.gettempdir()))) 
Example #12
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_auth_token(self):
        config = InlineConfig('inline_token')
        assert_that(config.auth_token, equal_to('inline_token')) 
Example #13
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_alternative_token(self, config_file_path):
        config = FileConfig(profile='alternative',
                            config_file_path=config_file_path)
        assert_that(config.auth_token, equal_to('alternativeabcd')) 
Example #14
Source File: test_util.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_parse_dataset_key():
    path_owner, path_id = util.parse_dataset_key('owner/dataset')
    assert_that(path_owner, equal_to('owner'))
    assert_that(path_id, equal_to('dataset')) 
Example #15
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_invalid_config_section(self, config_file_path):
        config = FileConfig(config_file_path=config_file_path)
        assert_that(config.auth_token, equal_to('lower_case_default'))
        assert_that(config._config_parser.sections(), has_length(0)) 
Example #16
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_save_overwrite(self, config_file_path):
        config = FileConfig(config_file_path=config_file_path)
        assert_that(config_file_path, is_not(equal_to('newtoken')))
        config.auth_token = 'newtoken'
        config.save()
        config_reloaded = FileConfig(config_file_path=config_file_path)
        assert_that(config_reloaded.auth_token, equal_to('newtoken')) 
Example #17
Source File: get_device_subscription.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_nonexistent_device(context):
    response = context.invalid_subscription_response
    assert_that(response.status_code, equal_to(HTTPStatus.UNAUTHORIZED)) 
Example #18
Source File: get_device.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_status_code(context):
    response = context.response_using_invalid_etag
    assert_that(response.status_code, equal_to(HTTPStatus.OK)) 
Example #19
Source File: get_device.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_etag(context):
    response = context.response_using_etag
    assert_that(response.status_code, equal_to(HTTPStatus.NOT_MODIFIED)) 
Example #20
Source File: get_device.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_update(context):
    response = context.update_device_response
    assert_that(response.status_code, equal_to(HTTPStatus.OK))

    response = context.get_device_response
    assert_that(response.status_code, equal_to(HTTPStatus.OK))
    device = json.loads(response.data)
    assert_that(device, has_key('name'))
    assert_that(device['coreVersion'], equal_to(new_fields['coreVersion']))
    assert_that(device['enclosureVersion'], equal_to(new_fields['enclosureVersion']))
    assert_that(device['platform'], equal_to(new_fields['platform'])) 
Example #21
Source File: get_device.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_response(context):
    response = context.get_device_response
    assert_that(response.status_code, equal_to(HTTPStatus.OK))
    device = json.loads(response.data)
    assert_that(device, has_key('uuid'))
    assert_that(device, has_key('name'))
    assert_that(device, has_key('description'))
    assert_that(device, has_key('coreVersion'))
    assert_that(device, has_key('enclosureVersion'))
    assert_that(device, has_key('platform'))
    assert_that(device, has_key('user'))
    assert_that(device['user'], has_key('uuid'))
    assert_that(device['user']['uuid'], equal_to(context.account.id)) 
Example #22
Source File: common.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def check_for_bad_request(context, error_type):
    if error_type == 'a bad request':
        assert_that(
            context.response.status_code,
            equal_to(HTTPStatus.BAD_REQUEST)
        )
    elif error_type == 'an unauthorized':
        assert_that(
            context.response.status_code,
            equal_to(HTTPStatus.UNAUTHORIZED)
        )
    else:
        raise ValueError('unsupported error_type') 
Example #23
Source File: common.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def check_request_success(context):
    assert_that(
        context.response.status_code,
        equal_to(HTTPStatus.NOT_MODIFIED)
    ) 
Example #24
Source File: common.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def check_device_last_contact(context):
    key = DEVICE_LAST_CONTACT_KEY.format(device_id=context.device_id)
    value = context.cache.get(key).decode()
    assert_that(value, not_none())

    last_contact_ts = datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f')
    assert_that(last_contact_ts.date(), equal_to(datetime.utcnow().date())) 
Example #25
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_auth_token(self, config_chain):
        assert_that(config_chain.auth_token, equal_to('file_token')) 
Example #26
Source File: device_skill_settings.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_updated_skill_setting_value(context):
    _get_device_skill_settings(context)
    assert_that(len(context.device_skill_settings), equal_to(3))
    expected_settings_values = dict(textfield='New skill text value')
    assert_that(
        expected_settings_values,
        is_in(context.device_settings_values)
    ) 
Example #27
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_cache_dir(self, config_chain):
        assert_that(config_chain.cache_dir, equal_to('env_cache_dir')) 
Example #28
Source File: device_skill_settings.py    From selene-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_updated_skill_setting_value(context):
    _get_device_skill_settings(context)
    assert_that(len(context.device_skill_settings), equal_to(2))
    expected_settings_values = dict(
        textfield='New device text value',
        checkboxfield='false'
    )
    assert_that(
        expected_settings_values,
        is_in(context.device_settings_values)
    ) 
Example #29
Source File: test_config.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_tmp_dir(self, config_chain):
        assert_that(config_chain.tmp_dir,
                    equal_to(path.expanduser(tempfile.gettempdir()))) 
Example #30
Source File: test_util.py    From data.world-py with Apache License 2.0 5 votes vote down vote up
def test_parse_dataset_key_with_url():
    url_owner, url_id = util.parse_dataset_key(
        'https://data.world/owner/dataset')
    assert_that(url_owner, equal_to('owner'))
    assert_that(url_id, equal_to('dataset'))