Python testtools.matchers.Not() Examples
The following are 30
code examples of testtools.matchers.Not().
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_leases.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_skips_dns_record_for_hostname_from_existing_node(self): subnet = factory.make_ipv4_Subnet_with_IPRanges( with_static_range=False, dhcp_on=True ) dynamic_range = subnet.get_dynamic_ranges()[0] ip = factory.pick_ip_in_IPRange(dynamic_range) hostname = factory.make_name().lower() factory.make_Node(hostname=hostname) kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname) update_lease(**kwargs) unknown_interface = UnknownInterface.objects.filter( mac_address=kwargs["mac"] ).first() self.assertIsNotNone(unknown_interface) self.assertEquals(subnet.vlan, unknown_interface.vlan) sip = unknown_interface.ip_addresses.first() self.assertIsNotNone(sip) self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip)))
Example #2
Source File: test_services.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_attempts_to_assume_sole_responsibility_on_each_iteration(self): # A filesystem lock is used to prevent multiple network monitors from # running on each host machine. lock = NetworksMonitoringLock() with lock: service = self.makeService() # Iterate one time. yield service.updateInterfaces() # Interfaces have not been recorded yet. self.assertThat(service.interfaces, Equals([])) # Iterate once more and ... yield service.updateInterfaces() # ... interfaces ARE recorded. self.assertThat(service.interfaces, Not(Equals([])))
Example #3
Source File: test_services.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_starts_and_stops_process(self): service = SleepProcessProtocolService() with TwistedLoggerFixture() as logger: service.startService() self.assertThat(service._protocol.done, Not(IsFiredDeferred())) yield service.stopService() result = yield service._protocol.done self.assertThat(result, Is(None)) self.assertThat( logger.output, DocTestMatches( "SleepProcessProtocolService started.\n" "-...-\n" "SleepProcessProtocolService ..." ), ) with ExpectedException(ProcessExitedAlready): service._process.signalProcess("INT")
Example #4
Source File: test_services.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_restarts_process_after_finishing(self): ifname = factory.make_name("eth") service = NeighbourDiscoveryService(ifname, Mock()) mock_process_params = self.patch(service, "getProcessParameters") mock_process_params.return_value = [b"/bin/echo", b"{}"] service.clock = Clock() service.startService() # Wait for the protocol to finish service.clock.advance(0.0) yield service._protocol.done # Advance the clock (should start the service again) interval = service.step service.clock.advance(interval) # The Deferred should have been recreated. self.assertThat(service._protocol.done, Not(IsFiredDeferred())) yield service._protocol.done service.stopService()
Example #5
Source File: test_services.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_restarts_process_after_finishing(self): ifname = factory.make_name("eth") service = BeaconingService(ifname, Mock()) mock_process_params = self.patch(service, "getProcessParameters") mock_process_params.return_value = [b"/bin/echo", b"{}"] service.clock = Clock() service.startService() # Wait for the protocol to finish service.clock.advance(0.0) yield service._protocol.done # Advance the clock (should start the service again) interval = service.step service.clock.advance(interval) # The Deferred should have been recreated. self.assertThat(service._protocol.done, Not(IsFiredDeferred())) yield service._protocol.done service.stopService()
Example #6
Source File: test_services.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_send_multicast_beacon_sets_ipv4_source(self): # Note: Always use a random port for testing. (port=0) protocol = BeaconingSocketProtocol( reactor, port=0, process_incoming=True, loopback=True, interface="::", debug=False, ) self.assertThat(protocol.listen_port, Not(Is(None))) listen_port = protocol.listen_port._realPortNumber self.write_secret() beacon = create_beacon_payload("advertisement", {}) protocol.send_multicast_beacon("127.0.0.1", beacon, port=listen_port) # Verify that we received the packet. yield wait_for_rx_packets(protocol, 1) yield protocol.stopProtocol()
Example #7
Source File: test_bootresources.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_streams_product_download_product_contains_keys(self): product, _ = self.make_usable_product_boot_resource() response = self.get_stream_client("maas:v2:download.json") output = json.loads(response.content.decode(settings.DEFAULT_CHARSET)) self.assertThat( output["products"][product], ContainsAll( [ "versions", "subarch", "label", "version", "arch", "release", "os", ] ), ) # Verify optional fields aren't added self.assertThat( output["products"][product], Not(ContainsAll(["kflavor", "bootloader_type"])), )
Example #8
Source File: test_boot_resources.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_failed_run_deletes_snapshot(self): # Patch out things that we don't want running during the test. Patch # at a low level, so that we exercise all the function calls that a # unit test might not put to the test. self.patch_maaslog() self.patch(boot_resources, "call_and_check") self.patch(boot_resources, "service_monitor") args = self.make_working_args() # Cause the import to fail. exception_type = factory.make_exception_type() mock_download = self.patch( boot_resources, "download_all_boot_resources" ) mock_download.side_effect = exception_type() # Run the import code. self.assertRaises(exception_type, boot_resources.main, args) # Verify the reuslts. self.assertThat(os.path.join(self.storage, "cache"), Not(DirExists())) self.assertThat( os.path.join(self.storage, "current"), Not(DirExists()) )
Example #9
Source File: test_views.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_make_view_atomic_wraps_view_with_post_commit_savepoint(self): hooks = post_commit_hooks.hooks savepoint_level = len(connection.savepoint_ids) def view(*args, **kwargs): # We're one more savepoint in. self.assertThat( connection.savepoint_ids, HasLength(savepoint_level + 1) ) # Post-commit hooks have been saved. self.assertThat(post_commit_hooks.hooks, Not(Is(hooks))) # Return the args we were given. return args, kwargs handler = views.WebApplicationHandler() view_atomic = handler.make_view_atomic(view) self.assertThat(post_commit_hooks.hooks, Is(hooks)) self.assertThat( view_atomic(sentinel.arg, kwarg=sentinel.kwarg), Equals(((sentinel.arg,), {"kwarg": sentinel.kwarg})), ) self.assertThat(post_commit_hooks.hooks, Is(hooks))
Example #10
Source File: test_views.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_handle_uncaught_exception_does_not_note_other_failure(self): handler = views.WebApplicationHandler() request = make_request() request.path = factory.make_name("path") failure_type = factory.make_exception_type() failure = failure_type, failure_type(), None response = handler.handle_uncaught_exception( request=request, resolver=get_resolver(None), exc_info=failure, reraise=False, ) # HTTP 500 is returned... self.expectThat( response.status_code, Equals(http.client.INTERNAL_SERVER_ERROR) ) # ... but the response is NOT recorded as needing a retry. self.expectThat( handler._WebApplicationHandler__retry, Not(Contains(response)) )
Example #11
Source File: test_machines.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_POST_allocate_allocates_machine_by_storage(self): """Storage label is returned alongside machine data""" machine = factory.make_Node( status=NODE_STATUS.READY, with_boot_disk=False ) factory.make_PhysicalBlockDevice( node=machine, size=11 * (1000 ** 3), tags=["ssd"], formatted_root=True, ) response = self.client.post( reverse("machines_handler"), {"op": "allocate", "storage": "needed:10(ssd)"}, ) self.assertThat(response, HasStatusCode(http.client.OK)) response_json = json.loads( response.content.decode(settings.DEFAULT_CHARSET) ) device_id = response_json["physicalblockdevice_set"][0]["id"] constraints = response_json["constraints_by_type"] self.expectThat(constraints, Contains("storage")) self.expectThat(constraints["storage"], Contains("needed")) self.expectThat(constraints["storage"]["needed"], Contains(device_id)) self.expectThat(constraints, Not(Contains("verbose_storage")))
Example #12
Source File: test_annotations.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_template_renders_with_no_warnings(self): """The Tempita tmpl-api.rst template should render for the sample annotated API docstring with no errors. """ ds = self.sample_api_annotated_docstring template = APITemplateRenderer() template_path = "%s/../%s" % ( os.path.dirname(__file__), self.api_tempita_template, ) api_docstring_parser = APIDocstringParser() api_docstring_parser.parse(ds, uri=self.test_uri_plural) result = template.apply_template(template_path, api_docstring_parser) self.assertThat(result, Not(Contains("API_WARNING")))
Example #13
Source File: test_vlans.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_update_with_undefined_space_clears_space(self): self.become_admin() fabric = factory.make_Fabric() vlan = factory.make_VLAN(fabric=fabric, space=RANDOM) self.assertThat(vlan.space, Not(Is(None))) uri = get_vlan_uri(vlan, fabric) response = self.client.put(uri, {"space": Space.UNDEFINED}) self.assertEqual( http.client.OK, response.status_code, response.content ) parsed_vlan = json.loads( response.content.decode(settings.DEFAULT_CHARSET) ) vlan = reload_object(vlan) self.assertThat(vlan.space, Is(None)) self.assertThat(parsed_vlan["space"], Equals(Space.UNDEFINED))
Example #14
Source File: test_proxyconfig.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_only_enabled_subnets_are_present(self): self.patch(settings, "PROXY_CONNECT", True) disabled = yield deferToDatabase(self.make_subnet, allow_proxy=False) enabled = yield deferToDatabase(self.make_subnet) yield proxyconfig.proxy_update_config(reload_proxy=False) # enabled's cidr must be present matcher = Contains("acl localnet src %s" % enabled.cidr) self.assertThat( "%s/%s" % (self.tmpdir, config.MAAS_PROXY_CONF_NAME), FileContains(matcher=matcher), ) # disabled's cidr must not be present matcher = Not(Contains("acl localnet src %s" % disabled.cidr)) self.assertThat( "%s/%s" % (self.tmpdir, config.MAAS_PROXY_CONF_NAME), FileContains(matcher=matcher), )
Example #15
Source File: test_vlans.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_update_with_empty_space_clears_space(self): self.become_admin() fabric = factory.make_Fabric() vlan = factory.make_VLAN(fabric=fabric, space=RANDOM) self.assertThat(vlan.space, Not(Is(None))) uri = get_vlan_uri(vlan, fabric) response = self.client.put(uri, {"space": ""}) self.assertEqual( http.client.OK, response.status_code, response.content ) parsed_vlan = json.loads( response.content.decode(settings.DEFAULT_CHARSET) ) vlan = reload_object(vlan) self.assertThat(vlan.space, Is(None)) self.assertThat(parsed_vlan["space"], Equals(Space.UNDEFINED))
Example #16
Source File: test_config.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_no_write_local(self): config.write_config(False) matcher_one = Not( Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist') ) matcher_two = Not( Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot') ) # maas.log is still local when no write local. matcher_three = Contains(':syslogtag, contains, "maas"') self.assertThat( "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME), FileContains( matcher=MatchesAll(matcher_one, matcher_two, matcher_three) ), )
Example #17
Source File: testing.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def assertPublicationUpdated(self): """Assert there's a newer `DNSPublication` record. Call `capturePublication` first to obtain a reference record. """ old = self.getCapturedPublication() new = yield self.capturePublication() if old is None: self.assertThat( new, Not(Is(None)), "DNS has not been published at all." ) else: self.assertThat( new.serial, GreaterThan(old.serial), "DNS has not been published again.", )
Example #18
Source File: testing.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def assertSynced(self): """Assert there's a newer `RBACSync` record. Call `captureSynced` first to obtain a reference record. """ old = self.getCapturedSynced() new = yield self.captureSynced() if old is None: self.assertThat( new, Not(Is(None)), "RBAC sync tracking has not been modified at all.", ) else: self.assertThat( new.id, GreaterThan(old.id), "RBAC sync tracking has not been modified again.", )
Example #19
Source File: test_blockdevice_manager.py From flocker with Apache License 2.0 | 6 votes |
def test_make_tmpfs_mount(self): """ make_tmpfs_mount should create a tmpfs mountpoint that can be written to. Once the mount is unmounted all files should be gone. """ mountpoint = self._get_directory_for_mount() test_file = mountpoint.child(unicode(uuid4())) self.manager_under_test.make_tmpfs_mount(mountpoint) self.expectThat(test_file.path, Not(FileExists())) test_file.touch() self.expectThat(test_file.path, FileExists(), 'File did not exist after being touched on tmpfs.') self.manager_under_test.unmount(mountpoint) self.expectThat(test_file.path, Not(FileExists()), 'File persisted after tmpfs mount unmounted')
Example #20
Source File: test_leases.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_skips_dns_record_for_coerced_hostname_from_existing_node(self): subnet = factory.make_ipv4_Subnet_with_IPRanges( with_static_range=False, dhcp_on=True ) dynamic_range = subnet.get_dynamic_ranges()[0] ip = factory.pick_ip_in_IPRange(dynamic_range) hostname = "gaming device" factory.make_Node(hostname="gaming-device") kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname) update_lease(**kwargs) unknown_interface = UnknownInterface.objects.filter( mac_address=kwargs["mac"] ).first() self.assertIsNotNone(unknown_interface) self.assertEquals(subnet.vlan, unknown_interface.vlan) sip = unknown_interface.ip_addresses.first() self.assertIsNotNone(sip) self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip)))
Example #21
Source File: test_builtin_scripts.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_creates_scripts(self): load_builtin_scripts() for script in BUILTIN_SCRIPTS: script_in_db = Script.objects.get(name=script.name) # While MAAS allows user scripts to leave these fields blank, # builtin scripts should always have values. self.assertTrue(script_in_db.title, script.name) self.assertTrue(script_in_db.description, script.name) self.assertTrue(script_in_db.script.data, script.name) self.assertThat(script_in_db.tags, Not(Equals([])), script.name) # These values should always be set by the script loader. self.assertEquals( "Created by maas-%s" % get_maas_version(), script_in_db.script.comment, script.name, ) self.assertTrue(script_in_db.default, script.name)
Example #22
Source File: test_packaging.py From keras-lambda with MIT License | 5 votes |
def test_manifest_exclude_honoured(self): self.run_setup('sdist', allow_fail=False) with open(os.path.join( self.package_dir, 'pbr_testpackage.egg-info/SOURCES.txt'), 'r') as f: body = f.read() self.assertThat( body, matchers.Not(matchers.Contains('pbr_testpackage/extra.py'))) self.assertThat(body, matchers.Contains('pbr_testpackage/__init__.py'))
Example #23
Source File: test_start_up.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_creates_maas_uuid(self): self.assertThat(get_maas_id(), Is(None)) with post_commit_hooks: start_up.inner_start_up(master=False) uuid = Config.objects.get_config("uuid") self.assertThat(uuid, Not(Is(None)))
Example #24
Source File: test_domain.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_delete_dnsdata_fails_for_non_admin(self): user = factory.make_User() handler = DomainHandler(user, {}, None) domain = factory.make_Domain() dnsresource = factory.make_DNSResource(domain=domain) dnsdata = factory.make_DNSData(dnsresource) with ExpectedException(HandlerPermissionError): handler.delete_dnsdata( {"domain": domain.id, "dnsdata_id": dnsdata.id} ) dnsdata = reload_object(dnsdata) self.assertThat(dnsdata, Not(Is(None)))
Example #25
Source File: test_start_up.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_creates_maas_id_file(self): self.assertThat(get_maas_id(), Is(None)) with post_commit_hooks: start_up.inner_start_up(master=False) self.assertThat(get_maas_id(), Not(Is(None)))
Example #26
Source File: test_dnsresource.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_does_not_modify_existing_non_dynamic_records(self): sip_reserved = factory.make_StaticIPAddress( ip="10.0.0.1", alloc_type=IPADDRESS_TYPE.USER_RESERVED ) hostname = factory.make_name().lower() factory.make_DNSResource(name=hostname, ip_addresses=[sip_reserved]) sip_dynamic = factory.make_StaticIPAddress( ip="10.0.0.2", alloc_type=IPADDRESS_TYPE.DISCOVERED ) DNSResource.objects.update_dynamic_hostname(sip_dynamic, hostname) dnsrr = DNSResource.objects.get(name=hostname) self.assertThat(dnsrr.ip_addresses.all(), Contains(sip_reserved)) self.assertThat(dnsrr.ip_addresses.all(), Not(Contains(sip_dynamic)))
Example #27
Source File: test_boot_sources.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_GET_returns_boot_source(self): self.become_admin() boot_source = factory.make_BootSource() response = self.client.get(get_boot_source_uri(boot_source)) self.assertEqual(http.client.OK, response.status_code) returned_boot_source = json_load_bytes(response.content) # The returned object contains a 'resource_uri' field. self.assertEqual( reverse("boot_source_handler", args=[boot_source.id]), returned_boot_source["resource_uri"], ) # The other fields are the boot source's fields. del returned_boot_source["resource_uri"] # JSON loads the keyring_data as a str, but it needs to be bytes. returned_boot_source["keyring_data"] = returned_boot_source[ "keyring_data" ].encode("utf-8") # All the fields are present. self.assertItemsEqual( DISPLAYED_BOOTSOURCE_FIELDS, returned_boot_source.keys() ) # Remove created and updated that is handled by django. del returned_boot_source["created"] del returned_boot_source["updated"] self.assertThat( boot_source, MatchesStructure.byEquality(**returned_boot_source) ) self.assertThat( returned_boot_source["keyring_data"], Not(Contains("<memory at")) )
Example #28
Source File: test_nodes.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_clearing_owner_clears_node_key(self): node = factory.make_Node(status=NODE_STATUS.READY) # Ensure the node has an owner. node.owner = factory.make_User() node.save() # Ensure there's a token. token = NodeKey.objects.get_token_for_node(node) self.assertThat(token, Not(Is(None))) # Remove the owner. node.owner = None node.save() # The token has been deleted. token = reload_object(token) self.assertThat(token, Is(None))
Example #29
Source File: test_nodes.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_changing_owner_clears_node_key(self): node = factory.make_Node(status=NODE_STATUS.READY) # Ensure the node has an owner. node.owner = factory.make_User() node.save() # Ensure there's a token. token = NodeKey.objects.get_token_for_node(node) self.assertThat(token, Not(Is(None))) # Change the owner. node.owner = factory.make_User() node.save() # The token has been deleted. token = reload_object(token) self.assertThat(token, Is(None))
Example #30
Source File: test_utils.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_get_maas_user_agent_without_uuid(self): user_agent = get_maas_user_agent() uuid = Config.objects.get_config("uuid") self.assertEqual(uuid, None) self.assertThat(user_agent, IsNonEmptyString) self.assertThat(user_agent, Not(Contains(uuid)))