Beispiel #1
0
 def test_get_all_by_list_workspace_data_ordering(self):
     # Arrange
     workspace = self.fixture.workspace_1.id
     ascending_order_by_field = ["+title"]
     descending_order_by_field = ["-title"]
     # Act
     ascending_result = Data.get_all_by_list_workspace([workspace], ascending_order_by_field)
     descending_result = Data.get_all_by_list_workspace([workspace], 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)
Beispiel #2
0
    def test_get_all_by_list_workspace_multi_field_sorting(self):
        # Arrange
        ascending_order_by_multi_field = ["+workspace", "+title"]
        descending_order_by_multi_field = ["+workspace", "-title"]
        workspace = self.fixture.workspace_1.id
        # Act
        ascending_result = Data.get_all_by_list_workspace([workspace], ascending_order_by_multi_field)
        descending_result = Data.get_all_by_list_workspace([workspace], descending_order_by_multi_field)
        # Assert
        self.assertEqual(self.fixture.data_3.user_id, ascending_result.all()[0].user_id)
        self.assertEqual(self.fixture.data_5.user_id, ascending_result.all()[1].user_id)

        self.assertEqual(self.fixture.data_3.user_id, descending_result.all()[1].user_id)
        self.assertEqual(self.fixture.data_5.user_id, descending_result.all()[0].user_id)
Beispiel #3
0
 def test_get_all_by_list_workspace_data_descending_sorting(self):
     # Arrange
     descending_order_by_field = ["-title"]
     workspace = self.fixture.workspace_1.id
     # Act
     descending_result = Data.get_all_by_list_workspace([workspace], descending_order_by_field)
     # Assert
     self.assertTrue(self.fixture.data_5.title == descending_result.all()[len(descending_result)-2].title)
     self.assertTrue(self.fixture.data_3.title == descending_result.all()[len(descending_result)-1].title)
Beispiel #4
0
 def test_get_all_by_list_workspace_data_ascending_sorting(self):
     # Arrange
     ascending_order_by_field = ["+title"]
     workspace = self.fixture.workspace_1.id
     # Act
     ascending_result = Data.get_all_by_list_workspace([workspace], ascending_order_by_field)
     # Assert
     self.assertTrue(self.fixture.data_3.title == ascending_result.all()[0].title)
     self.assertTrue(self.fixture.data_5.title == ascending_result.all()[1].title)
Beispiel #5
0
def get_all_data_in_workspaces(workspace_list):
    """Get all data stored in a list of workspace

    Args:
        workspace_list:

    Returns:

    """
    return Data.get_all_by_list_workspace(workspace_list, DATA_SORTING_FIELDS)
Beispiel #6
0
def get_all_accessible_by_user(user):
    """ Return all data accessible by a user.

        Parameters:
            user:

        Returns: data collection
    """

    read_workspaces = workspace_api.get_all_workspaces_with_read_access_by_user(
        user)
    write_workspaces = workspace_api.get_all_workspaces_with_write_access_by_user(
        user)
    user_accessible_workspaces = list(set().union(read_workspaces,
                                                  write_workspaces))

    accessible_data = Data.get_all_by_list_workspace(
        user_accessible_workspaces)
    owned_data = get_all_by_user(user)

    return list(set().union(owned_data, accessible_data))