コード例 #1
0
 def test_already_tracked(self, ) -> None:
     report = self._build_report(
         report_id=123,
         tracking_status='T',
         logs=[
             TrackingStatusLog(
                 created_at='2021-01-01T00:00:00+00:00',
                 log_id=1,
                 log_type='tracking-status',
                 private=True,
                 author=Author(username='******', ),
                 message_html='Tracked',
                 attachments=[],
                 tracker_name='my-tracker',
                 tracker_url='http://tracker/issue/1',
                 tracker_id='1',
             ),
         ],
     )
     ywh_api_client_mock = create_autospec(YesWeHackApiClient,
                                           spec_set=True)
     tracker_client_mock = create_autospec(TrackerClient, spec_set=True)
     tracker_client_mock.tracker_type = 'MyTracker'
     tracker_client_mock.get_tracker_issue.return_value = TrackerIssue(
         tracker_url='http://tracker/issue/1',
         project='my-project',
         issue_id='1',
         issue_url='http://tracker/issue/1',
         closed=False,
     )
     Given(
         case=self,
         report=report,
         yeswehack_client=ywh_api_client_mock,
         tracker_name='my-tracker',
         tracker_client=tracker_client_mock,
         synchronize_options=SynchronizeOptions(
             upload_private_comments=True,
             upload_public_comments=True,
             upload_details_updates=True,
             upload_rewards=True,
             upload_status_updates=True,
         ),
         feedback_options=FeedbackOptions(),
         message_formatter=SimpleMessageFormatter(
             tracking_status_update_format=
             'issue url: {tracker_issue.issue_url}',
             synchronization_done_format=
             'issue url: {send_logs_result.tracker_issue.issue_url}',
             download_comment_format='comment: {comment}',
             status_update_comment_format='comment: {comment}',
         ),
     ).when_synchronize_report().then_assert_no_error(
     ).then_assert_has_result().then_assert_is_existing_issue(
     ).then_assert_tracker_client_send_report_not_called(
     ).then_assert_tracker_client_send_logs_not_called(
     ).then_assert_yeswehack_client_put_report_tracking_status_not_called()
コード例 #2
0
 def test_new_afi_no_logs(self, ) -> None:
     report = self._build_report(
         report_id=123,
         tracking_status='AFI',
     )
     ywh_api_client_mock = create_autospec(YesWeHackApiClient,
                                           spec_set=True)
     tracker_client_mock = create_autospec(TrackerClient, spec_set=True)
     tracker_client_mock.tracker_type = 'MyTracker'
     tracker_client_mock.send_report.return_value = TrackerIssue(
         tracker_url='http://tracker/issue/1',
         project='my-project',
         issue_id='1',
         issue_url='http://tracker/issue/1',
         closed=False,
     )
     Given(
         case=self,
         report=report,
         yeswehack_client=ywh_api_client_mock,
         tracker_name='my-tracker',
         tracker_client=tracker_client_mock,
         synchronize_options=SynchronizeOptions(
             upload_private_comments=True,
             upload_public_comments=True,
             upload_details_updates=True,
             upload_rewards=True,
             upload_status_updates=True,
         ),
         feedback_options=FeedbackOptions(),
         message_formatter=SimpleMessageFormatter(
             tracking_status_update_format=
             'issue url: {tracker_issue.issue_url}',
             synchronization_done_format=
             'issue url: {send_logs_result.tracker_issue.issue_url}',
             download_comment_format='comment: {comment}',
             status_update_comment_format='comment: {comment}',
         ),
     ).when_synchronize_report().then_assert_no_error(
     ).then_assert_has_result().then_assert_is_not_existing_issue(
     ).then_assert_tracker_client_send_report_called_once_with(
         report=report,
     ).then_assert_tracker_client_send_logs_not_called(
     ).then_assert_yeswehack_client_put_report_tracking_status_called_once_with(
         report=report,
         status='T',
         tracker_name='my-tracker',
         issue_id='1',
         issue_url='http://tracker/issue/1',
         comment='issue url: http://tracker/issue/1',
     )
