def test_ensure_dhcp_key_creates_key(self): nodegroup = factory.make_node_group(dhcp_key='') nodegroup.ensure_dhcp_key() # Check that the dhcp_key is not empty and looks # valid. self.assertThat(nodegroup.dhcp_key, EndsWith("==")) # The key is persisted. self.assertThat(reload_object(nodegroup).dhcp_key, EndsWith("=="))
def test_nonterminated_line(self, data, separator): """ If the input data does not end with a separator, then every line ends with a separator *except* the last line. """ assume(not data[-1].endswith(separator)) observed = list(_iter_lines(iter(data), separator)) self.expectThat(observed[:-1], AllMatch(EndsWith(separator))) self.assertThat(observed[-1], Not(EndsWith(separator)))
def test_nonterminated_line(self, data, separator): """ If the input data does not end with a separator, then every line ends with a separator *except* the last line. """ # Except when the data *ends* with the separator # E.g. data = '\x00'; separator = '\x00' assume(not b''.join(data).endswith(separator)) observed = list(_iter_lines(iter(data), separator)) self.expectThat(observed[:-1], AllMatch(EndsWith(separator))) self.assertThat(observed[-1], Not(EndsWith(separator)))
def test_all_scenarios_yielded(self): class ReferenceTest(unittest.TestCase): scenarios = [('1', {}), ('2', {})] def test_pass(self): pass test = ReferenceTest("test_pass") tests = list(generate_scenarios(test)) self.expectThat(tests[0].id(), EndsWith('ReferenceTest.test_pass(1)')) self.expectThat(tests[1].id(), EndsWith('ReferenceTest.test_pass(2)'))
def test_cache_and_retrieve(self): with open("hash_file", "w") as f: f.write("random stub data") calculated_hash = calculate_hash("hash_file", algorithm=self.algo) file = self.file_cache.cache( filename="hash_file", algorithm=self.algo, hash=calculated_hash ) leaf_path = os.path.join(self.algo, calculated_hash) self.assertThat(file, EndsWith(leaf_path)) retrieved_file = self.file_cache.get(algorithm=self.algo, hash=calculated_hash) self.assertThat(retrieved_file, EndsWith(leaf_path))
def test_with_two_scenarios_two_run(self): class ReferenceTest(self.Implementation): scenarios = [('1', {}), ('2', {})] def test_pass(self): pass test = ReferenceTest("test_pass") log = [] result = LoggingResult(log) test.run(result) self.assertTrue(result.wasSuccessful()) self.assertEqual(2, result.testsRun) self.expectThat(log[0][1].id(), EndsWith('ReferenceTest.test_pass(1)')) self.expectThat(log[4][1].id(), EndsWith('ReferenceTest.test_pass(2)'))
def test_compose_positional_args_does_not_end_with_newline(self): arg = factory.make_name('arg', sep='_') parser = ArgumentParser() parser.add_argument(arg) self.assertThat( '\n'.join(api.ActionHelp.compose_positional_args(parser)), Not(EndsWith('\n')))
def test_annotated_matcher(self): def die(): with ExpectedException(ValueError, 'bar', msg="foo"): pass exc = self.assertRaises(AssertionError, die) self.assertThat(exc.args[0], EndsWith(': foo'))
def test_start_responding(self, token, subdomain, zone_name): """ Calling ``start_responding`` causes an appropriate TXT record to be created. """ challenge = self._challenge_factory(token=token) response = challenge.response(RSA_KEY_512) responder = self._responder_factory(zone_name=zone_name) server_name = u'{}.{}'.format(subdomain, zone_name) zone = responder._driver.list_zones()[0] self.assertThat(zone.list_records(), HasLength(0)) d = responder.start_responding(server_name, challenge, response) self._perform() self.assertThat(d, succeeded(Always())) self.assertThat( zone.list_records(), MatchesListwise([ MatchesStructure( name=EndsWith(u'.' + subdomain), type=Equals('TXT'), ) ])) # Starting twice before stopping doesn't break things d = responder.start_responding(server_name, challenge, response) self._perform() self.assertThat(d, succeeded(Always())) self.assertThat(zone.list_records(), HasLength(1)) d = responder.stop_responding(server_name, challenge, response) self._perform() self.assertThat(d, succeeded(Always())) self.assertThat(zone.list_records(), HasLength(0))
def test_sets_specified_id(self): raw_test = self.ReferenceTest('test_pass') raw_id = "ReferenceTest.test_pass" scenario_name = self.scenario_name expect_id = "%(raw_id)s(%(scenario_name)s)" % vars() modified_test = apply_scenario(self.scenario, raw_test) self.expectThat(modified_test.id(), EndsWith(expect_id))
def test_start_sets_backtrace_by_default(self): timeline = Timeline() action = timeline.start("Sending mail", "Noone") self.assertNotEqual(None, action.backtrace) self.assertIsInstance(action.backtrace, str) self.assertThat(action.backtrace, EndsWith(' action = timeline.start("Sending mail", "Noone")\n'))
def test_glibc_mangling(self): dynamic_linker = elf.find_linker( root_path=self.path, snap_base_path='/snap/snap-name/current') self.get_packages_mock.assert_called_once_with('libc6') self.assertThat(dynamic_linker, EndsWith('ld-2.26.so'))
def test_make_parsed_url_accepts_explicit_port(self): port = factory.pick_port() url = factory.make_parsed_url(port=port) self.assertThat( url.netloc, EndsWith(':%d' % port), 'The generated URL does not contain' 'a port specification for port %d' % port)
def test_github_path_download(self, download_file): """Map github repository path to URL and download by url""" download_file.return_value = os.path.join( BLUEPRINTS_DIR, 'cloudify-hello-world-example-master.zip' ) download_file.side_effect = None blueprint_path = blueprint.get( 'cloudify-cosmo/cloudify-hello-world-example', 'openstack-blueprint.yaml', download=True ) self.addCleanup( shutil.rmtree, os.path.dirname(os.path.dirname(blueprint_path)) ) self.assertThat( blueprint_path, EndsWith( 'cloudify-hello-world-example-master/openstack-blueprint.yaml' ), ) self.assertEqual(download_file.call_count, 1) self.assertIn( 'https://github.com/cloudify-cosmo/' 'cloudify-hello-world-example/archive/master.tar.gz', download_file.call_args.args )
def test_compose_positional_args_does_not_end_with_newline(self): arg = factory.make_name("arg", sep="_") parser = ArgumentParser() parser.add_argument(arg) self.assertThat( "\n".join(api.ActionHelp.compose_positional_args(parser)), Not(EndsWith("\n")), )
def test_configure_dhcp_is_called_with_valid_dhcp_key(self): self.patch(dhcp, 'write_dhcp_config') self.patch(settings, "DHCP_CONNECT", True) nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED, dhcp_key='') configure_dhcp(nodegroup) args, kwargs = dhcp.write_dhcp_config.apply_async.call_args self.assertThat(kwargs['kwargs']['omapi_key'], EndsWith('=='))
def test_separator_terminates(self, data, separator): """ After splitting into lines, each line ends with the separator. """ # Make sure data ends with the separator. data.append(separator) observed = list(_iter_lines(iter(data), separator)) self.assertThat(observed, AllMatch(EndsWith(separator)))
def test_hud_icon_shows_the_ubuntu_emblem_on_empty_desktop(self): """When in 'show desktop' mode the hud icon must be the BFB icon.""" self.start_placeholder_app() self.unity.window_manager.enter_show_desktop() self.addCleanup(self.unity.window_manager.leave_show_desktop) self.unity.hud.ensure_visible() self.assertThat(self.unity.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
def assertCalledSouth(self, mock, database="default", call=1): call = mock.call_args_list[call] self.assertThat( call[0][0], MatchesListwise([ Equals("python2.7"), EndsWith("migrate.py"), Equals(database), ]))
def test_StateNotFoundError_endswith_troubleshoot_url_message_text(self): """The assertion raised must end with a link to troubleshooting url.""" err = StateNotFoundError('MyClass', foo="bar") self.assertThat( str(err), EndsWith('Tips on minimizing the occurrence of this failure ' 'are available here: ' 'https://developer.ubuntu.com/api/autopilot/python/1.6.0/' 'faq-troubleshooting/'))
def test_conflicts(self): project_dir = 'conflicts' exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, 'stage', project_dir) self.assertEqual(1, exception.returncode) expected = ( "Parts 'p1' and 'p2' have the following file paths in common " "which have\ndifferent contents: bin/test\n") self.assertThat(exception.output, EndsWith(expected))
def test_error_with_inexistent_build_package(self): self.copy_project_to_cwd("assemble") with open("snapcraft.yaml", "a") as yaml_file: yaml_file.write("build-packages:\n - inexistent-package\n") exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, "snap") expected = ("Could not find a required package in 'build-packages': " "inexistent-package\n") self.assertThat(exception.output, EndsWith(expected))
def test_reject(self): # A question can be rejected via the API. question_url = '/%s/+question/%d' % (self.target_name, self.question.id) response = self.webservice.named_post(question_url, 'reject', comment='A rejection message') self.assertEqual(201, response.status) self.assertThat(response.getheader('location'), EndsWith('%s/messages/1' % question_url)) self.assertEqual(QuestionStatus.INVALID, self.question.status)
def test_clean_main_without_any_dependent_raises(self): # Test that p1 (which has no dependencies but dependents) fails to # clean if none of its dependents are also specified. exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, ['clean', 'p1']) self.assertThat( exception.output, EndsWith( "Requested clean of 'p1' but 'p2' depends upon it. Please add " "each to the clean command if that's what you intended.\n")) self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)
def test_get_include_snippet_returns_snippet(self): target_dir = patch_dns_config_path(self) snippet = DNSConfig.get_include_snippet() self.assertThat( snippet, MatchesAll( Not(StartsWith('\n')), EndsWith('\n'), Contains(target_dir), Contains('include "%s/%s"' % ( config.get_dns_config_dir(), DNSConfig.target_file_name, ))))
def test_get_include_snippet_returns_snippet(self): target_dir = self.make_dir() self.patch(DNSConfig, 'target_dir', target_dir) dnsconfig = DNSConfig() snippet = dnsconfig.get_include_snippet() self.assertThat( snippet, MatchesAll( Not(StartsWith('\n')), EndsWith('\n'), Contains(target_dir), Contains('include "%s"' % dnsconfig.target_path)))
def test_clean_dependent_without_nested_dependents_raises(self): # Test that p2 (which has both dependencies and dependents) fails to # clean if its dependents (p3 and p4) are not also specified exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, ['clean', 'p2']) self.assertThat( exception.output, EndsWith( "Requested clean of 'p2' but 'p3' and 'p4' depend upon it. " "Please add each to the clean command if that's what you " "intended.\n")) self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)
def test_error_with_unexistent_build_package(self): self.copy_project_to_cwd('assemble') with open('snapcraft.yaml', 'a') as yaml_file: yaml_file.write('build-packages:\n' ' - inexistent-package\n') # We update here to get a clean log/stdout later self.run_snapcraft('update') exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, 'snap') expected = ("Could not find a required package in 'build-packages': " "inexistent-package\n") self.assertThat(exception.output, EndsWith(expected))
def test_tests_with_scenarios_calls_apply_scenarios(self): class ReferenceTest(unittest.TestCase): scenarios = [('demo', {})] def test_pass(self): pass test = ReferenceTest("test_pass") log = self.hook_apply_scenarios() tests = list(generate_scenarios(test)) self.expectThat(tests[0].id(), EndsWith('ReferenceTest.test_pass(demo)')) self.assertEqual([([('demo', {})], test)], log)
def test_clean_main_without_nested_dependent_raises(self): # Test that p1 (which has no dependencies but dependents) fails to # clean if its nested dependent (p3, by way of p2) is not also # specified exception = self.assertRaises(subprocess.CalledProcessError, self.run_snapcraft, ['clean', 'p1', 'p2'], self.project_dir) self.assertThat( exception.output, EndsWith( "Requested clean of 'p2' but 'p3' and 'p4' depend upon it. Please " "add each to the clean command if that's what you intended.\n") ) self.assert_not_clean(['p1', 'p2', 'p3', 'p4'], True)