def integration_test(): with LiveServer() as liveserver: status_code = upload().file("schnulli.tar.gz").file_content("Hello world") \ .package_name("foobar").package_version("1.0.0").to(liveserver) assert_that(status_code).is_equal_to(OK) assert_that("target/integrationtest/packages/hosted/foobar-1.0.0.tar.gz").is_a_file()
def integration_test(): with StaticPyPiServer(): with LiveServer() as liveserver: versions_page = download(liveserver.url + "simple/yadt/") assert_that(versions_page).contains("0.1.2").contains( "1.2.3").contains("2.3.4")
def test_should_register_interceptor(self): def some_interceptor(): pass @before(some_interceptor) def some_test(): pass assert_that(getattr(some_test, BEFORE_ATTRIBUTE)).is_equal_to([some_interceptor])
def integration_test_with_hosted_file(): with LiveServer() as liveserver: liveserver.create_hosted_file("pyassert-0.1.2.tar.gz") index_page = download(liveserver.url + "simple/") assert_that(index_page).contains("pyassert")
def list_versions_should_return_empty_list_when_no_package_files_are_found(temp_dir): temp_dir.create_directory("packages") index = PackageIndex("any_name", temp_dir.join("packages")) versions = [v for v in index.list_versions("spam")] assert_that(versions).is_empty()
def integration_test(): with StaticPyPiServer(): with LiveServer() as liveserver: actual_content = download(liveserver.url + "package/yadt/1.2.3/yadt-1.2.3.tar.gz") assert_that(actual_content).is_equal_to("static content")
def parse_p(p, category): judgment_type = CATEGORY_TO_JUDGMENT_TYPE[category] judgment_name = CATEGORY_TO_JUDGMENT_NAME.get(category) or category lines = list(p.stripped_strings) assert_that(len(lines)).ge(2).le(4) name = lines[0] if name.endswith(' - ON STRIKE'): name = name[:-12] if len(lines) <= 2: address = parse_addr(lines[1:2]) else: address = parse_addr(lines[1:3]) if len(lines) >= 4: assert_that(lines[3]).starts_with('Phone: ') address.set('telephone', lines[3][7:]) hotel = Item('Hotel') hotel.set('name', name) hotel.set('address', address) judgment = Item('Judgment') judgment.set('judgmentType', judgment_type) judgment.set('name', judgment_name) judgment.set('target', hotel) return judgment
def constructor_should_raise_exception_when_config_does_not_contain_expected_section(temp_dir): temp_dir.create_file("config.cfg", "[spam]\nspam=eggs") def callback(): Configuration(temp_dir.join("config.cfg")) assert_that(callback).raises(ValueError)
def test_resumeTorrents_by_hashlist(): sut = QBitTorrent("admin", "adminadmin") sut.__POST__ = MagicMock(name="post") sut.resumeTorrents(hashes=["2", "3", "4"]) assert_that(sut.__POST__.call_count).is_equal_to(3)
def constructor_should_raise_exception_when_config_file_has_invalid_content(temp_dir): temp_dir.create_file("config.cfg", "spam") def callback(): Configuration(temp_dir.join("config.cfg")) assert_that(callback).raises(ValueError)
def add_package_should_write_package_file(temp_dir, package_data): index = PackageIndex("any_name", temp_dir.join("packages")) index.add_package("spam", "version", package_data) expected_file_name = temp_dir.join("packages", "spam-version.tar.gz") assert_that(expected_file_name).is_a_file() assert_that(expected_file_name).has_file_length_of(17)
def contains_should_return_true_if_package_in_specific_version_available( temp_dir): temp_dir.create_directory("packages") temp_dir.touch("packages", "spam-0.1.2.tar.gz") index = PackageIndex("any_name", temp_dir.join("packages")) assert_that(index.contains("spam", "0.1.2")).is_equal_to(True)
def should_send_index_result(web_application): when(webapp).get_package_statistics().thenReturn((0, 0)) response = web_application.get("/") assert_that(response.status_code).is_equal_to(200) verify(webapp).get_package_statistics()
def test_should_not_validate_project_with_duplicate_dependency_when_version_is_given_for_one( self): self.project.depends_on('spam') self.project.depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Runtime dependency 'spam' has been defined multiple times.")
def test_should_not_validate_project_with_duplicate_build_dependency_when_url_is_given_for_one( self): self.project.build_depends_on('spam') self.project.build_depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Build dependency 'spam' has been defined multiple times.")
def test_should_not_validate_project_with_duplicate_dependency_when_urls_are_different( self): self.project.depends_on('spam', url='y') self.project.depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Runtime dependency 'spam' has been defined multiple times.")
def test_should_not_validate_project_with_duplicate_build_dependency_but_different_versions( self): self.project.build_depends_on('spam', version='1') self.project.build_depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Build dependency 'spam' has been defined multiple times.")
def test_ensure_that_single_two_decorators_with_multiple_fixtures_are_handled(self): @given(spam="spam", eggs="eggs") @given(foo="foo") def some_function(): pass assert_that(getattr(some_function, GIVEN_ATTRIBUTE)).equals({"spam": "spam", "eggs": "eggs", "foo": "foo"})
def test_should_not_validate_project_with_runtime_dependency_being_also_given_as_build_dependency (self): self.project.depends_on('spam') self.project.build_depends_on('spam') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has also been given as build dependency.") assert_that(len(validation_messages)).equals(1)
def should_return_given_hosted_packages_directory_when_packages_directory_option_is_given(temp_dir): temp_dir.create_file("config.cfg", "[{0}]\n{1}=packages/hosted".format(Configuration.SECTION, Configuration.OPTION_HOSTED_PACKAGES_DIRECTORY)) config = Configuration(temp_dir.join("config.cfg")) assert_that(config.hosted_packages_directory).is_equal_to("packages/hosted")
def step_impl(context: Context, status_code: int) -> None: """ :type context: behave.runner.Context :type status_code: int """ # intに変換されていることを確認する assert_that(status_code).is_instance_of(int)
def integration_test_with_hosted_file(): with LiveServer() as liveserver: liveserver.create_hosted_file("yadt-1.2.3.tar.gz") actual_content = download(liveserver.url + "package/yadt/1.2.3/yadt-1.2.3.tar.gz") assert_that(actual_content).is_equal_to("hosted content")
def integration_test_with_cached_file(): with StaticPyPiServer(): with LiveServer() as liveserver: liveserver.create_cached_file("yadt-5.4.3.tar.gz") versions_page = download(liveserver.url + "simple/yadt/") assert_that(versions_page).contains("0.1.2").contains("1.2.3").contains("2.3.4").does_not_contain("5.4.3")
def test_ensure_that_decorated_functions_can_be_executed(self): @given(spam="spam") def some_test(): some_test.called = True some_test.called = False some_test() assert_that(some_test.called).is_true()
def should_send_not_found_when_trying_to_get_package_content_for_nonexisting_package(web_application): when(webapp).get_package_content(any_value(), any_value()).thenReturn(None) response = web_application.get("/package/package_name/version/package_name-version.tar.gz") assert_that(response.status_code).is_equal_to(404) verify(webapp).get_package_content("package_name", "version")
def get_package_content_should_return_none_when_file_does_not_exist(temp_dir): temp_dir.create_directory("packages") index = PackageIndex("any_name", temp_dir.join("packages")) actual_content = index.get_package_content("eggs", "0.1.2") assert_that(actual_content).is_none()
def list_versions_should_return_empty_list_when_no_package_files_are_found( temp_dir): temp_dir.create_directory("packages") index = PackageIndex("any_name", temp_dir.join("packages")) versions = [v for v in index.list_versions("spam")] assert_that(versions).is_empty()
def GenAlive(): resp = requests.get('http://127.0.0.1:5000/namegen') print('\nGen Alive test') if resp.ok == True: print('PASS') else: print('FAIL') assert_that(resp.ok).is_true()
def list_available_package_names_should_return_single_package_when_directory_contains_single_package_file(temp_dir): temp_dir.create_directory("packages") temp_dir.touch("packages", "spam-0.1.2.tar.gz") index = PackageIndex("any_name", temp_dir.join("packages")) names = [name for name in index.list_available_package_names()] assert_that(names).is_equal_to(["spam"])
def should_return_error_when_no_versions_available(web_application): when(webapp).list_versions(any_value()).thenReturn([]) response = web_application.get("/simple/committer/") assert_that(response.status_code).is_equal_to(404) verify(webapp).list_versions("committer")
def threadAlive(): resp = requests.get('http://127.0.0.1:5000') print('\nThread Alive test') if resp.ok == True: print('PASS') else: print('FAIL') assert_that(resp.ok).is_true()
def test_ensure_that_decorated_function_can_be_called(self): @test def some_test(): some_test.called = True some_test.called = False some_test() assert_that(some_test.called).is_true()
def test_get_torrents_should_filter_by_func(): sut = QBitTorrent("admin", "adminadmin") sut.__GET__ = MagicMock(name="__GET__") sut.__GET__.return_value = list([{"state": "downloading"}, {"state": "pausedDL"}]) torrents = sut.getTorrents(lambda x: x["state"] == "downloading") assert_that(generator_len(torrents)).is_equal_to(1) sut.__GET__.assert_called_with("/json/torrents")
def test_should_not_validate_project_with_runtime_dependency_being_also_given_as_build_dependency(self): self.project.depends_on('spam') self.project.build_depends_on('spam') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Runtime dependency 'spam' has also been given as build dependency.") assert_that(len(validation_messages)).equals(1)
def test_should_not_validate_project_with_duplicate_dependency_for_more_than_two_times(self): self.project.depends_on("spam", version="1") self.project.depends_on("spam", version="2") self.project.depends_on("spam", version="3") validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") assert_that(len(validation_messages)).equals(1)
def list_versions_should_return_single_version_when_single_package_file_matches_package_name(temp_dir): temp_dir.create_directory("packages") temp_dir.touch("packages", "spam-0.1.2.tar.gz") index = PackageIndex("any_name", temp_dir.join("packages")) versions = [v for v in index.list_versions("spam")] assert_that(versions).is_equal_to(["0.1.2"])
def should_send_bad_request_when_trying_to_upload_package_when_version_is_missing( web_application): response = web_application.post("/", data={ ":action": "spam", "name": "spam" }) assert_that(response.status_code).is_equal_to(400)
def should_return_given_pypi_url_when_pypi_url_option_is_given(temp_dir): temp_dir.create_file( "config.cfg", "[{0}]\n{1}=spam.log".format(Configuration.SECTION, Configuration.OPTION_PYPI_URL)) config = Configuration(temp_dir.join("config.cfg")) assert_that(config.pypi_url).is_equal_to("spam.log")
def constructor_should_raise_exception_when_config_does_not_contain_expected_section( temp_dir): temp_dir.create_file("config.cfg", "[spam]\nspam=eggs") def callback(): Configuration(temp_dir.join("config.cfg")) assert_that(callback).raises(ValueError)
def should_return_given_log_file_when_log_file_option_is_given(temp_dir): temp_dir.create_file( "config.cfg", "[{0}]\n{1}=spam.log".format(Configuration.SECTION, Configuration.OPTION_LOG_FILE)) config = Configuration(temp_dir.join("config.cfg")) assert_that(config.log_file).is_equal_to("spam.log")
def test_should_invoke_test_function_twice_when_fixture_provides_two_values(self): function = InvocationCountingFunctionMock() test_definition = TestDefinition(function, "unittest", "unittest", "module", {"spam": enumerate("spam", "eggs")}) self.injector.execute_test(test_definition) assert_that(function.invocation_counter).equals(2)
def constructor_should_raise_exception_when_config_file_has_invalid_content( temp_dir): temp_dir.create_file("config.cfg", "spam") def callback(): Configuration(temp_dir.join("config.cfg")) assert_that(callback).raises(ValueError)
def test_ensure_that_test_is_marked_as_failing_and_exception_type_in_message_when_some_exception_raised(self): function = InvocationCountingFunctionMock(Exception("Caboom")) test_definition = TestDefinition(function, "unittest", "unittest", "module", {}) actual = self.injector.execute_test(test_definition) assert_that(actual[0].success).is_false() assert_that(actual[0].message).equals("Exception: Caboom")
def test_should_invoke_test_function_once_when_no_givens_are_set(self): function = InvocationCountingFunctionMock() test_definition = TestDefinition(function, "unittest", "unittest", "module", {}) self.injector.execute_test(test_definition) assert_that(function.invocation_counter).equals(1) assert_that(function.invocation_arguments[0]).equals({})
def test_ensure_that_test_is_marked_as_successful_when_being_executed_without_exception(self): function = InvocationCountingFunctionMock() test_definition = TestDefinition(function, "unittest", "unittest", "module", {}) actual = self.injector.execute_test(test_definition) assert_that(actual[0].success).is_true() assert_that(actual[0].parameter_description).equals("")
def test_ensure_that_test_is_marked_as_failing_when_being_executed_with_an_assertion_error(self): function = InvocationCountingFunctionMock(AssertionError("Caboom")) test_definition = TestDefinition(function, "unittest", "unittest", "module", {}) actual = self.injector.execute_test(test_definition) assert_that(actual[0].success).is_false() assert_that(actual[0].message).equals("Caboom")
def test_should_not_validate_project_with_duplicate_build_dependency_for_more_than_two_times (self): self.project.build_depends_on('spam', version='1') self.project.build_depends_on('spam', version='2') self.project.build_depends_on('spam', version='3') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") assert_that(len(validation_messages)).equals(1)
def test_should_not_validate_project_with_duplicate_build_dependency_for_more_than_two_times(self): self.project.build_depends_on('spam', version='1') self.project.build_depends_on('spam', version='2') self.project.build_depends_on('spam', version='3') validation_messages = self.project.validate() assert_that(validation_messages).contains( "Build dependency 'spam' has been defined multiple times.") assert_that(len(validation_messages)).equals(1)
def list_versions_should_return_single_version_when_single_package_file_matches_package_name( temp_dir): temp_dir.create_directory("packages") temp_dir.touch("packages", "spam-0.1.2.tar.gz") index = PackageIndex("any_name", temp_dir.join("packages")) versions = [v for v in index.list_versions("spam")] assert_that(versions).is_equal_to(["0.1.2"])
def list_available_package_names_should_return_single_package_when_directory_contains_single_package_file( temp_dir): temp_dir.create_directory("packages") temp_dir.touch("packages", "spam-0.1.2.tar.gz") index = PackageIndex("any_name", temp_dir.join("packages")) names = [name for name in index.list_available_package_names()] assert_that(names).is_equal_to(["spam"])
def integration_test_with_cached_file(): with StaticPyPiServer(): with LiveServer() as liveserver: liveserver.create_cached_file("yadt-5.4.3.tar.gz") versions_page = download(liveserver.url + "simple/yadt/") assert_that(versions_page).contains("0.1.2").contains( "1.2.3").contains("2.3.4").does_not_contain("5.4.3")
def test_full_run(): output_dir = '/tmp/iam_tester_results' returncode, stdout, stderr = run_command([ 'aws-iam-tester', 'account', '--config-file', f'{script_path}/config.yml', '--write-to-file', '--output-location', output_dir ], ) assert_that(stdout).contains("are written to") assert_that(output_dir).is_a_directory()