async def test_002_package_url(self): async with pypi_package_url.imp(BaseConfig()) as pypi_url: async with pypi_url(None, None) as ctx: results = await ctx.run( {"response_json": self.INT_RESULT_JSON}) self.assertIn("insecure-package-0.1.0.tar.gz", results["url"]) self.PACKAGE_URL = results["url"]
async def test_001_package_version(self): async with pypi_latest_package_version.imp( BaseConfig()) as pypi_latest: async with pypi_latest(None, None) as ctx: results = await ctx.run( {"response_json": self.INT_RESULT_JSON}) self.assertEqual(results["version"], "0.1.0")
async def test_run(self): async with safety_check.imp(BaseConfig()) as safety: async with safety(None, None) as ctx: results = await ctx.run( {"package": "insecure-package", "version": "0.1.0"} ) self.assertEqual(results["issues"], 1)
async def test_003_package_contents(self): PACKAGE_URL = "https://files.pythonhosted.org/packages/dd/b7/b7318693b356d0e0ba566fb22b72a349a10337880c254e5e7e9f24f4f9b3/insecure-package-0.1.0.tar.gz" async with pypi_package_contents.imp(BaseConfig()) as pypi_cont: async with pypi_cont(None, None) as ctx: results = await ctx.run({"url": PACKAGE_URL}) no_files = os.listdir(results["directory"]) self.assertGreater(len(no_files), 0) shutil.rmtree(results["directory"])
async def test_run(self): async with run_bandit.imp(BaseConfig()) as bandit_latest: async with bandit_latest(None, None) as ctx: results = await ctx.run({"pkg": os.getcwd()}) self.assertLessEqual( int(results["report"] ["CONFIDENCE.HIGH_AND_SEVERITY.HIGH"]), 5.0, )
async def rproxy(self, upstream_path, subdomain, path): rproxyh = ReverseProxyHandler(BaseConfig()) async with rproxyh("localhost") as ctx: ctx.set_upstream( "http://%s:%d%s" % (self.server.host, self.server.port, upstream_path), subdomain="test", path="/route/this", ) yield ctx
async def test_run(self): async with self.operationsNetworkCtx() as ctx: await ctx.instantiate(add.op, BaseConfig(), opimp=add.imp) # No input set context and input network context required to test # the add operation self.assertEqual( 42, (await ctx.run(None, None, add.op, {"numbers": [40, 2]}))["sum"], )
async def setUp(self): await super().setUp() self.kvStore = MemoryKeyValueStore(BaseConfig())
async def test_contains_true(self): async with self.operationsNetworkCtx() as ctx: await ctx.instantiate(add.op, BaseConfig(), opimp=add.imp) self.assertTrue(await ctx.contains(add.op))
def setUp(self): self.kvStore = MemoryKeyValueStore(BaseConfig())
async def _add_fake_model(self): async with FakeModel(BaseConfig()) as model: self.model = self.cli.app["models"][self.mlabel] = model async with model() as mctx: self.mctx = self.cli.app["model_contexts"][self.mlabel] = mctx yield
async def setUp(self): self.operationsNetwork = MemoryOperationImplementationNetwork( MemoryOperationImplementationNetworkConfig( operations={"add": add.imp(BaseConfig())})) self.operationsNetworkCtx = await self.operationsNetwork.__aenter__()
async def test_004_cleanup_package(self): temp_dir = tempfile.mkdtemp(prefix="temp-") async with cleanup_pypi_package.imp(BaseConfig()) as cleanup_cont: async with cleanup_cont(None, None) as ctx: results = await ctx.run({"directory": temp_dir}) self.assertDictEqual(results, {})
async def test_000_package_json(self): async with pypi_package_json.imp(BaseConfig()) as pypi_package: async with pypi_package(None, None) as ctx: results = await ctx.run({"package": self.PACKAGE}) self.assertIs(type(results["response_json"]), dict) self.INT_RESULT_JSON.update(results["response_json"])
async def test_run(self): async with pypi_latest_package_version.imp( BaseConfig()) as pypi_latest: async with pypi_latest(None, None) as ctx: results = await ctx.run({"package": "insecure-package"}) self.assertEqual(results["version"], "0.1.0")