-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExampleData.py
More file actions
120 lines (96 loc) · 3.58 KB
/
ExampleData.py
File metadata and controls
120 lines (96 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" Copyright 2012-2025 Smartling, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limit
"""
class TestData:
def __init__(self, fields, pre = [], post = [], customTestCheck ='', isApiV2Response = True):
self.fields = fields
self.preCalls = pre
self.postCalls = post
self.customTestCheck = customTestCheck
self.is_apiv2_response = isApiV2Response
COPYRIGHT_HEADER = '''
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" Copyright 2012-2025 Smartling, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
"""
'''
EXAMPLE_HEADER= COPYRIGHT_HEADER + """
import os
import sys
import time, datetime
sys.path += [os.path.abspath('../'), os.path.abspath('../../')] # allow to import ../smartlingApiSdk.api
import smartlingApiSdk
from smartlingApiSdk.api.{API_NAME} import {API_NAME}
from smartlingApiSdk.ProxySettings import ProxySettings
from smartlingApiSdk.Credentials import Credentials
isPython3 = sys.version_info[:2] >= (3,0)
{EXTRA_IMPORTS}
def assert_equal(a,b, comment=''):
if a != b :
err = "Assertion Failed: '%s' != '%s' %s" % (a,b, comment)
if not isPython3 and type(err) == str:
err = err.decode('utf-8', 'ignore')
raise Exception(repr(err))
class test{API_NAME}(object):
CODE_SUCCESS_TOKEN = 'SUCCESS'
ACCEPTED_TOKEN = 'ACCEPTED'
def tearDown(self):
print("tearDown", "OK")
def setUp(self):
credentials = Credentials() #Gets your Smartling credetnials from environment variables
self.MY_USER_IDENTIFIER = credentials.MY_USER_IDENTIFIER
self.MY_USER_SECRET = credentials.MY_USER_SECRET
self.MY_PROJECT_ID = credentials.MY_PROJECT_ID
#needed for testProjects
self.MY_ACCOUNT_UID = credentials.MY_ACCOUNT_UID
self.MY_LOCALE = credentials.MY_LOCALE
if self.MY_ACCOUNT_UID == "CHANGE_ME":
print("can't test projects api call, set self.MY_ACCOUNT_UID or export SL_ACCOUNT_UID=*********")
return
useProxy = False
if useProxy :
proxySettings = ProxySettings("login", "password", "proxy_host", "proxy_port or None")
else:
proxySettings = None
self.{api_name}_api = {API_NAME}(self.MY_USER_IDENTIFIER, self.MY_USER_SECRET, self.MY_PROJECT_ID, proxySettings)
print("setUp", "OK", "\\n")
"""
EXAMPLE_FOOTER = """
def example():
t = test{API_NAME}()
t.setUp()
%s
t.tearDown()
if __name__ == '__main__':
example()
"""
TESTS_FOOTER = """
def test_all(self):
t = self
%s
"""