Exemple #1
0
    def test_after_publishes_payload(self, mock_get_original_resource,
                                     mock_publish):
        n = NotificationHook()

        sample_original_task = TaskWmodel.from_db_model(
            Task(id=1,
                 creator_id=1,
                 title='Test',
                 status='inprogress',
                 story_id=1,
                 project_id=1,
                 assignee_id=1,
                 priority='medium'))

        sample_modified_task = TaskWmodel.from_db_model(
            Task(id=1,
                 creator_id=1,
                 title='Test',
                 status='merged',
                 story_id=1,
                 project_id=1,
                 assignee_id=1,
                 priority='medium'))

        sot_json = tojson(TaskWmodel, sample_original_task)
        smt_json = tojson(TaskWmodel, sample_modified_task)

        # Mocking state object to simulate a 'PUT' request for task
        # resource 1
        mock_state = Mock()
        mock_state.request.current_user_id = '1'
        mock_state.request.method = 'PUT'
        mock_state.request.headers = {'Referer': 'http://localhost/'}
        mock_state.request.query_string = ''
        mock_state.request.path = '/v1/tasks/1'
        mock_state.response.status_code = 200
        mock_state.old_entity_values = sot_json
        mock_get_original_resource.return_value = smt_json

        n.after(mock_state)
        mock_publish.assert_called_with(
            author_id=mock_state.request.current_user_id,
            method=mock_state.request.method,
            url=mock_state.request.headers['Referer'],
            path=mock_state.request.path,
            query_string=mock_state.request.query_string,
            status=mock_state.response.status_code,
            resource='task',
            resource_id='1',
            sub_resource=None,
            sub_resource_id=None,
            resource_before=sot_json,
            resource_after=smt_json)
    def test_after_publishes_payload(self, mock_get_original_resource,
                                     mock_publish):
        n = NotificationHook()

        sample_original_task = TaskWmodel.from_db_model(Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='inprogress',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium'))

        sample_modified_task = TaskWmodel.from_db_model(Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='merged',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium'))

        sot_json = tojson(TaskWmodel, sample_original_task)
        smt_json = tojson(TaskWmodel, sample_modified_task)

        # Mocking state object to simulate a 'PUT' request for task
        # resource 1
        mock_state = Mock()
        mock_state.request.current_user_id = '1'
        mock_state.request.method = 'PUT'
        mock_state.request.headers = {'Referer': 'http://localhost/'}
        mock_state.request.query_string = ''
        mock_state.request.path = '/v1/tasks/1'
        mock_state.response.status_code = 200
        mock_state.old_entity_values = sot_json
        mock_get_original_resource.return_value = smt_json

        n.after(mock_state)
        mock_publish.assert_called_with(
            author_id=mock_state.request.current_user_id,
            method=mock_state.request.method,
            url=mock_state.request.headers['Referer'],
            path=mock_state.request.path,
            query_string=mock_state.request.query_string,
            status=mock_state.response.status_code,
            resource='task',
            resource_id='1',
            sub_resource=None,
            sub_resource_id=None,
            resource_before=sot_json,
            resource_after=smt_json)
Exemple #3
0
    def test_get_original_resource_valid_options(self, mock_entity_get):
        """Assert that the get_original_resource method behaves as expected
        when receiving valid values.
        """
        n = NotificationHook()

        # Mock entity_get method to return a sample Task
        sample_task = Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='inprogress',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium')
        mock_entity_get.return_value = sample_task

        sample_task_wmodel = TaskWmodel.from_db_model(sample_task)
        old_entity_values = n.get_original_resource('task', 1)

        self.assertEqual(old_entity_values['id'], sample_task_wmodel.id)
        self.assertEqual(old_entity_values['creator_id'],
                         sample_task_wmodel.creator_id)
        self.assertEqual(old_entity_values['title'], sample_task_wmodel.title)
        self.assertEqual(old_entity_values['status'],
                         sample_task_wmodel.status)
        self.assertEqual(old_entity_values['story_id'],
                         sample_task_wmodel.story_id)
        self.assertEqual(old_entity_values['project_id'],
                         sample_task_wmodel.project_id)
        self.assertEqual(old_entity_values['assignee_id'],
                         sample_task_wmodel.assignee_id)
        self.assertEqual(old_entity_values['priority'],
                         sample_task_wmodel.priority)
    def test_old_entity_values_set_on_state_by_before(self, mock_entity_get):
        """Tests that the values of the resource being changed by the
        request are retrieved in the before method and stored in the
        state object as variable 'old_returned_values'.
        """
        n = NotificationHook()

        # Mocking state object to simulate a 'PUT' request for task
        # resource 1
        mock_state = Mock()
        mock_state.request.method = 'PUT'
        mock_state.request.path = '/v1/tasks/1'

        # Mock entity_get method to return a sample Task
        sample_task = Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='inprogress',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium')
        mock_entity_get.return_value = sample_task

        sample_task_wmodel = TaskWmodel.from_db_model(sample_task)
        n.before(mock_state)

        self.assertEqual(mock_state.old_entity_values['id'],
                         sample_task_wmodel.id)
        self.assertEqual(mock_state.old_entity_values['creator_id'],
                         sample_task_wmodel.creator_id)
        self.assertEqual(mock_state.old_entity_values['title'],
                         sample_task_wmodel.title)
        self.assertEqual(mock_state.old_entity_values['status'],
                         sample_task_wmodel.status)
        self.assertEqual(mock_state.old_entity_values['story_id'],
                         sample_task_wmodel.story_id)
        self.assertEqual(mock_state.old_entity_values['project_id'],
                         sample_task_wmodel.project_id)
        self.assertEqual(mock_state.old_entity_values['assignee_id'],
                         sample_task_wmodel.assignee_id)
        self.assertEqual(mock_state.old_entity_values['priority'],
                         sample_task_wmodel.priority)
Exemple #5
0
    def test_old_entity_values_set_on_state_by_before(self, mock_entity_get):
        """Tests that the values of the resource being changed by the
        request are retrieved in the before method and stored in the
        state object as variable 'old_returned_values'.
        """
        n = NotificationHook()

        # Mocking state object to simulate a 'PUT' request for task
        # resource 1
        mock_state = Mock()
        mock_state.request.method = 'PUT'
        mock_state.request.path = '/v1/tasks/1'

        # Mock entity_get method to return a sample Task
        sample_task = Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='inprogress',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium')
        mock_entity_get.return_value = sample_task

        sample_task_wmodel = TaskWmodel.from_db_model(sample_task)
        n.before(mock_state)

        self.assertEqual(mock_state.old_entity_values['id'],
                         sample_task_wmodel.id)
        self.assertEqual(mock_state.old_entity_values['creator_id'],
                         sample_task_wmodel.creator_id)
        self.assertEqual(mock_state.old_entity_values['title'],
                         sample_task_wmodel.title)
        self.assertEqual(mock_state.old_entity_values['status'],
                         sample_task_wmodel.status)
        self.assertEqual(mock_state.old_entity_values['story_id'],
                         sample_task_wmodel.story_id)
        self.assertEqual(mock_state.old_entity_values['project_id'],
                         sample_task_wmodel.project_id)
        self.assertEqual(mock_state.old_entity_values['assignee_id'],
                         sample_task_wmodel.assignee_id)
        self.assertEqual(mock_state.old_entity_values['priority'],
                         sample_task_wmodel.priority)
    def test_get_original_resource_valid_options(self, mock_entity_get):
        """Assert that the get_original_resource method behaves as expected
        when receiving valid values.
        """
        n = NotificationHook()

        # Mock entity_get method to return a sample Task
        sample_task = Task(id=1,
                           creator_id=1,
                           title='Test',
                           status='inprogress',
                           story_id=1,
                           project_id=1,
                           assignee_id=1,
                           priority='medium')
        mock_entity_get.return_value = sample_task

        sample_task_wmodel = TaskWmodel.from_db_model(sample_task)
        old_entity_values = n.get_original_resource('task', 1)

        self.assertEqual(old_entity_values['id'],
                         sample_task_wmodel.id)
        self.assertEqual(old_entity_values['creator_id'],
                         sample_task_wmodel.creator_id)
        self.assertEqual(old_entity_values['title'],
                         sample_task_wmodel.title)
        self.assertEqual(old_entity_values['status'],
                         sample_task_wmodel.status)
        self.assertEqual(old_entity_values['story_id'],
                         sample_task_wmodel.story_id)
        self.assertEqual(old_entity_values['project_id'],
                         sample_task_wmodel.project_id)
        self.assertEqual(old_entity_values['assignee_id'],
                         sample_task_wmodel.assignee_id)
        self.assertEqual(old_entity_values['priority'],
                         sample_task_wmodel.priority)