Skip to content

Commit

Permalink
10139 - Use NameRequestService.create_expiry_date() (#1197)
Browse files Browse the repository at this point in the history
* Used NameRequestService.create_expiry_date()

* Added queue_common to requirements.txt; changed tests
  • Loading branch information
andrepestana-aot authored Dec 1, 2021
1 parent 9f74d17 commit f6f6c6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
16 changes: 4 additions & 12 deletions jobs/nro-update/nro/nro_datapump.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
import pytz

from namex.models import Name, State
from namex.services.name_request import NameRequestService
from namex.services.nro.utils import nro_examiner_name


def create_expiry_date(start: datetime, expires_in_days: int, expiry_hour: int = 0, expiry_min: int = 1, tz: timezone = timezone('US/Pacific')) -> datetime:
"""Return an expiry date in given days starting tomorrow."""
date = (start.astimezone(tz) + timedelta(days=expires_in_days+1))\
.replace(hour=expiry_hour, minute=expiry_min, second=0, microsecond=0)

return date


def nro_data_pump_update(nr, ora_cursor, expires_days=56):

expiry_date = create_expiry_date(
nr_service = NameRequestService()
expiry_date = nr_service.create_expiry_date(
start=nr.lastUpdate,
expires_in_days=expires_days,
tz=timezone('US/Pacific')
expires_in_days=expires_days
)

current_app.logger.debug(f'Setting expiry date to: { expiry_date }')
Expand Down
5 changes: 3 additions & 2 deletions jobs/nro-update/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ Flask-SQLAlchemy==2.5.1
Flask==1.1.2
Jinja2==2.11.3
MarkupSafe==1.1.1
SQLAlchemy==1.4.2
SQLAlchemy==1.4.11
Werkzeug==1.0.1
click==7.1.2
cx-Oracle==8.1.0
greenlet==1.0.0
itsdangerous==1.1.0
psycopg2-binary==2.8.6
python-dotenv==0.15.0
python-dotenv==0.17.1
pytz==2021.1
git+https://github.com/bcgov/namex.git#egg=namex&subdirectory=api
git+https://github.com/bcgov/namex-synonyms-api-py-client.git#egg=swagger_client
git+https://github.com/bcgov/namex.git#egg=queue_common&subdirectory=services/common
17 changes: 8 additions & 9 deletions jobs/nro-update/tests/test_nro_datapump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
import pytest
from pytz import timezone

from nro.nro_datapump import nro_data_pump_update, create_expiry_date
from nro.nro_datapump import nro_data_pump_update
from namex.models import Request, Name, State, User
from namex.services.name_request import NameRequestService


expiry_date_test_data = [
('using epoch utc', # test descriptive name
datetime(1970, 1, 1, 00, 00, tzinfo=timezone('US/Pacific', )), # start date - time
20, # days to add
23, # hour to set the final date time to
59, # minute to set the final date time to
'US/Pacific', # timezone that should be used
datetime(1970, 1, 21, 23, 59)), # expected outcome
('using a time after 4pm',
datetime(2001, 8, 5, 19, 00, tzinfo=timezone('US/Pacific',)), 20, 23, 59, 'US/Pacific', datetime(2001, 8, 25, 23, 59)),
datetime(2001, 8, 5, 19, 00, tzinfo=timezone('US/Pacific',)), 20, 'US/Pacific', datetime(2001, 8, 25, 23, 59)),
('using a time before 4pm',
datetime(2001, 8, 5, 9, 00, tzinfo=timezone('US/Pacific',)), 20, 23, 59, 'US/Pacific', datetime(2001, 8, 25, 23, 59)),
datetime(2001, 8, 5, 9, 00, tzinfo=timezone('US/Pacific',)), 20, 'US/Pacific', datetime(2001, 8, 25, 23, 59)),
]

@pytest.mark.parametrize("test_name, start_date, days, hours, mins, tz, ,expected_date", expiry_date_test_data)
def test_create_expiry_date(test_name, start_date, days, hours, mins, tz, expected_date):

ced = create_expiry_date(start_date, expires_in_days=days, expiry_hour=hours, expiry_min=mins, tz=timezone(tz))
@pytest.mark.parametrize("test_name, start_date, days, tz, expected_date", expiry_date_test_data)
def test_create_expiry_date(test_name, start_date, days, tz, expected_date):
nr_service = NameRequestService()
ced = nr_service.create_expiry_date(start_date, expires_in_days=days)

assert ced.replace(tzinfo=None) == expected_date
assert ced.tzinfo.zone == tz
Expand Down

0 comments on commit f6f6c6c

Please sign in to comment.