示例#1
0
"""
from mock import patch
from rest_framework import status

from core_main_app.components.data.models import Data
from core_main_app.components.workspace.models import Workspace
from core_main_app.rest.data import views as data_rest_views
from core_main_app.utils.integration_tests.integration_base_test_case import \
    MongoIntegrationBaseTestCase
from core_main_app.utils.tests_tools.MockUser import create_mock_user
from core_main_app.utils.tests_tools.RequestMock import RequestMock
from tests.components.data.fixtures.fixtures import DataFixtures, QueryDataFixtures, AccessControlDataFixture

fixture_data = DataFixtures()
fixture_data_query = QueryDataFixtures()
fixture_data_workspace = AccessControlDataFixture()


class TestDataList(MongoIntegrationBaseTestCase):
    fixture = fixture_data

    def setUp(self):
        super(TestDataList, self).setUp()

    @patch.object(Data, 'xml_content')
    def test_get_returns_http_200(self, mock_xml_content):
        # Arrange
        user = create_mock_user('1')
        mock_xml_content.return_value = "content"

        # Act
from core_main_app.components.data.models import Data
from core_main_app.utils.integration_tests.integration_base_test_case import (
    MongoIntegrationBaseTestCase, )

from tests.components.data.fixtures.fixtures import AccessControlDataFixture

# FIXME move other tests (from tests_int.py) here
ordering_data_fixture = AccessControlDataFixture()


class TestGetAllByListTemplate(MongoIntegrationBaseTestCase):
    fixture = ordering_data_fixture

    def test_get_all_by_list_template_data_ordering(self):
        # Arrange
        template = self.fixture.template.id
        ascending_order_by_field = ["+title"]
        descending_order_by_field = ["-title"]
        # Act
        ascending_result = Data.get_all_by_list_template(
            [template], ascending_order_by_field)
        descending_result = Data.get_all_by_list_template(
            [template], descending_order_by_field)
        # Assert
        for i in range(len(ascending_result)):
            self.assertTrue(ascending_result.all()[i].title ==
                            descending_result.all()[len(ascending_result) - i -
                                                    1].title)

    def test_get_all_by_list_template_data_ascending_sorting(self):
        # Arrange
示例#3
0
""" Access control testing
"""
import unittest

from mock.mock import patch

from core_main_app.components.data import api as data_api
from core_main_app.components.data.models import Data
from core_main_app.access_control.exceptions import AccessControlError
from core_main_app.utils.integration_tests.integration_base_test_case import MongoIntegrationBaseTestCase
from core_main_app.utils.tests_tools.MockUser import create_mock_user
from tests.components.data.fixtures.fixtures import AccessControlDataFixture

fixture_data = AccessControlDataFixture()

# NOTE: Uncomment to test in debug
# from django.conf import settings
# settings.INSTALLED_APPS = ['core_workspace_app']


class TestDataGetById(MongoIntegrationBaseTestCase):

    fixture = fixture_data

    @patch(
        'core_main_app.components.workspace.api.get_all_workspaces_with_read_access_by_user'
    )
    def test_get_by_id_owner_with_read_access_returns_data(
            self, get_all_workspaces_with_read_access_by_user):
        data_id = self.fixture.data_collection[
            fixture_data.USER_1_WORKSPACE_1].id
示例#4
0
""" Unit Test Data
"""
from bson.objectid import ObjectId

from core_main_app.commons import exceptions
from core_main_app.components.data.models import Data
from core_main_app.components.data import api as data_api
from core_main_app.utils.tests_tools.MockUser import create_mock_user
from core_main_app.utils.integration_tests.integration_base_test_case import MongoIntegrationBaseTestCase
from core_main_app.settings import DATA_SORTING_FIELDS
from tests.components.data.fixtures.fixtures import DataFixtures, AccessControlDataFixture

fixture_data = DataFixtures()
access_control_data_fixture = AccessControlDataFixture()


class TestDataGetAll(MongoIntegrationBaseTestCase):

    fixture = access_control_data_fixture

    def test_data_get_all_return_collection_of_data(self):
        # Act
        result = Data.get_all(DATA_SORTING_FIELDS)
        # Assert
        self.assertTrue(all(isinstance(item, Data) for item in result))

    def test_data_get_all_return_objects_data_in_collection(self):
        # Act
        result = Data.get_all(DATA_SORTING_FIELDS)
        # Assert
        self.assertTrue(len(self.fixture.data_collection) == result.count())