Python testtools.matchers.Equals() Examples
The following are 30
code examples of testtools.matchers.Equals().
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
testtools.matchers
, or try the search function
.
Example #1
Source File: test_project.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_create_project_v3(self,): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) reference_req = project_data.json_request.copy() reference_req['project']['enabled'] = True self.register_uris([ dict(method='POST', uri=self.get_mock_url(), status_code=200, json=project_data.json_response, validate=dict(json=reference_req)) ]) project = self.cloud.create_project( name=project_data.project_name, description=project_data.description, domain_id=project_data.domain_id) self.assertThat(project.id, matchers.Equals(project_data.project_id)) self.assertThat( project.name, matchers.Equals(project_data.project_name)) self.assertThat( project.description, matchers.Equals(project_data.description)) self.assertThat( project.domain_id, matchers.Equals(project_data.domain_id)) self.assert_calls()
Example #2
Source File: test_services.py From shade with Apache License 2.0 | 6 votes |
def test_create_service_v3(self): service_data = self._get_service_data(name='a service', type='network', description='A test service') self.register_uris([ dict(method='POST', uri=self.get_mock_url(), status_code=200, json=service_data.json_response_v3, validate=dict(json={'service': service_data.json_request})) ]) service = self.op_cloud.create_service( name=service_data.service_name, service_type=service_data.service_type, description=service_data.description) self.assertThat(service.name, matchers.Equals(service_data.service_name)) self.assertThat(service.id, matchers.Equals(service_data.service_id)) self.assertThat(service.description, matchers.Equals(service_data.description)) self.assertThat(service.type, matchers.Equals(service_data.service_type)) self.assert_calls()
Example #3
Source File: test_domains.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_update_domain_name_or_id(self): domain_data = self._get_domain_data( description=self.getUniqueString('domainDesc')) domain_resource_uri = self.get_mock_url(append=[domain_data.domain_id]) self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'domains': [domain_data.json_response['domain']]}), dict(method='PATCH', uri=domain_resource_uri, status_code=200, json=domain_data.json_response, validate=dict(json=domain_data.json_request))]) domain = self.cloud.update_domain( name_or_id=domain_data.domain_id, name=domain_data.domain_name, description=domain_data.description) self.assertThat(domain.id, matchers.Equals(domain_data.domain_id)) self.assertThat(domain.name, matchers.Equals(domain_data.domain_name)) self.assertThat( domain.description, matchers.Equals(domain_data.description)) self.assert_calls()
Example #4
Source File: test_services.py From shade with Apache License 2.0 | 6 votes |
def test_list_services(self): service_data = self._get_service_data() self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'services': [service_data.json_response_v3['service']]}) ]) services = self.op_cloud.list_services() self.assertThat(len(services), matchers.Equals(1)) self.assertThat(services[0].id, matchers.Equals(service_data.service_id)) self.assertThat(services[0].name, matchers.Equals(service_data.service_name)) self.assertThat(services[0].type, matchers.Equals(service_data.service_type)) self.assert_calls()
Example #5
Source File: test_diffing.py From flocker with Apache License 2.0 | 6 votes |
def test_straight_swap(self): """ A diff composed of two separate ``set`` operations can be applied to an object without triggering an invariant exception. """ o1 = DiffTestObjInvariant( a=1, b=2, ) o2 = DiffTestObjInvariant( a=2, b=1, ) diff = create_diff(o1, o2) self.expectThat(len(diff.changes), Equals(2)) self.assertEqual( o2, diff.apply(o1) )
Example #6
Source File: test_domains.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_update_domain(self): domain_data = self._get_domain_data( description=self.getUniqueString('domainDesc')) domain_resource_uri = self.get_mock_url(append=[domain_data.domain_id]) self.register_uris([ dict(method='PATCH', uri=domain_resource_uri, status_code=200, json=domain_data.json_response, validate=dict(json=domain_data.json_request))]) domain = self.cloud.update_domain( domain_data.domain_id, name=domain_data.domain_name, description=domain_data.description) self.assertThat(domain.id, matchers.Equals(domain_data.domain_id)) self.assertThat(domain.name, matchers.Equals(domain_data.domain_name)) self.assertThat( domain.description, matchers.Equals(domain_data.description)) self.assert_calls()
Example #7
Source File: test_diffing.py From flocker with Apache License 2.0 | 6 votes |
def test_equal_objects(self): """ Diffing objects that are equal results in an object that is smaller than the object. """ baseobj = frozenset(xrange(1000)) object_a = DiffTestObj(a=baseobj) object_b = DiffTestObj(a=baseobj) diff = create_diff(object_a, object_b) serialized_diff = wire_encode(diff) self.assertThat( len(serialized_diff), LessThan(len(dumps(list(baseobj)))) ) self.assertThat( wire_decode(serialized_diff).apply(object_a), Equals(object_b) )
Example #8
Source File: test_services.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_list_services(self): service_data = self._get_service_data() self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'services': [service_data.json_response_v3['service']]}) ]) services = self.cloud.list_services() self.assertThat(len(services), matchers.Equals(1)) self.assertThat(services[0].id, matchers.Equals(service_data.service_id)) self.assertThat(services[0].name, matchers.Equals(service_data.service_name)) self.assertThat(services[0].type, matchers.Equals(service_data.service_type)) self.assert_calls()
Example #9
Source File: test_api_common.py From tacker with Apache License 2.0 | 6 votes |
def test_prepare_request_body(self): body = { 'fake': { 'name': 'terminator', 'model': 'T-800', } } params = [ {'param-name': 'name', 'required': True}, {'param-name': 'model', 'required': True}, {'param-name': 'quote', 'required': False, 'default-value': "i'll be back"}, ] expect = { 'fake': { 'name': 'terminator', 'model': 'T-800', 'quote': "i'll be back", } } actual = self.controller._prepare_request_body(body, params) self.assertThat(expect, matchers.Equals(actual))
Example #10
Source File: test_diffing.py From flocker with Apache License 2.0 | 6 votes |
def test_deployment_diffing_composable(self, deployments): """ Diffs should compose to create an aggregate diff. Create a bunch of deployments and compute the incremental diffs from one to the next. Compose all diffs together and apply the resulting diff to the first deployment. Verify that the final deployment is the result. """ reserialize = lambda x: wire_decode(wire_encode(x)) deployment_diffs = list( reserialize(create_diff(a, b)) for a, b in zip(deployments[:-1], deployments[1:]) ) full_diff = reserialize(compose_diffs(deployment_diffs)) self.assertThat( full_diff.apply(deployments[0]), Equals(deployments[-1]) )
Example #11
Source File: test_identity_roles.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_update_role(self): role_data = self._get_role_data() req = {'role_id': role_data.role_id, 'role': {'name': role_data.role_name}} self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'roles': [role_data.json_response['role']]}), dict(method='PATCH', uri=self.get_mock_url(), status_code=200, json=role_data.json_response, validate=dict(json=req)) ]) role = self.cloud.update_role( role_data.role_id, role_data.role_name) self.assertIsNotNone(role) self.assertThat(role.name, matchers.Equals(role_data.role_name)) self.assertThat(role.id, matchers.Equals(role_data.role_id)) self.assert_calls()
Example #12
Source File: test_identity_roles.py From shade with Apache License 2.0 | 6 votes |
def test_update_role(self): role_data = self._get_role_data() req = {'role_id': role_data.role_id, 'role': {'name': role_data.role_name}} self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'roles': [role_data.json_response['role']]}), dict(method='PATCH', uri=self.get_mock_url(), status_code=200, json=role_data.json_response, validate=dict(json=req)) ]) role = self.op_cloud.update_role(role_data.role_id, role_data.role_name) self.assertIsNotNone(role) self.assertThat(role.name, matchers.Equals(role_data.role_name)) self.assertThat(role.id, matchers.Equals(role_data.role_id)) self.assert_calls()
Example #13
Source File: test_persistence.py From flocker with Apache License 2.0 | 6 votes |
def test_consistent_hash(self): """ A given deployment hashes to a specific value. """ # Unfortunately these are manually created golden values generated by # running the test with wrong values and copying the output into this # file. This test mostly adds value in verifying that the hashes # computed in all of our CI environments are the same. TEST_DEPLOYMENT_1_HASH = ''.join(chr(x) for x in [ 0x87, 0x13, 0xcb, 0x47, 0x60, 0xd7, 0xab, 0x0f, 0x30, 0xd5, 0xd2, 0x78, 0xe8, 0x12, 0x5d, 0x11 ]) TEST_DEPLOYMENT_2_HASH = ''.join(chr(x) for x in [ 0x5f, 0xc0, 0x2b, 0x4c, 0x57, 0x75, 0x35, 0xff, 0x6d, 0x1f, 0xd2, 0xc0, 0x14, 0xcf, 0x45, 0x32 ]) self.assertThat( generation_hash(TEST_DEPLOYMENT_1), Equals(TEST_DEPLOYMENT_1_HASH) ) self.assertThat( generation_hash(TEST_DEPLOYMENT_2), Equals(TEST_DEPLOYMENT_2_HASH) )
Example #14
Source File: test_project.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_list_projects_search_compat_v3(self): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) self.register_uris([ dict(method='GET', uri=self.get_mock_url( resource=('projects?domain_id=%s' % project_data.domain_id)), status_code=200, json={'projects': [project_data.json_response['project']]}) ]) projects = self.cloud.search_projects( domain_id=project_data.domain_id) self.assertThat(len(projects), matchers.Equals(1)) self.assertThat( projects[0].id, matchers.Equals(project_data.project_id)) self.assert_calls()
Example #15
Source File: test_services.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_create_service_v3(self): service_data = self._get_service_data(name='a service', type='network', description='A test service') self.register_uris([ dict(method='POST', uri=self.get_mock_url(), status_code=200, json=service_data.json_response_v3, validate=dict(json={'service': service_data.json_request})) ]) service = self.cloud.create_service( name=service_data.service_name, service_type=service_data.service_type, description=service_data.description) self.assertThat(service.name, matchers.Equals(service_data.service_name)) self.assertThat(service.id, matchers.Equals(service_data.service_id)) self.assertThat(service.description, matchers.Equals(service_data.description)) self.assertThat(service.type, matchers.Equals(service_data.service_type)) self.assert_calls()
Example #16
Source File: test_project.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_list_projects_v3_kwarg(self): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) self.register_uris([ dict(method='GET', uri=self.get_mock_url( resource=('projects?domain_id=%s' % project_data.domain_id)), status_code=200, json={'projects': [project_data.json_response['project']]}) ]) projects = self.cloud.list_projects( domain_id=project_data.domain_id) self.assertThat(len(projects), matchers.Equals(1)) self.assertThat( projects[0].id, matchers.Equals(project_data.project_id)) self.assert_calls()
Example #17
Source File: test_release.py From flocker with Apache License 2.0 | 6 votes |
def test_run(self): """ The script creates a new release version branch in a new working directory and prints some shell commands to ``stdout``. """ expected_version = "9.9.9" script_path = self.make_temporary_directory() repo_path = script_path.sibling( 'flocker-release-{}'.format(expected_version) ) result = run_process( [INITIALIZE_RELEASE_PATH.path, '--flocker-version={}'.format(expected_version)], cwd=script_path.path ) self.expectThat(result.status, Equals(0)) self.expectThat( result.output, Contains('export VERSION={}'.format(expected_version)) ) self.expectThat( Repo(path=repo_path.path).active_branch.name, Equals('release/flocker-{}'.format(expected_version)) )
Example #18
Source File: test_project.py From shade with Apache License 2.0 | 6 votes |
def test_create_project_v3(self,): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) reference_req = project_data.json_request.copy() reference_req['project']['enabled'] = True self.register_uris([ dict(method='POST', uri=self.get_mock_url(), status_code=200, json=project_data.json_response, validate=dict(json=reference_req)) ]) project = self.op_cloud.create_project( name=project_data.project_name, description=project_data.description, domain_id=project_data.domain_id) self.assertThat(project.id, matchers.Equals(project_data.project_id)) self.assertThat( project.name, matchers.Equals(project_data.project_name)) self.assertThat( project.description, matchers.Equals(project_data.description)) self.assertThat( project.domain_id, matchers.Equals(project_data.domain_id)) self.assert_calls()
Example #19
Source File: test_content_type.py From pth-toolkit with BSD 2-Clause "Simplified" License | 5 votes |
def test_extended_repr(self): content_type = ContentType( 'text', 'plain', {'foo': 'bar', 'baz': 'qux'}) self.assertThat( repr(content_type), Equals('text/plain; foo="bar", baz="qux"'))
Example #20
Source File: test_identity_roles.py From shade with Apache License 2.0 | 5 votes |
def test_delete_role_by_name(self): role_data = self._get_role_data() self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'roles': [role_data.json_response['role']]}), dict(method='DELETE', uri=self.get_mock_url(append=[role_data.role_id]), status_code=204) ]) role = self.op_cloud.delete_role(role_data.role_name) self.assertThat(role, matchers.Equals(True)) self.assert_calls()
Example #21
Source File: test_services.py From shade with Apache License 2.0 | 5 votes |
def test_create_service_v2(self): self.use_keystone_v2() service_data = self._get_service_data(name='a service', type='network', description='A test service') reference_req = service_data.json_request.copy() reference_req.pop('enabled') self.register_uris([ dict(method='POST', uri=self.get_mock_url(base_url_append='OS-KSADM'), status_code=200, json=service_data.json_response_v2, validate=dict(json={'OS-KSADM:service': reference_req})) ]) service = self.op_cloud.create_service( name=service_data.service_name, service_type=service_data.service_type, description=service_data.description) self.assertThat(service.name, matchers.Equals(service_data.service_name)) self.assertThat(service.id, matchers.Equals(service_data.service_id)) self.assertThat(service.description, matchers.Equals(service_data.description)) self.assertThat(service.type, matchers.Equals(service_data.service_type)) self.assert_calls()
Example #22
Source File: test_identity_roles.py From shade with Apache License 2.0 | 5 votes |
def test_list_role_assignments(self): domain_data = self._get_domain_data() user_data = self._get_user_data(domain_id=domain_data.domain_id) group_data = self._get_group_data(domain_id=domain_data.domain_id) project_data = self._get_project_data(domain_id=domain_data.domain_id) role_data = self._get_role_data() response = [ {'links': 'https://example.com', 'role': {'id': role_data.role_id}, 'scope': {'domain': {'id': domain_data.domain_id}}, 'user': {'id': user_data.user_id}}, {'links': 'https://example.com', 'role': {'id': role_data.role_id}, 'scope': {'project': {'id': project_data.project_id}}, 'group': {'id': group_data.group_id}}, ] self.register_uris([ dict(method='GET', uri=self.get_mock_url( resource='role_assignments'), status_code=200, json={'role_assignments': response}, complete_qs=True) ]) ret = self.op_cloud.list_role_assignments() self.assertThat(len(ret), matchers.Equals(2)) self.assertThat(ret[0].user, matchers.Equals(user_data.user_id)) self.assertThat(ret[0].id, matchers.Equals(role_data.role_id)) self.assertThat(ret[0].domain, matchers.Equals(domain_data.domain_id)) self.assertThat(ret[1].group, matchers.Equals(group_data.group_id)) self.assertThat(ret[1].id, matchers.Equals(role_data.role_id)) self.assertThat(ret[1].project, matchers.Equals(project_data.project_id))
Example #23
Source File: test_content_type.py From pth-toolkit with BSD 2-Clause "Simplified" License | 5 votes |
def test_basic_repr(self): content_type = ContentType('text', 'plain') self.assertThat(repr(content_type), Equals('text/plain'))
Example #24
Source File: test_builtin_workflows.py From cloudify-plugins-common with Apache License 2.0 | 5 votes |
def _dep_order_tests_helper(self, cfy_local, node_ids_param, ordered_node_ids_of_instances, indices_pairs_for_time_diff_assertions): params = self._get_params( op='cloudify.interfaces.lifecycle.start', node_ids=node_ids_param, run_by_dep=True) cfy_local.execute('execute_operation', params, task_thread_pool_size=4) instances_and_visit_times = sorted( ((inst, inst.runtime_properties['visit_time']) for inst in cfy_local.storage.get_node_instances() if 'visit_time' in inst.runtime_properties), key=lambda inst_and_time: inst_and_time[1]) self.assertEqual(ordered_node_ids_of_instances, [inst_and_time[0].node_id for inst_and_time in instances_and_visit_times]) # asserting time difference between the operation execution for the # different nodes. this way if something breaks and the tasks aren't # dependent on one another, there's a better chance we'll catch # it, since even if the order of the visits happens to be correct, # it's less likely there'll be a significant time difference between # the visits def assert_time_difference(earlier_inst_index, later_inst_index): td = instances_and_visit_times[later_inst_index][1] - \ instances_and_visit_times[earlier_inst_index][1] self.assertThat(td, MatchesAny(Equals(1), GreaterThan(1))) for index1, index2 in indices_pairs_for_time_diff_assertions: assert_time_difference(index1, index2)
Example #25
Source File: test_domains.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_create_domain(self): domain_data = self._get_domain_data(description=uuid.uuid4().hex, enabled=True) self.register_uris([ dict(method='POST', uri=self.get_mock_url(), status_code=200, json=domain_data.json_response, validate=dict(json=domain_data.json_request))]) domain = self.cloud.create_domain( domain_data.domain_name, domain_data.description) self.assertThat(domain.id, matchers.Equals(domain_data.domain_id)) self.assertThat(domain.name, matchers.Equals(domain_data.domain_name)) self.assertThat( domain.description, matchers.Equals(domain_data.description)) self.assert_calls()
Example #26
Source File: test_domains.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_get_domain(self): domain_data = self._get_domain_data() self.register_uris([ dict(method='GET', uri=self.get_mock_url(append=[domain_data.domain_id]), status_code=200, json=domain_data.json_response)]) domain = self.cloud.get_domain(domain_id=domain_data.domain_id) self.assertThat(domain.id, matchers.Equals(domain_data.domain_id)) self.assertThat(domain.name, matchers.Equals(domain_data.domain_name)) self.assert_calls()
Example #27
Source File: test_domains.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_list_domains(self): domain_data = self._get_domain_data() self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'domains': [domain_data.json_response['domain']]})]) domains = self.cloud.list_domains() self.assertThat(len(domains), matchers.Equals(1)) self.assertThat(domains[0].name, matchers.Equals(domain_data.domain_name)) self.assertThat(domains[0].id, matchers.Equals(domain_data.domain_id)) self.assert_calls()
Example #28
Source File: test_project.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_list_projects_search_compat(self): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) self.register_uris([ dict(method='GET', uri=self.get_mock_url(), status_code=200, json={'projects': [project_data.json_response['project']]}) ]) projects = self.cloud.search_projects(project_data.project_id) self.assertThat(len(projects), matchers.Equals(1)) self.assertThat( projects[0].id, matchers.Equals(project_data.project_id)) self.assert_calls()
Example #29
Source File: test_project.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_update_project_v3(self): project_data = self._get_project_data( description=self.getUniqueString('projectDesc')) reference_req = project_data.json_request.copy() # Remove elements not actually sent in the update reference_req['project'].pop('domain_id') reference_req['project'].pop('name') reference_req['project'].pop('enabled') self.register_uris([ dict(method='GET', uri=self.get_mock_url( resource=('projects?domain_id=%s' % project_data.domain_id)), status_code=200, json={'projects': [project_data.json_response['project']]}), dict(method='PATCH', uri=self.get_mock_url(append=[project_data.project_id]), status_code=200, json=project_data.json_response, validate=dict(json=reference_req)) ]) project = self.cloud.update_project( project_data.project_id, description=project_data.description, domain_id=project_data.domain_id) self.assertThat(project.id, matchers.Equals(project_data.project_id)) self.assertThat( project.name, matchers.Equals(project_data.project_name)) self.assertThat( project.description, matchers.Equals(project_data.description)) self.assert_calls()
Example #30
Source File: test_project.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_update_project_v2(self): self.use_keystone_v2() project_data = self._get_project_data( v3=False, description=self.getUniqueString('projectDesc')) # remove elements that are not updated in this test. project_data.json_request['tenant'].pop('name') project_data.json_request['tenant'].pop('enabled') self.register_uris([ dict(method='GET', uri=self.get_mock_url(v3=False), status_code=200, json={'tenants': [project_data.json_response['tenant']]}), dict(method='POST', uri=self.get_mock_url( v3=False, append=[project_data.project_id]), status_code=200, json=project_data.json_response, validate=dict(json=project_data.json_request)) ]) project = self.cloud.update_project( project_data.project_id, description=project_data.description) self.assertThat(project.id, matchers.Equals(project_data.project_id)) self.assertThat( project.name, matchers.Equals(project_data.project_name)) self.assertThat( project.description, matchers.Equals(project_data.description)) self.assert_calls()