Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .whitesource
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"settingsInheritedFrom": "sede-x/whitesource-config@main"
"scanSettings": {
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff",
"useMendCheckNames": true
},
"issueSettings": {
"minSeverityLevel": "LOW",
"issueType": "DEPENDENCY"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging
import time
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from io import BytesIO

import pandas as pd
Expand Down Expand Up @@ -172,13 +172,17 @@ def _validate_options(self) -> bool:
f"Unable to parse End date. Please specify in {self.user_datetime_format} format."
)

if start_date > datetime.utcnow() - timedelta(days=1):
if start_date > datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(
days=1
):
raise ValueError("Start date can't be in future.")

if start_date > end_date:
raise ValueError("Start date can't be ahead of End date.")

if end_date > datetime.utcnow() - timedelta(days=1):
if end_date > datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(
days=1
):
raise ValueError("End date can't be in future.")

if self.sleep_duration < 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
from datetime import datetime, timezone
import logging
import time
import pandas as pd
Expand Down Expand Up @@ -142,13 +142,17 @@ def _validate_options(self) -> bool:
f"Unable to parse End date. Please specify in {self.user_datetime_format} format."
)

if start_date > datetime.utcnow() - timedelta(days=1):
if start_date > datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(
days=1
):
raise ValueError("Start date can't be in future.")

if start_date > end_date:
raise ValueError("Start date can't be ahead of End date.")

if end_date > datetime.utcnow() - timedelta(days=1):
if end_date > datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(
days=1
):
raise ValueError("End date can't be in future.")

return True
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
from datetime import datetime
from datetime import datetime, timezone

from pyspark.sql import DataFrame, SparkSession
from pyspark.sql.functions import when, substring, lit, col, concat
Expand Down Expand Up @@ -91,7 +91,7 @@ def transform(self) -> DataFrame:

self.pre_transform_validation()

processed_date = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
processed_date = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")

df = (
self.data.withColumn("WeatherDay", substring("FcstValidLocal", 0, 10))
Expand Down
44 changes: 35 additions & 9 deletions tests/api/v1/test_api_circular_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
from pytest_mock import MockerFixture
import pandas as pd
from datetime import datetime
from datetime import datetime, timezone
from tests.api.v1.api_test_objects import (
CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT,
CIRCULAR_AVERAGE_MOCKED_PARAMETER_ERROR_DICT,
Expand All @@ -36,7 +36,11 @@

async def test_api_circular_average_get_success(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.5]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.5],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -49,7 +53,8 @@ async def test_api_circular_average_get_success(mocker: MockerFixture):
actual = response.text
expected = test_data.to_json(orient="table", index=False, date_unit="ns")
expected = (
expected.rstrip("}") + ',"pagination":{"limit":null,"offset":null,"next":null}}'
expected.replace(',"tz":"UTC"', "").rstrip("}")
+ ',"pagination":{"limit":null,"offset":null,"next":null}}'
)

assert response.status_code == 200
Expand All @@ -58,7 +63,11 @@ async def test_api_circular_average_get_success(mocker: MockerFixture):

async def test_api_circular_average_get_validation_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -79,7 +88,11 @@ async def test_api_circular_average_get_validation_error(mocker: MockerFixture):

async def test_api_circular_average_get_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(
mocker, MOCK_METHOD, test_data, Exception("Error Connecting to Database")
Expand All @@ -99,7 +112,11 @@ async def test_api_circular_average_get_error(mocker: MockerFixture):

async def test_api_circular_average_post_success(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.5]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.5],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -113,7 +130,8 @@ async def test_api_circular_average_post_success(mocker: MockerFixture):
actual = response.text
expected = test_data.to_json(orient="table", index=False, date_unit="ns")
expected = (
expected.rstrip("}") + ',"pagination":{"limit":null,"offset":null,"next":null}}'
expected.replace(',"tz":"UTC"', "").rstrip("}")
+ ',"pagination":{"limit":null,"offset":null,"next":null}}'
)

assert response.status_code == 200
Expand All @@ -122,7 +140,11 @@ async def test_api_circular_average_post_success(mocker: MockerFixture):

async def test_api_circular_average_post_validation_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -144,7 +166,11 @@ async def test_api_circular_average_post_validation_error(mocker: MockerFixture)

async def test_api_circular_average_post_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(
mocker, MOCK_METHOD, test_data, Exception("Error Connecting to Database")
Expand Down
44 changes: 35 additions & 9 deletions tests/api/v1/test_api_circular_standard_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
from pytest_mock import MockerFixture
import pandas as pd
from datetime import datetime
from datetime import datetime, timezone
from tests.api.v1.api_test_objects import (
CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT,
CIRCULAR_AVERAGE_MOCKED_PARAMETER_ERROR_DICT,
Expand All @@ -38,7 +38,11 @@

async def test_api_circular_standard_deviation_get_success(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.5]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.5],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -51,7 +55,8 @@ async def test_api_circular_standard_deviation_get_success(mocker: MockerFixture
actual = response.text
expected = test_data.to_json(orient="table", index=False, date_unit="ns")
expected = (
expected.rstrip("}") + ',"pagination":{"limit":null,"offset":null,"next":null}}'
expected.replace(',"tz":"UTC"', "").rstrip("}")
+ ',"pagination":{"limit":null,"offset":null,"next":null}}'
)

assert response.status_code == 200
Expand All @@ -62,7 +67,11 @@ async def test_api_circular_standard_deviation_get_validation_error(
mocker: MockerFixture,
):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -83,7 +92,11 @@ async def test_api_circular_standard_deviation_get_validation_error(

async def test_api_circular_standard_deviation_get_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(
mocker, MOCK_METHOD, test_data, Exception("Error Connecting to Database")
Expand All @@ -103,7 +116,11 @@ async def test_api_circular_standard_deviation_get_error(mocker: MockerFixture):

async def test_api_circular_standard_deviation_post_success(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.5]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.5],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -117,7 +134,8 @@ async def test_api_circular_standard_deviation_post_success(mocker: MockerFixtur
actual = response.text
expected = test_data.to_json(orient="table", index=False, date_unit="ns")
expected = (
expected.rstrip("}") + ',"pagination":{"limit":null,"offset":null,"next":null}}'
expected.replace(',"tz":"UTC"', "").rstrip("}")
+ ',"pagination":{"limit":null,"offset":null,"next":null}}'
)

assert response.status_code == 200
Expand All @@ -128,7 +146,11 @@ async def test_api_circular_standard_deviation_post_validation_error(
mocker: MockerFixture,
):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

Expand All @@ -150,7 +172,11 @@ async def test_api_circular_standard_deviation_post_validation_error(

async def test_api_circular_standard_deviation_post_error(mocker: MockerFixture):
test_data = pd.DataFrame(
{"EventTime": [datetime.utcnow()], "TagName": ["TestTag"], "Value": [1.01]}
{
"EventTime": [datetime.now(timezone.utc)],
"TagName": ["TestTag"],
"Value": [1.01],
}
)
mocker = mocker_setup(
mocker, MOCK_METHOD, test_data, Exception("Error Connecting to Database")
Expand Down
Loading