コード例 #3
0
 def test_partially_synced(self, ) -> None:
     comment_log1 = CommentLog(
         created_at='2021-01-01T00:00:00+00:00',
         log_id=1,
         log_type='comment',
         private=True,
         author=Author(username='******', ),
         message_html='This is a comment',
         attachments=[],
     )
     tracking_status = TrackingStatusLog(
         created_at='2021-01-01T00:30:00+00:00',
         log_id=1,
         log_type='tracking-status',
         private=True,
         author=Author(username='******', ),
         message_html='Tracked',
         attachments=[],
         tracker_name='my-tracker',
         tracker_url='http://tracker/issue/1',
         tracker_id='1',
     )
     tracker_update_log1 = TrackerUpdateLog(
         created_at='2021-01-01T01:00:00+00:00',
         log_id=2,
         log_type='tracker-update',
         private=True,
         author=Author(username='******', ),
         message_html='This is a a tracker update',
         attachments=[],
         tracker_name='my-tracker',
         tracker_id='1',
         tracker_url='http://tracker/issue/1',
         tracker_token=StateEncryptor.encrypt(
             key='123',
             state=TrackerIssueState(
                 closed=False,
                 bugtracker_name='my-tracker',
             ),
         ),
     )
     comment_log2 = CommentLog(
         created_at='2021-01-01T02:00:00+00:00',
         log_id=3,
         log_type='comment',
         private=True,
         author=Author(username='******', ),
         message_html='This is another comment',
         attachments=[],
     )
     report = self._build_report(
         report_id=123,
         tracking_status='T',
         logs=[
             comment_log1,
             tracking_status,
             tracker_update_log1,
             comment_log2,
         ],
     )
     ywh_api_client_mock = create_autospec(YesWeHackApiClient,
                                           spec_set=True)
     tracker_client_mock = create_autospec(TrackerClient, spec_set=True)
     tracker_client_mock.tracker_type = 'MyTracker'
     issue = TrackerIssue(
         tracker_url='http://tracker/issue/1',
         project='my-project',
         issue_id='1',
         issue_url='http://tracker/issue/1',
         closed=False,
     )
     tracker_client_mock.get_tracker_issue.return_value = issue
     tracker_client_mock.send_logs.return_value = SendLogsResult(
         tracker_issue=issue,
         added_comments=[
             TrackerIssueComment(
                 created_at=datetime.datetime(
                     year=2020,
                     month=1,
                     day=1,
                     hour=15,
                     minute=17,
                     second=23,
                     microsecond=420000,
                     tzinfo=datetime.timezone.utc,
                 ),
                 author='tracker-user',
                 comment_id='456',
                 body='',
                 attachments={},
             ),
         ],
     )
     Given(
         case=self,
         report=report,
         yeswehack_client=ywh_api_client_mock,
         tracker_name='my-tracker',
         tracker_client=tracker_client_mock,
         synchronize_options=SynchronizeOptions(
             upload_private_comments=True,
             upload_public_comments=True,
             upload_details_updates=True,
             upload_rewards=True,
             upload_status_updates=True,
         ),
         feedback_options=FeedbackOptions(),
         message_formatter=SimpleMessageFormatter(
             tracking_status_update_format=
             'issue url: {tracker_issue.issue_url}',
             synchronization_done_format=
             'issue url: {send_logs_result.tracker_issue.issue_url}',
             download_comment_format='comment: {comment}',
             status_update_comment_format='comment: {comment}',
         ),
     ).when_synchronize_report().then_assert_no_error(
     ).then_assert_has_result().then_assert_is_existing_issue(
     ).then_assert_tracker_client_send_report_not_called(
     ).then_assert_tracker_client_send_logs_called_once_with(
         tracker_issue=issue,
         logs=[
             comment_log2,
         ],
     ).then_assert_yeswehack_client_post_report_tracker_update_called_once_with(
         report=report,
         tracker_name='my-tracker',
         issue_id='1',
         issue_url='http://tracker/issue/1',
         comment='issue url: http://tracker/issue/1',
         token=StateEncryptor.encrypt(
             key='123',
             state=TrackerIssueState(closed=False,
                                     bugtracker_name='my-tracker',
                                     downloaded_comments=['456']),
         ),
     )