pam-python 0.1.9__tar.gz → 0.1.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pam_python-0.1.9/pam_python.egg-info → pam_python-0.1.11}/PKG-INFO +1 -1
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/cli.py +2 -2
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/service.py +2 -2
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/docker/Dockerfile +1 -0
- pam_python-0.1.11/pam/templates/service/service.test.tmpl +103 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/service/service.yaml +1 -1
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/service/service_class.tmpl +1 -1
- {pam_python-0.1.9 → pam_python-0.1.11/pam_python.egg-info}/PKG-INFO +1 -1
- {pam_python-0.1.9 → pam_python-0.1.11}/setup.py +1 -1
- pam_python-0.1.9/pam/templates/service/service.test.tmpl +0 -102
- {pam_python-0.1.9 → pam_python-0.1.11}/LICENSE.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/README.md +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/__init__.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/api.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/interface_task_manager.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/models/__init__.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/models/request_command.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/server.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/task_manager.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/temp_file_utils.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/buildcmd/pamb +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/buildcmd/pamb-base.sh +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/init/dockerignore.tmpl +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/init/gitignore.tmpl +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/init/main.tmpl +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/init/pylintrc.tmpl +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/templates/service/functions.tmpl +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/tester_task.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam/utils.py +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam_python.egg-info/SOURCES.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam_python.egg-info/dependency_links.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam_python.egg-info/entry_points.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam_python.egg-info/requires.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/pam_python.egg-info/top_level.txt +0 -0
- {pam_python-0.1.9 → pam_python-0.1.11}/setup.cfg +0 -0
|
@@ -104,11 +104,11 @@ def create_service(name):
|
|
|
104
104
|
|
|
105
105
|
cpy("service/service.yaml", os.path.join(name, "service.yaml") )
|
|
106
106
|
cpy("service/functions.tmpl", os.path.join(name, "functions.py") )
|
|
107
|
-
cpy("service/service.test.tmpl", os.path.join(name, name
|
|
107
|
+
cpy("service/service.test.tmpl", os.path.join(name, f"test_{name}.py") )
|
|
108
108
|
|
|
109
109
|
replace_template_content(name, to_pascal_case(name)+"Svc", to_pascal_case(name)+"Svc.py")
|
|
110
110
|
replace_template_content(name, to_pascal_case(name)+"Svc", "service.yaml")
|
|
111
|
-
replace_template_content(name, to_pascal_case(name)+"Svc", name
|
|
111
|
+
replace_template_content(name, to_pascal_case(name)+"Svc", f"test_{name}.py")
|
|
112
112
|
|
|
113
113
|
print(f"Service {name} created.")
|
|
114
114
|
print(f"Run `pam test {name}` to run tests for the service.")
|
|
@@ -40,7 +40,7 @@ class Service:
|
|
|
40
40
|
self.request.service_name, self.request.token, "result_", ".csv"
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
-
dry_run = self.request.runtime_parameters
|
|
43
|
+
dry_run = self.request.runtime_parameters.get("dry_run", "false")
|
|
44
44
|
if dry_run is not None and dry_run.lower() == "true":
|
|
45
45
|
log("Dry run mode will not upload results.")
|
|
46
46
|
return tmp_file_name
|
|
@@ -80,7 +80,7 @@ class Service:
|
|
|
80
80
|
service_name, token, f"report_{report_name}_", '.csv'
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
-
dry_run = self.request.runtime_parameters
|
|
83
|
+
dry_run = self.request.runtime_parameters.get("dry_run", "false")
|
|
84
84
|
if dry_run is not None and dry_run.lower() == "true":
|
|
85
85
|
log("Dry run mode will not upload report.")
|
|
86
86
|
return report_csv_path
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import uuid
|
|
4
|
+
import unittest
|
|
5
|
+
from typing import List, Tuple
|
|
6
|
+
from faker import Faker
|
|
7
|
+
import pandas as pd
|
|
8
|
+
from pam.tester_task import TesterTask
|
|
9
|
+
from pam.models.request_command import RequestCommand
|
|
10
|
+
from pam.temp_file_utils import TempfileUtils
|
|
11
|
+
#pylint: disable=import-error
|
|
12
|
+
from #CLASS_NAME# import #CLASS_NAME#
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# ==================== GLOBAL VARIABLES ====================
|
|
16
|
+
TOTAL_PAGES=3
|
|
17
|
+
MOCK_DIR = "./TEMP_TEST_DATA"
|
|
18
|
+
TempfileUtils.temp_base_path = f"{MOCK_DIR}/app/data"
|
|
19
|
+
TempfileUtils.temp_datasource_path = f"{MOCK_DIR}/app/data/data_sources"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# ==================== UTILITY FUNCTIONS ====================
|
|
23
|
+
def __create_mock_csv(page, mockDir):
|
|
24
|
+
fake = Faker()
|
|
25
|
+
for i in range(page):
|
|
26
|
+
data = {
|
|
27
|
+
"id": range(1, 11), # 10 rows
|
|
28
|
+
"name": [fake.name() for _ in range(10)],
|
|
29
|
+
"age": [fake.random_int(min=18, max=65) for _ in range(10)],
|
|
30
|
+
"email": [fake.email() for _ in range(10)],
|
|
31
|
+
"created_date": [fake.date_time_this_year() for _ in range(10)]
|
|
32
|
+
}
|
|
33
|
+
file_name = f"{mockDir}/mock_data_{i+1}.csv"
|
|
34
|
+
df = pd.DataFrame(data)
|
|
35
|
+
df.to_csv(file_name, index=False)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def on_request_data(page) -> Tuple[List[str], bool, str]:
|
|
39
|
+
if page is None or page == "" :
|
|
40
|
+
page = "1"
|
|
41
|
+
|
|
42
|
+
page_num = int(page)
|
|
43
|
+
next_page = page_num+1
|
|
44
|
+
|
|
45
|
+
is_end = False
|
|
46
|
+
if page_num == TOTAL_PAGES:
|
|
47
|
+
is_end = True
|
|
48
|
+
next_page = ""
|
|
49
|
+
|
|
50
|
+
mock_csv = f"{MOCK_DIR}/mock_data_{page}.csv"
|
|
51
|
+
return [mock_csv], is_end, next_page
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def on_upload_report(report_file):
|
|
55
|
+
print(f"Uploaded Report {report_file}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def on_upload_result(result_file):
|
|
59
|
+
print(f"Uploaded {result_file}")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def createMockDir(mockDir):
|
|
63
|
+
if os.path.exists(mockDir):
|
|
64
|
+
shutil.rmtree(mockDir)
|
|
65
|
+
os.makedirs(mockDir)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# ======================================================================
|
|
69
|
+
|
|
70
|
+
class TestService1(unittest.TestCase):
|
|
71
|
+
|
|
72
|
+
def setUp(self):
|
|
73
|
+
createMockDir(MOCK_DIR)
|
|
74
|
+
__create_mock_csv(TOTAL_PAGES, MOCK_DIR)
|
|
75
|
+
|
|
76
|
+
self.testerTask = TesterTask()
|
|
77
|
+
self.testerTask.set_on_upload_result(on_upload_result)
|
|
78
|
+
self.testerTask.set_on_request_data(on_request_data)
|
|
79
|
+
self.testerTask.set_on_upload_report(on_upload_report)
|
|
80
|
+
|
|
81
|
+
def test_run_service(self):
|
|
82
|
+
#---- Create Request Command
|
|
83
|
+
token = uuid.uuid4()
|
|
84
|
+
runtime_parameters = {
|
|
85
|
+
"some_param": "some_value"
|
|
86
|
+
}
|
|
87
|
+
DATA_API="https://localhost.test/api/dataadapter/test"
|
|
88
|
+
RESPONSE_API="https://localhost.test/api/dataadapter/test"
|
|
89
|
+
|
|
90
|
+
req = RequestCommand(
|
|
91
|
+
runtime_parameters=runtime_parameters,
|
|
92
|
+
token=token,
|
|
93
|
+
cmd="start",
|
|
94
|
+
data_api=DATA_API,
|
|
95
|
+
response_api=RESPONSE_API,
|
|
96
|
+
is_end=None,
|
|
97
|
+
next=None,
|
|
98
|
+
input_files=None,
|
|
99
|
+
service_name='FinishSvc',
|
|
100
|
+
)
|
|
101
|
+
service_instance = #CLASS_NAME#(self.testerTask, req)
|
|
102
|
+
#---- Run Service ----
|
|
103
|
+
self.testerTask.test_service(service_instance)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
endpoint: /#CLASS_NAME#
|
|
2
|
-
class: #CLASS_NAME#
|
|
2
|
+
class: #CLASS_NAME#
|
|
@@ -4,7 +4,7 @@ from pam.utils import log
|
|
|
4
4
|
#pylint: disable=import-error
|
|
5
5
|
from .functions import create_report, load_csv_file
|
|
6
6
|
|
|
7
|
-
class #CLASS_NAME#(Service):
|
|
7
|
+
class #CLASS_NAME#Svc(Service):
|
|
8
8
|
|
|
9
9
|
#pylint: disable=useless-parent-delegation
|
|
10
10
|
def __init__(self, task_manager, req):
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import os
|
|
3
|
-
import shutil
|
|
4
|
-
import uuid
|
|
5
|
-
from typing import List, Tuple
|
|
6
|
-
from faker import Faker
|
|
7
|
-
import pandas as pd
|
|
8
|
-
from pam.tester_task import TesterTask
|
|
9
|
-
from pam.models.request_command import RequestCommand
|
|
10
|
-
from pam.temp_file_utils import TempfileUtils
|
|
11
|
-
#pylint: disable=import-error
|
|
12
|
-
from #CLASS_NAME# import #CLASS_NAME#
|
|
13
|
-
|
|
14
|
-
def __create_mock_csv(page):
|
|
15
|
-
fake = Faker()
|
|
16
|
-
data = {
|
|
17
|
-
"id": range(1, 11), # 10 rows
|
|
18
|
-
"name": [fake.name() for _ in range(10)],
|
|
19
|
-
"age": [fake.random_int(min=18, max=65) for _ in range(10)],
|
|
20
|
-
"email": [fake.email() for _ in range(10)],
|
|
21
|
-
"created_date": [fake.date_time_this_year() for _ in range(10)]
|
|
22
|
-
}
|
|
23
|
-
file_name = f"{MOCK_DIR}/mock_data_faker_{page}.csv"
|
|
24
|
-
df = pd.DataFrame(data)
|
|
25
|
-
df.to_csv(file_name, index=False)
|
|
26
|
-
return file_name
|
|
27
|
-
|
|
28
|
-
def can_convert_to_int(x):
|
|
29
|
-
try:
|
|
30
|
-
int(x)
|
|
31
|
-
return True
|
|
32
|
-
except (ValueError, TypeError):
|
|
33
|
-
return False
|
|
34
|
-
|
|
35
|
-
def on_request_data(page) -> Tuple[List[str], bool, str]:
|
|
36
|
-
page_num = 1
|
|
37
|
-
if can_convert_to_int(page):
|
|
38
|
-
page_num = int(page)
|
|
39
|
-
|
|
40
|
-
next_page = str(page_num + 1)
|
|
41
|
-
is_end = False
|
|
42
|
-
if page_num == MAXPAGE:
|
|
43
|
-
is_end = True
|
|
44
|
-
next_page = ""
|
|
45
|
-
|
|
46
|
-
mock_csv = __create_mock_csv(page_num)
|
|
47
|
-
|
|
48
|
-
return [mock_csv], is_end, next_page
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def on_upload_report(report_file):
|
|
52
|
-
print(f"Uploaded Report {report_file}")
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def on_upload_result(result_file):
|
|
56
|
-
print(f"Uploaded {result_file}")
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
#---- Constants ----
|
|
61
|
-
MAXPAGE=3
|
|
62
|
-
MOCK_DIR = "./TEMP_TEST_DATA"
|
|
63
|
-
TempfileUtils.temp_base_path = f"{MOCK_DIR}/app/data"
|
|
64
|
-
TempfileUtils.temp_datasource_path = f"{MOCK_DIR}/app/data/data_sources"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
#---- Create Mock Dir ----
|
|
68
|
-
if os.path.exists(MOCK_DIR):
|
|
69
|
-
shutil.rmtree(MOCK_DIR)
|
|
70
|
-
os.makedirs(MOCK_DIR)
|
|
71
|
-
|
|
72
|
-
#---- Create Tester Task ----
|
|
73
|
-
testerTask = TesterTask()
|
|
74
|
-
testerTask.set_on_upload_result(on_upload_result)
|
|
75
|
-
testerTask.set_on_request_data(on_request_data)
|
|
76
|
-
testerTask.set_on_upload_report(on_upload_report)
|
|
77
|
-
|
|
78
|
-
#---- Create Request Command ----
|
|
79
|
-
token=unique_id = uuid.uuid4()
|
|
80
|
-
runtime_parameters = {
|
|
81
|
-
"some_param": "some_value"
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
DATA_API="https://localhost.test/api/dataadapter/test"
|
|
85
|
-
RESPONSE_API="https://localhost.test/api/dataadapter/test"
|
|
86
|
-
|
|
87
|
-
req = RequestCommand(
|
|
88
|
-
runtime_parameters=runtime_parameters,
|
|
89
|
-
token=token,
|
|
90
|
-
cmd="start",
|
|
91
|
-
data_api=DATA_API,
|
|
92
|
-
response_api=RESPONSE_API,
|
|
93
|
-
is_end=None,
|
|
94
|
-
next=None,
|
|
95
|
-
input_files=None,
|
|
96
|
-
service_name='#CLASS_NAME#',
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
service_instance = #CLASS_NAME#Svc(testerTask, req)
|
|
100
|
-
|
|
101
|
-
#---- Start Test ----
|
|
102
|
-
testerTask.test_service(service_instance)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|