Ejemplo n.º 1
0
 def setUp(self):
     schema = create_default_schema()
     self.users = create_sample_users()
     self.client = client_for_testing(schema, self.users[0])
     regions = create_sample_regions(Region)
     self.projects = create_sample_projects(get_project_model(), self.users, regions)
     self.locations = create_local_sample_locations(get_location_schema()['model_class'])
Ejemplo n.º 2
0
 def setUp(self):
     users = create_sample_users()
     self.client = client_for_testing(schema, users[0])
     self.locations = create_local_sample_locations(get_location_schema()['model_class'])
     self.regions = create_sample_regions(Region)
     self.projects = create_sample_projects(Project, users, self.regions)
     for project in self.projects:
         project.locations.add(*self.locations)
 def setUp(self):
     users = create_sample_users()
     self.client = client_for_testing(schema, users[0])
     delete_sample_resources()
     self.region = R.head(create_sample_regions(Region))
     self.resources = create_sample_resources([self.region])
     # Create a graph for all resources
     # This modifies each node to have a node_index
     self.graph = create_sankey_graph_from_resources(self.resources)
Ejemplo n.º 4
0
def create_sample_user_states(
    cls,
    region_cls,
    project_cls,
    location_cls,
    search_location_cls,
    create_sample_locations=create_local_sample_locations,
    create_sample_search_locations=create_local_sample_search_locations,
    create_additional_scope_instance_properties=lambda user_scope_instance:
    user_scope_instance):
    """
    :param cls: The UserState class
    :param region_cls:
    :param project_cls:
    :param location_cls:
    :param search_location_cls:
    :param create_sample_locations: Defaults to create_local_sample_locations. Expects
    the location_cls as the only arg
    :param create_search_sample_locations: Defaults to create_local_sample_search_locations. Expects
    the serach_location_cls and a list of sample locations. The locations can be ignored
    if creating samples independent of the locations
    :param create_additional_scope_instance_properties Function that takes each user_scope_instance
    and adds properties to it if needed. This corresponds with schemas defined by users in
    additional_user_scope_schemas
    :return:
    """
    users = create_sample_users()
    # Create regions for the users to associate with. A region also needs and owner so we pass users to the function
    regions = create_sample_regions(region_cls)
    projects = create_sample_projects(project_cls, users, regions)
    locations = create_sample_locations(location_cls)
    search_locations = create_sample_search_locations(search_location_cls,
                                                      locations)
    # Assign all the locations to each project
    for project in projects:
        project.locations.add(*locations)

    # Merge search_locations into each userScope dict
    def sample_user_state_with_search_locations_and_additional_scope_instances(
            user_scope_name, sample_user_state):
        return R.fake_lens_path_set(
            f'data.{user_scope_name}'.split('.'),
            R.map(
                lambda user_scope: R.compose(
                    # Gives applications a chance to add the needed additional scope instances,
                    # e.g. userDesignFeatures
                    lambda user_scope:
                    create_additional_scope_instance_properties(user_scope),
                    lambda user_scope: R.merge(
                        user_scope,
                        dict(userSearch=dict(userSearchLocations=R.map(
                            lambda i_search_location: dict(
                                # Just return with the id since the full data is in the database
                                searchLocation=R.pick(['id'],
                                                      i_search_location[1]),
                                # Set the first search_location to active
                                activity=dict(isActive=i_search_location[0] ==
                                              0)),
                            enumerate(search_locations))))))(user_scope),
                R.item_str_path(f'data.{user_scope_name}', sample_user_state)),
            sample_user_state)

    # Convert all sample user_state dicts to persisted UserState instances
    # Use the username to match a real user
    user_states = R.map(
        lambda sample_user_state: create_sample_user_state(
            cls, regions, projects, sample_user_state),
        # Adds search_locations to each userState.data.[userRegions[*]|userProjects[*]].user_search.userSearchLocations
        R.compose(
            lambda sample_user_states: R.map(
                lambda sample_user_state:
                sample_user_state_with_search_locations_and_additional_scope_instances(
                    'userProjects', sample_user_state), sample_user_states),
            lambda sample_user_states: R.map(
                lambda sample_user_state:
                sample_user_state_with_search_locations_and_additional_scope_instances(
                    'userRegions', sample_user_state), sample_user_states),
        )(sample_user_states))
    return user_states
Ejemplo n.º 5
0
 def setUp(self):
     users = create_sample_users()
     self.client = client_for_testing(schema, users[0])
     self.regions = create_sample_regions(Region)
 def setUp(self):
     users = create_sample_users()
     self.client = client_for_testing(schema, users[0])
     self.settings = create_sample_settings_sets(Settings)