Пример #1
0
    def test_patch_missing_id(self, mock_get_db_connection):
        """Raises an error when the resource id was not provided at init"""
        r = Resource(resource='test')

        with pytest.raises(OperationOutcome, match='Resource ID is required to \
patch a resource'):
            r = r.patch({'some': 'patch'})
        assert mock_get_db_connection.return_value.update.call_count == 0
Пример #2
0
    def test_patch_missing_data(self, mock_get_db_connection):
        """Raises an error when the patch data is not provided
        """
        test_id = {'id': 'id'}
        r = Resource(id=test_id['id'])

        with pytest.raises(OperationOutcome, match='Patch data is required to \
patch a resource'):
            r = r.patch(None)
        assert mock_get_db_connection.return_value.update.call_count == 0
Пример #3
0
    def test_patch(self, mock_get_db_connection):
        """Applies a patch on the resource by reading and then updating it
        """
        test_id = {'id': 'id'}
        patch_data = {'test': 'two'}
        read_ret_data = {'my': 'resource', **test_id}
        update_ret_data = {**read_ret_data, **patch_data, **test_id}
        mock_get_db_connection.return_value.read.return_value = read_ret_data
        mock_get_db_connection.return_value.update.return_value = \
            update_ret_data
        r = Resource(id=test_id['id'])

        r = r.patch(patch_data)
        mock_get_db_connection.return_value.read.assert_called_once_with({
            'resourceType': 'Resource',
            'id': r.id
        })
        mock_get_db_connection.return_value.update.assert_called_once_with({
            'resourceType': 'Resource',
            **read_ret_data,
            **patch_data
        })
        assert r.resource == update_ret_data
        assert r.id == test_id['id']