Exemplo n.º 1
0
    def test_nr_of_inactive_actions_invalid_json(self, mock_url_read,
                                                 mock_error, mock_write_json,
                                                 mock_read_json):
        """ Test that the number of inactive tasks returns -1 when 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_inactive_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],
                              json.decoder.JSONDecodeError)
    def test_nr_of_inactive_actions_no_tasks(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of inactive tasks is 0 when no tasks are provided. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}', '{"value": []}']
        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_inactive_actions('plan_id_xx'), 0)
    def test_nr_of_inactive_actions_no_tasks(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of inactive tasks is 0 when no tasks are provided. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}', '{"value": []}']
        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_inactive_actions('plan_id_xx'), 0)
    def test_nr_of_inactive_actions_http_error(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of inactive 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_inactive_actions('plan_id_xx'), -1)
    def test_nr_of_inactive_actions_http_error(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of inactive 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_inactive_actions('plan_id_xx'), -1)
    def test_nr_of_inactive_actions_due_null(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the task without due date is counted as inactive. """
        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": 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_inactive_actions('plan_id_xx'), 1)
    def test_nr_of_inactive_actions_due_null(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the task without due date is counted as inactive. """
        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": 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_inactive_actions('plan_id_xx'), 1)
    def test_nr_of_inactive_actions_less_than_limit(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the task inactive for less than 14 days is not counted as inactive. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"' + (
                datetime.datetime.utcnow() - relativedelta(days=13)).strftime("%Y-%m-%dT%H:%M:%S.%fZ") + '",'
            '"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_inactive_actions('plan_id_xx'), 0)
    def test_nr_of_inactive_actions_invalid_json(self, mock_url_read, mock_error, mock_write_json, mock_read_json):
        """ Test that the number of inactive tasks returns -1 when 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_inactive_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], json.decoder.JSONDecodeError)
Exemplo n.º 10
0
    def test_nr_of_inactive_actions_less_than_limit(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the task inactive for less than 14 days is not counted as inactive. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"' + (
                datetime.datetime.utcnow() - relativedelta(days=13)).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_inactive_actions('plan_id_xx'), 0)
Exemplo n.º 11
0
    def test_nr_of_inactive_actions_ignore_list(self, mock_url_read, mock_write_json, mock_read_json):
        """ Test that the number of inactive tasks matches. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"name": "ToDo", "planId": "plan_id_xx", "id": "1a"}]}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"2018-02-28T13:01:08.8386828Z",'
            '"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=', lists_to_ignore=['ToDo'],
                                    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_inactive_actions('plan_id_xx'), 0)
Exemplo n.º 12
0
    def test_nr_of_inactive_actions_ignore_list(self, mock_url_read,
                                                mock_write_json,
                                                mock_read_json):
        """ Test that the number of inactive tasks matches. """
        mock_url_read.side_effect = [
            '{"access_token": "ey_xx", "refresh_token": "new_refresh_token"}',
            '{"value": [{"name": "ToDo", "planId": "plan_id_xx", "id": "1a"}]}',
            '{"value": [{"completedDateTime": null, "createdDateTime":"2018-02-28T13:01:08.8386828Z",'
            '"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=',
            lists_to_ignore=['ToDo'],
            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_inactive_actions('plan_id_xx'), 0)