本文整理汇总了Python中hamcrest.equal_to方法的典型用法代码示例。如果您正苦于以下问题:Python hamcrest.equal_to方法的具体用法?Python hamcrest.equal_to怎么用?Python hamcrest.equal_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hamcrest
的用法示例。
在下文中一共展示了hamcrest.equal_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shouldCreateAllMigrations
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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)))
示例2: test__shouldHandleUndefinedSecondWorkflowCase
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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())
示例3: validate_token_cookies
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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(''))
示例4: validate_response
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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'))
示例5: check_for_new_cookies
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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))
示例6: validate_response
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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))
示例7: validate_skill_setting_field_removed
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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']))
示例8: validate_response
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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))
示例9: validate_request_headers
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
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
示例10: test__shouldNotKeepRecreatingMigrationsWhenNoChange
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test__shouldNotKeepRecreatingMigrationsWhenNoChange(self):
call_command('makemigrations', 'tests')
self.migrations_before = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river_tests/')))
out = StringIO()
sys.stout = out
call_command('makemigrations', 'tests', stdout=out)
self.migrations_after = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river_tests/')))
assert_that(out.getvalue(), equal_to("No changes detected in app 'tests'\n"))
assert_that(self.migrations_after, has_length(len(self.migrations_before)))
示例11: test_shouldAllowAuthorizedUserToProceedToNextState
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test_shouldAllowAuthorizedUserToProceedToNextState(self):
authorized_permission = PermissionObjectFactory()
authorized_user = UserObjectFactory(user_permissions=[authorized_permission])
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
transition_meta = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state2,
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=0,
permissions=[authorized_permission]
)
workflow_object = BasicTestModelObjectFactory()
assert_that(workflow_object.model.my_field, equal_to(state1))
workflow_object.model.river.my_field.approve(as_user=authorized_user)
assert_that(workflow_object.model.my_field, equal_to(state2))
示例12: test_shouldNotTransitToNextStateWhenThereAreMultipleApprovalsToBeApproved
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test_shouldNotTransitToNextStateWhenThereAreMultipleApprovalsToBeApproved(self):
manager_permission = PermissionObjectFactory()
team_leader_permission = PermissionObjectFactory()
team_leader = UserObjectFactory(user_permissions=[team_leader_permission])
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
transition_meta = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state2,
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=1,
permissions=[manager_permission]
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=0,
permissions=[team_leader_permission]
)
workflow_object = BasicTestModelObjectFactory()
assert_that(workflow_object.model.my_field, equal_to(state1))
workflow_object.model.river.my_field.approve(team_leader)
assert_that(workflow_object.model.my_field, equal_to(state1))
示例13: test_shouldTransitToNextStateWhenAppTheApprovalsAreApprovedBeApproved
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test_shouldTransitToNextStateWhenAppTheApprovalsAreApprovedBeApproved(self):
manager_permission = PermissionObjectFactory()
team_leader_permission = PermissionObjectFactory()
manager = UserObjectFactory(user_permissions=[manager_permission])
team_leader = UserObjectFactory(user_permissions=[team_leader_permission])
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
transition_meta = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state2,
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=1,
permissions=[manager_permission]
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=0,
permissions=[team_leader_permission]
)
workflow_object = BasicTestModelObjectFactory()
assert_that(workflow_object.model.my_field, equal_to(state1))
workflow_object.model.river.my_field.approve(team_leader)
assert_that(workflow_object.model.my_field, equal_to(state1))
assert_that(workflow_object.model.my_field, equal_to(state1))
workflow_object.model.river.my_field.approve(manager)
assert_that(workflow_object.model.my_field, equal_to(state2))
示例14: test_shouldTransitToTheGivenNextStateWhenThereAreMultipleNextStates
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test_shouldTransitToTheGivenNextStateWhenThereAreMultipleNextStates(self):
authorized_permission = PermissionObjectFactory()
authorized_user = UserObjectFactory(user_permissions=[authorized_permission])
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
state3 = StateObjectFactory(label="state3")
workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
transition_meta_1 = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state2,
)
transition_meta_2 = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state3,
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta_1,
priority=0,
permissions=[authorized_permission]
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta_2,
priority=0,
permissions=[authorized_permission]
)
workflow_object = BasicTestModelObjectFactory()
assert_that(workflow_object.model.my_field, equal_to(state1))
workflow_object.model.river.my_field.approve(as_user=authorized_user, next_state=state3)
assert_that(workflow_object.model.my_field, equal_to(state3))
示例15: test_shouldNotCrashWhenAModelObjectWithStringPrimaryKeyIsApproved
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import equal_to [as 别名]
def test_shouldNotCrashWhenAModelObjectWithStringPrimaryKeyIsApproved(self):
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
content_type = ContentType.objects.get_for_model(ModelWithStringPrimaryKey)
authorized_permission = PermissionObjectFactory(content_type=content_type)
authorized_user = UserObjectFactory(user_permissions=[authorized_permission])
workflow = WorkflowFactory(initial_state=state1, content_type=content_type, field_name="status")
transition_meta = TransitionMetaFactory.create(
workflow=workflow,
source_state=state1,
destination_state=state2,
)
TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=0,
permissions=[authorized_permission]
)
workflow_object = ModelWithStringPrimaryKey.objects.create()
assert_that(workflow_object.status, equal_to(state1))
workflow_object.river.status.approve(as_user=authorized_user)
assert_that(workflow_object.status, equal_to(state2))