Example #1
0
    def test_nr_of_over_due_actions_invalid_time(self, mock_url_read,
                                                 mock_error, mock_write_json,
                                                 mock_read_json):
        """ Test that the number of overdue tasks returns -1 when json is invalid. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"non-value": [{"completedDateTime": null, '
            '"createdDateTime":"2018-02-28T11:01:08.8386828Z","assignments": {}}]}'
        ]
        mock_read_json.return_value = {
            'refresh_token': 'refresh_token_content_xx'
        }
        planner = SharepointPlanner(
            url='/home',
            client_id='client_id_xx',
            client_secret='client_secret_k=',
            refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with(
            {'refresh_token': 'new_refresh_token'},
            'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        self.assertEqual('Invalid json retrieved for tasks. Reason: %s.',
                         mock_error.call_args_list[0][0][0])
        self.assertIsInstance(mock_error.call_args_list[0][0][1], KeyError)
    def test_nr_of_over_due_actions_empty_refresh_json(self, mock_url_read, mock_info, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when refresh token file is empty. """
        mock_read_json.return_value = ''
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_not_called()
        mock_info.assert_called_once_with(
            'No refresh token could be loaded. Please, generate one using the script refresh_token_generator.py.')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        mock_url_read.assert_not_called()
    def test_nr_of_over_due_actions_http_error(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when http error occurs. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            urllib.error.HTTPError(None, None, None, None, None)]
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
    def test_nr_of_over_due_actions_empty_refresh_json(self, mock_url_read, mock_info, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when refresh token file is empty. """
        mock_read_json.return_value = ''
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_not_called()
        mock_info.assert_called_once_with(
            'No refresh token could be loaded. Please, generate one using the script refresh_token_generator.py.')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        mock_url_read.assert_not_called()
    def test_nr_of_over_due_actions_http_error(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when http error occurs. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            urllib.error.HTTPError(None, None, None, None, None)]
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
    def test_nr_of_over_due_actions_date_null(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks does not count tasks with empty due date. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"2018-02-28T13:01:08.838Z", "dueDateTime": null,'
            '"assignments": {"ecf0xx": {"assignedDateTime": "2018-02-28T13:01:08.8386828Z"}}}]}']
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), 0)
    def test_nr_of_over_due_actions_date_null(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks does not count tasks with empty due date. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"2018-02-28T13:01:08.838Z", "dueDateTime": null,'
            '"bucketId": "1a", "assignments": {"ecf0xx": {"assignedDateTime": "2018-02-28T13:01:08.8386828Z"}}}]}']
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), 0)
    def test_nr_of_over_due_actions_invalid_json(self, mock_url_read, mock_error, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when tasks json is invalid. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            'non-json']
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        self.assertEqual('Invalid json retrieved for tasks. Reason: %s.', mock_error.call_args_list[0][0][0])
        self.assertIsInstance(mock_error.call_args_list[0][0][1], ValueError)
    def test_nr_of_over_due_actions_invalid_json(self, mock_url_read, mock_error, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when tasks json is invalid. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            'non-json']
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        self.assertEqual('Invalid json retrieved for tasks. Reason: %s.', mock_error.call_args_list[0][0][0])
        self.assertIsInstance(mock_error.call_args_list[0][0][1], ValueError)
    def test_nr_of_over_due_actions_invalid_time(self, mock_url_read, mock_error, mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks returns -1 when json is invalid. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"non-value": [{"completedDateTime": null, '
            '"createdDateTime":"2018-02-28T11:01:08.8386828Z","assignments": {}}]}']
        mock_read_json.return_value = {'refresh_token': 'refresh_token_content_xx'}
        planner = SharepointPlanner(url='/home', client_id='client_id_xx',
                                    client_secret='client_secret_k=',
                                    refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with({'refresh_token': 'new_refresh_token'}, 'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), -1)
        self.assertEqual('Invalid json retrieved for tasks. Reason: %s.', mock_error.call_args_list[0][0][0])
        self.assertIsInstance(mock_error.call_args_list[0][0][1], KeyError)
Example #11
0
    def test_nr_of_over_due_actions_future(self, mock_url_read,
                                           mock_write_json, mock_read_json):
        """ Test that the number of overdue tasks does not count tasks with due date in the future. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"2018-02-28T13:01:08.828Z", "dueDateTime": "'
            + (datetime.datetime.utcnow() +
               relativedelta(days=1)).strftime("%Y-%m-%dT%H:%M:%S.%fZ") + '",'
            '"bucketId": "1a", "assignments": {"ecf0xx": {"assignedDateTime": "2018-02-28T13:01:08.8386828Z"}}}]}'
        ]
        mock_read_json.return_value = {
            'refresh_token': 'refresh_token_content_xx'
        }
        planner = SharepointPlanner(
            url='/home',
            client_id='client_id_xx',
            client_secret='client_secret_k=',
            refresh_token_location='file_location_of_token.json')

        mock_write_json.assert_called_once_with(
            {'refresh_token': 'new_refresh_token'},
            'file_location_of_token.json')
        self.assertEqual(planner.nr_of_over_due_actions('plan_id_xx'), 0)