From 7bc4d34704492cd4a176ea989bbf056e3326921b Mon Sep 17 00:00:00 2001 From: Five Grant <5@fivegrant.com> Date: Mon, 11 Sep 2023 13:24:44 -0500 Subject: [PATCH] Upload to S3 --- env.sample | 5 ++- lib/settings.py | 3 ++ poetry.lock | 83 +++++++++++++++++++++++++++++++++++++++++++------ pyproject.toml | 5 ++- tests/report.py | 12 +++++-- 5 files changed, 95 insertions(+), 13 deletions(-) diff --git a/env.sample b/env.sample index 9c2357f..1e8c939 100644 --- a/env.sample +++ b/env.sample @@ -7,4 +7,7 @@ MIT_TR_URL=http://mit-tr.staging.terarium.ai LOG_LEVEL=INFO MOCK_TA1=True MOCK_TDSt=True -OPENAI_API_KEY=foo \ No newline at end of file +OPENAI_API_KEY=foo +AWS_ACCESS_KEY_ID=NA +AWS_SECRET_ACCESS_KEY=NA +BUCKET=NA diff --git a/lib/settings.py b/lib/settings.py index a78215f..d0a179c 100644 --- a/lib/settings.py +++ b/lib/settings.py @@ -11,6 +11,9 @@ class Settings(BaseSettings): TDS_URL: str = "http://tds:15" OPENAI_API_KEY: str = "foo" LOG_LEVEL: str = "INFO" + AWS_ACCESS_KEY_ID: str = "NA" + AWS_SECRET_ACCESS_KEY: str = "NA" + BUCKET: str = "NA" settings = Settings() diff --git a/poetry.lock b/poetry.lock index e9229dc..4a8d569 100644 --- a/poetry.lock +++ b/poetry.lock @@ -61,6 +61,44 @@ docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib- tests = ["attrs[tests-no-zope]", "zope-interface"] tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +[[package]] +name = "boto3" +version = "1.28.44" +description = "The AWS SDK for Python" +optional = false +python-versions = ">= 3.7" +files = [ + {file = "boto3-1.28.44-py3-none-any.whl", hash = "sha256:c53c92dfe22489ba31e918c2e7b59ff43e2e778bd3d3559e62351a739382bb5c"}, + {file = "boto3-1.28.44.tar.gz", hash = "sha256:eea3b07e0f28c9f92bccab972af24a3b0dd951c69d93da75227b8ecd3e18f6c4"}, +] + +[package.dependencies] +botocore = ">=1.31.44,<1.32.0" +jmespath = ">=0.7.1,<2.0.0" +s3transfer = ">=0.6.0,<0.7.0" + +[package.extras] +crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] + +[[package]] +name = "botocore" +version = "1.31.44" +description = "Low-level, data-driven core of boto 3." +optional = false +python-versions = ">= 3.7" +files = [ + {file = "botocore-1.31.44-py3-none-any.whl", hash = "sha256:83d61c1ca781e6ede19fcc4d5dd73004eee3825a2b220f0d7727e32069209d98"}, + {file = "botocore-1.31.44.tar.gz", hash = "sha256:84f90919fecb4a4f417fd10145c8a87ff2c4b14d6381cd34d9babf02110b3315"}, +] + +[package.dependencies] +jmespath = ">=0.7.1,<2.0.0" +python-dateutil = ">=2.1,<3.0.0" +urllib3 = ">=1.25.4,<1.27" + +[package.extras] +crt = ["awscrt (==0.16.26)"] + [[package]] name = "certifi" version = "2023.7.22" @@ -431,6 +469,17 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "jmespath" +version = "1.0.1" +description = "JSON Matching Expressions" +optional = false +python-versions = ">=3.7" +files = [ + {file = "jmespath-1.0.1-py3-none-any.whl", hash = "sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980"}, + {file = "jmespath-1.0.1.tar.gz", hash = "sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe"}, +] + [[package]] name = "jsonschema" version = "4.19.0" @@ -1212,6 +1261,23 @@ files = [ click = ">=5.0.0" redis = ">=4.0.0" +[[package]] +name = "s3transfer" +version = "0.6.2" +description = "An Amazon S3 Transfer Manager" +optional = false +python-versions = ">= 3.7" +files = [ + {file = "s3transfer-0.6.2-py3-none-any.whl", hash = "sha256:b014be3a8a2aab98cfe1abc7229cc5a9a0cf05eb9c1f2b86b230fd8df3f78084"}, + {file = "s3transfer-0.6.2.tar.gz", hash = "sha256:cab66d3380cca3e70939ef2255d01cd8aece6a4907a9528740f668c4b0611861"}, +] + +[package.dependencies] +botocore = ">=1.12.36,<2.0a.0" + +[package.extras] +crt = ["botocore[crt] (>=1.20.29,<2.0a.0)"] + [[package]] name = "service-test-tools" version = "1.0.0" @@ -1337,20 +1403,19 @@ files = [ [[package]] name = "urllib3" -version = "2.0.4" +version = "1.26.16" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false -python-versions = ">=3.7" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" files = [ - {file = "urllib3-2.0.4-py3-none-any.whl", hash = "sha256:de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4"}, - {file = "urllib3-2.0.4.tar.gz", hash = "sha256:8d22f86aae8ef5e410d4f539fde9ce6b2113a001bb4d189e0aed70642d602b11"}, + {file = "urllib3-1.26.16-py2.py3-none-any.whl", hash = "sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f"}, + {file = "urllib3-1.26.16.tar.gz", hash = "sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14"}, ] [package.extras] -brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] -secure = ["certifi", "cryptography (>=1.9)", "idna (>=2.0.0)", "pyopenssl (>=17.1.0)", "urllib3-secure-extra"] -socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] -zstd = ["zstandard (>=0.18.0)"] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] name = "uvicorn" @@ -1411,4 +1476,4 @@ dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "78503563750e347cda50c3af8ef4f9278ff08ae34cd05a1af65b2f44f906510b" +content-hash = "4d6fc9f3243181f702668ea4d8f025db05814f208b82b22a0d0fb1df74e6814a" diff --git a/pyproject.toml b/pyproject.toml index 7071377..b191811 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ pydantic-settings = "^2.0.3" uvicorn = "^0.22.0" fastapi = "^0.100.0" pypdf = "^3.12.0" +boto3 = "^1.28.44" [tool.poetry.group.dev.dependencies] service-test-tools = {git = "https://github.com/jataware/service-test-tools"} @@ -35,7 +36,9 @@ gen-report = "tests.report:report" [tool.poe.tasks] _test = "status-test" _report = "gen-report" -report = ["_test", "_report"] +report.sequence = ["_test", "_report"] +report.ignore_fail = true + [tool.pytest.ini_options] markers = ["resource"] diff --git a/tests/report.py b/tests/report.py index 606ef23..187e2e4 100644 --- a/tests/report.py +++ b/tests/report.py @@ -7,6 +7,9 @@ import yaml import pytest +import boto3 + +from lib.settings import settings def test(output_file="tests/output/tests.json"): pytest.main(["--json-report", f"--json-report-file={output_file}"]) @@ -47,9 +50,14 @@ def add_case(testobj): report[scenario]["description"] = spec["description"] timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') - filename = f"tests/output/report_{timestamp}.json" - with open(filename, "w") as file: + filename = f"report_{timestamp}.json" + fullpath = os.path.join("tests/output", "filename") + with open(fullpath, "w") as file: json.dump(report, file, indent=2) + s3 = boto3.client("s3") + full_handle = os.path.join("ta1", filename) + s3.upload_file(fullpath, settings.BUCKET, full_handle) + if __name__ == "__main__": report() \ No newline at end of file