Skip to content

Commit

Permalink
Fix #242 - Updated dates in new changed: lines when override is not u…
Browse files Browse the repository at this point in the history
…sed.
  • Loading branch information
mxsasha committed Jul 8, 2019
1 parent 2172c52 commit 11f252e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
15 changes: 15 additions & 0 deletions irrd/updates/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def save(self, database_handler: DatabaseHandler) -> None:
logger.info(f'{id(self)}: Saving change for {self.rpsl_obj_new}: deleting current object')
database_handler.delete_rpsl_object(self.rpsl_obj_current)
else:
if not self.used_override:
self.rpsl_obj_new.overwrite_date_new_changed_attributes(self.rpsl_obj_current)
# This call may have emitted a new info message.
self._import_new_rpsl_obj_info_messages()
logger.info(f'{id(self)}: Saving change for {self.rpsl_obj_new}: inserting/updating current object')
database_handler.upsert_rpsl_object(self.rpsl_obj_new)
self.status = UpdateRequestStatus.SAVED
Expand Down Expand Up @@ -251,6 +255,17 @@ def _check_references(self) -> bool:
logger.debug(f'{id(self)}: Reference check succeeded')
return True

def _import_new_rpsl_obj_info_messages(self):
"""
Import new info messages from self.rpsl_obj_new.
This is used after overwrite_date_new_changed_attributes()
is called, as it's called just before saving, but may
emit a new info message.
"""
for info_message in self.rpsl_obj_new.messages.infos():
if info_message not in self.info_messages:
self.info_messages.append(info_message)


def parse_change_requests(requests_text: str,
database_handler: DatabaseHandler,
Expand Down
26 changes: 19 additions & 7 deletions irrd/updates/tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: noqa: W293

import datetime
import textwrap
from unittest.mock import Mock

Expand Down Expand Up @@ -183,7 +183,8 @@ def test_parse_valid_new_person_existing_mntner_pgp_key(self, prepare_mocks):
assert mock_dh.mock_calls[2][0] == 'commit'
assert mock_dh.mock_calls[3][0] == 'close'

assert handler.submitter_report() == textwrap.dedent("""
expected_changed_date = datetime.datetime.now().strftime('%Y%m%d')
assert handler.submitter_report() == textwrap.dedent(f"""
> Message-ID: test
> From: example@example.com
Expand All @@ -201,18 +202,29 @@ def test_parse_valid_new_person_existing_mntner_pgp_key(self, prepare_mocks):
Delete: 0
DETAILED EXPLANATION:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
Create succeeded: [person] PERSON-TEST
person: Placeholder Person Object
address: The Netherlands
phone: +31 20 000 0000
nic-hdl: PERSON-TEST
mnt-by: TEST-MNT
e-mail: email@example.com
changed: changed@example.com 20190701 # comment
source: TEST
INFO: Set date in changed line "changed@example.com 20190701 # comment" to today.
---
Modify succeeded: [mntner] TEST-MNT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
""")

expected_notification = textwrap.dedent("""
expected_notification = textwrap.dedent(f"""
This is to notify you of changes in the TEST database
or object authorisation failures.
Expand Down Expand Up @@ -241,7 +253,7 @@ def test_parse_valid_new_person_existing_mntner_pgp_key(self, prepare_mocks):
nic-hdl: PERSON-TEST
mnt-by: TEST-MNT
e-mail: email@example.com
changed: changed@example.com 20190701 # comment
changed: changed@example.com {expected_changed_date} # comment
source: TEST
---
Expand Down

0 comments on commit 11f252e

Please sign in to comment.