2 File in charge of testing the boilerplate Boilerplate non http class.
6from datetime
import datetime
7import constants
as TCONST
12sys.path.append(os.getcwd())
17except ImportError
as e:
18 raise ImportError(
"Failed to import the src module")
from e
21SUCCESS = TCONST.SUCCESS
27 username=CONST.DB_USER,
28 password=CONST.DB_PASSWORD,
29 db_name=CONST.DB_DATABASE,
36 Function in charge of converting a datetime object to a string.
38 return date.strftime(
"%Y-%m-%d")
43 Function in charge of converting a datetime object to a string.
45 return date.strftime(
"%Y-%m-%d %H:%M:%S")
50 Function in charge of converting a datetime object to a string.
52 microsecond = date.strftime(
"%f")[:3]
53 converted_time = date.strftime(
"%Y-%m-%d %H:%M:%S")
54 return f
"{converted_time}.{microsecond}"
59 Function in charge of converting a string to a datetime object.
61 return datetime.strptime(string,
"%Y-%m-%d %H:%M:%S")
66 Function in charge of converting a string to a datetime object.
68 return datetime.strptime(string,
"%Y-%m-%d")
73 Function in charge of testing the datetime_to_string function.
76 test_data = SI.datetime_to_string(test, date_only=
False, sql_mode=
False)
78 assert test_data
is not None
79 assert test_data == correct_data
84 Function in charge of testing the datetime_to_string function.
87 test_data = SI.datetime_to_string(test, date_only=
False, sql_mode=
True)
89 assert test_data
is not None
90 assert test_data == correct_data
95 Function in charge of testing the datetime_to_string function.
98 test_data = SI.datetime_to_string(test, date_only=
True, sql_mode=
False)
100 assert test_data
is not None
101 assert test_data == correct_data
106 Function in charge of testing the datetime_to_string function.
108 test = datetime.now()
109 test_data = SI.datetime_to_string(test, date_only=
True, sql_mode=
True)
111 assert test_data
is not None
112 assert test_data == correct_data
117 Function in charge of testing the datetime_to_string function.
120 with pytest.raises(ValueError):
121 SI.datetime_to_string(test, date_only=
False, sql_mode=
False)
126 Function in charge of testing the datetime_to_string function.
129 with pytest.raises(ValueError):
130 SI.datetime_to_string(test, date_only=
False, sql_mode=
True)
135 Function in charge of testing the datetime_to_string function.
139 with pytest.raises(ValueError):
140 SI.datetime_to_string(test, date_only=
True, sql_mode=
False)
145 Function in charge of testing the datetime_to_string function.
149 with pytest.raises(ValueError):
150 SI.datetime_to_string(test, date_only=
True, sql_mode=
True)
155 Function in charge of testing the string_to_datetime function.
157 node = datetime.now()
159 test_data = SI.string_to_datetime(test, date_only=
False)
160 assert test_data
is not None
161 assert test_data == node
166 Function in charge of testing the string_to_datetime function.
168 node = datetime.now()
170 test_data = SI.string_to_datetime(test, date_only=
True)
171 assert test_data
is not None
172 assert test_data == node
177 Function in charge of testing the string_to_datetime function.
179 test = datetime.now()
180 with pytest.raises(ValueError):
181 SI.string_to_datetime(test, date_only=
False)
186 Function in charge of testing the string_to_datetime function.
189 test = datetime.now()
190 with pytest.raises(ValueError):
191 SI.string_to_datetime(test, date_only=
True)
196 Function in charge of testing the string_to_datetime function.
199 with pytest.raises(ValueError):
200 SI.string_to_datetime(test, date_only=
False)
205 Function in charge of testing the string_to_datetime function.
209 with pytest.raises(ValueError):
210 SI.string_to_datetime(test, date_only=
True)
datetime _str_to_datetime(str string)
None test_string_to_datetime_no_error()
None test_string_to_date_datetime_not_a_string_instance()
None test_datetime_to_datetime_string_not_a_datetime_instance()
str _datetime_to_date_str(datetime date)
datetime _str_to_date(str string)
None test_string_to_datetime_datetime_not_a_string_instance()
str _datetime_to_sql_time_str(datetime date)
None test_datetime_to_date_sql_string_not_a_datetime_instance()
None test_datetime_to_datetime_string_no_error()
None test_string_to_datetime_datetime_not_a_datetime_string_instance()
None test_datetime_to_date_string_not_a_datetime_instance()
None test_string_to_date_datetime_not_a_datetime_string_instance()
None test_datetime_to_date_sql_string_no_error()
None test_datetime_to_sql_string_not_a_datetime_instance()
None test_datetime_to_sql_string_no_error()
None test_string_to_date_datetime_no_error()
str _datetime_to_datetime_str(datetime date)
None test_datetime_to_date_string_no_error()