Beispiel #1
0
    def test_research_project_related_ex(self):
        '''Method returns an array of datasets - create new
        datasets to associate with new research project, count how many'''
        self.test_location = Location(name="location name here",
                                      latitude=6.08,
                                      longitude=2.2)
        self.test_location.save()

        self.rp_dataset_1 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.rp_dataset_1.save()
        self.rp_dataset_2 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.rp_dataset_2.save()

        self.research_project_dataset = ResearchProject(
            name="dataset test", start_date=datetime.now())
        self.research_project_dataset.save()

        self.rp_dataset_1.researchproject_set.add(
            self.research_project_dataset)
        self.rp_dataset_1.save()
        self.rp_dataset_2.researchproject_set.add(
            self.research_project_dataset)
        self.rp_dataset_2.save()

        self.assertEqual(len(self.research_project_dataset.related_ex()), 2)
Beispiel #2
0
    def test_forest_story_related_ex(self):
        '''Returns array of people and datasets'''
        self.test_location = Location(name="location name here",
                                      latitude=6.08,
                                      longitude=2.2)
        self.test_location.save()

        self.fs_dataset_1 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.fs_dataset_1.save()
        self.fs_dataset_2 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.fs_dataset_2.save()

        self.forest_story_dataset = ForestStory(name="dataset test")
        self.forest_story_dataset.save()

        self.fs_dataset_1.foreststory_set.add(self.forest_story_dataset)
        self.fs_dataset_1.save()
        self.fs_dataset_2.foreststory_set.add(self.forest_story_dataset)
        self.fs_dataset_2.save()
        self.assertEqual(len(self.forest_story_dataset.related_ex()), 2)
Beispiel #3
0
    def test_learning_activity_related_ex(self):
        '''Returns array of people and datasets'''
        self.test_location = Location(name="location name here",
                                      latitude=6.08,
                                      longitude=2.2)
        self.test_location.save()

        self.la_dataset_1 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.la_dataset_1.save()
        self.la_dataset_2 = DataSet(name="dataset test",
                                    description="This is a data set.",
                                    collection_start_date=datetime.now(),
                                    location=self.test_location)
        self.la_dataset_2.save()

        self.learning_activity_dataset = LearningActivity(name="dataset test")
        self.learning_activity_dataset.save()

        self.la_dataset_1.learningactivity_set.add(
            self.learning_activity_dataset)
        self.la_dataset_1.save()
        self.la_dataset_2.learningactivity_set.add(
            self.learning_activity_dataset)
        self.la_dataset_2.save()
        self.assertEquals(len(self.learning_activity_dataset.related_ex()), 2)
Beispiel #4
0
def process_metadata(result):
    created = False
    dataset = None

    try:
        the_id = result['dataset_id']
        dataset = DataSet.objects.get(blackrock_id=the_id)
    except DataSet.DoesNotExist:
        dataset = DataSet()
        created = True

    original_state = dict(dataset.__dict__)

    values = process_fieldnames(result)

    dataset = process_dataset_meta_fields(dataset, values)

    dataset.location = process_location(values)
    save_if_created(created, dataset)

    for field in dataset._meta.many_to_many:
        if field.name in list(values.keys()):
            related_model = apps.et_model("portal", field.name)
            for v in values[field.name]:
                if field.name == 'url':
                    v = settings.CDRS_SOLR_FILEURL + v
                related_obj, temp_created = \
                    related_model.objects.get_or_create(name=v.strip())
                dataset.__getattribute__(field.name).add(related_obj)

    dataset.audience.add(Audience.objects.get(name='Research'))

    save_if_dirty(original_state, dataset)

    return created
Beispiel #5
0
 def test_dataset_station_is_none(self):
     self.new_none_data_set_location = Location(name="New Dataset Location",
                                                latitude=6.08,
                                                longitude=2.2)
     self.new_none_data_set_location.save()
     self.new_none_dataset = DataSet(
         name="data set",
         description="This is a data set.",
         collection_start_date=datetime.now(),
         location=self.new_none_data_set_location)
     self.new_none_dataset.save()
     self.assertIsNone(self.new_none_dataset.station())
Beispiel #6
0
 def test_region_datasets(self):
     self.reg_location = Location(name="region test location name",
                                  latitude=6.08,
                                  longitude=2.2)
     self.reg_location.save()
     self.reg_dataset_1 = DataSet(name="region test data set",
                                  description="This is a data set.",
                                  collection_start_date=datetime.now(),
                                  location=self.reg_location)
     self.reg_dataset_1.save()
     self.reg_dataset_2 = DataSet(name="another region test data set",
                                  description="This is a data set.",
                                  collection_start_date=datetime.now(),
                                  location=self.reg_location)
     self.reg_dataset_2.save()
     self.reg_region = Region(
         name="Region Name",
         description="This is some region of blackrock.")
     self.reg_region.save()
     self.reg_location.region_set.add(self.reg_region)
     self.reg_location.save()
     self.assertIsNotNone(self.reg_region.datasets())
     self.assertEqual(len(self.reg_region.datasets()), 2)
Beispiel #7
0
def process_metadata(result):
    created = False
    dataset = None

    try:
        the_id = result['dataset_id']
        dataset = DataSet.objects.get(blackrock_id=the_id)
    except DataSet.DoesNotExist:
        dataset = DataSet()
        created = True

    original_state = dict(dataset.__dict__)

    values = process_fieldnames(result)

    for field in dataset._meta.fields:
        if field.name in values.keys():
            if isinstance(field, DateField):
                value = process_date(values[field.name][0])
            else:
                value = values[field.name][0]
            dataset.__setattr__(field.name, value)

    dataset.location = process_location(values)
    if created:
        dataset.save()

    for field in dataset._meta.many_to_many:
        if field.name in values.keys():
            related_model = get_model("portal", field.name)
            for v in values[field.name]:
                if field.name == 'url':
                    v = settings.CDRS_SOLR_FILEURL + v
                related_obj, temp_created = \
                    related_model.objects.get_or_create(name=v.strip())
                dataset.__getattribute__(field.name).add(related_obj)

    dataset.audience.add(Audience.objects.get(name='Research'))

    if _is_dirty(original_state, dict(dataset.__dict__)):
        dataset.save()

    return created
Beispiel #8
0
 def test_dataset_station_not_none(self):
     self.data_set_location = Location(name="New Dataset Location",
                                       latitude=6.08,
                                       longitude=2.2)
     self.data_set_location.save()
     self.data_set_station = Station(
         name="New Station",
         description="this is a another station object",
         access_means="you can walk there!",
         activation_date=datetime.now(),
         location=self.location)
     self.data_set_station.save()
     self.new_dataset = DataSet(name="data set",
                                description="This is a data set.",
                                collection_start_date=datetime.now(),
                                location=self.location)
     self.new_dataset.save()
     self.data_set_location.station_set.add(self.data_set_station)
     self.data_set_location.dataset_set.add(self.new_dataset)
     self.data_set_location.save()
     self.assertIsNotNone(self.dataset.station())
Beispiel #9
0
 def setUp(self):
     self.audience = Audience(name="audience name")
     self.audience.save()
     self.digital_format_image = DigitalFormat(name="png", id=1866)
     self.digital_format_image.save()
     self.digital_format_video = DigitalFormat(name="mp4", id=1200)
     self.digital_format_video.save()
     self.facet = Facet(name="facet name here",
                        display_name="facet display name",
                        facet="facet here...")
     self.facet.save()
     self.institution = Institution(name="institution name here")
     self.institution.save()
     self.location_subtype = LocationSubtype(name="location subtype name")
     self.location_subtype.save()
     self.location_type = LocationType(name="location type name")
     self.location_type.save()
     self.person_type = PersonType(name="special type of person")
     self.person_type.save()
     self.publication_type = PublicationType(name="publication name")
     self.publication_type.save()
     self.region_type = RegionType(name="region name")
     self.region_type.save()
     self.tag = Tag(name="tag name")
     self.tag.save()
     self.url = Url(name="http://www.ccnmtl.columbia.edu",
                    display_name="ccnmtl.columbia.edu")
     self.url.save()
     self.digital_object = DigitalObject(
         name="digital object name",
         digital_format=self.digital_format_image)
     self.digital_object.save()
     self.location = Location(name="location name here",
                              latitude=6.08,
                              longitude=2.2)
     self.location.save()
     self.station = Station(name="station name",
                            description="this is a station object",
                            access_means="you can walk there!",
                            activation_date=datetime.now(),
                            location=self.location)
     self.station.save()
     self.person = Person(
         full_name="Harold The Flying Sheep",
         first_name="Harold",
         last_name="Sheep",
         description=(
             "most people have 2 legs, Harold has 4 and can fly with wings"
         ))
     self.person.save()
     self.person_no_first_name = Person(full_name="person has no name",
                                        last_name="Sheep No. 2")
     self.person_no_first_name.save()
     self.publication_long_name = Publication(
         name=("This is a very very long publication name, "
               "long as in longer than twenty five (25) characters"))
     self.publication_long_name.save()
     self.publication = Publication(name="Regular Publication Name")
     self.publication.save()
     self.dataset = DataSet(name="data set",
                            description="This is a data set.",
                            collection_start_date=datetime.now(),
                            location=self.location)
     self.dataset.save()
     self.rights_type = RightsType(name="Rights Type Name")
     self.photo_gallery_item = PhotoGalleryItem(title="photo_gallery_item",
                                                position=7)
     self.photo_gallery_item.save()
     self.learning_activity = LearningActivity(
         name="Learning Activity Name")
     self.learning_activity.save()
     self.research_project_normal_name = ResearchProject(
         name="This is normal name", start_date=datetime.now())
     self.research_project_normal_name.save()
     self.research_project_long_name = ResearchProject(
         name=("This is a research project with an extrememly "
               "long name, this name is more like a description "
               "because the user did not follow the directions "
               "for entering a propername."),
         start_date=datetime.now())
     self.research_project_long_name.save()
     self.forest_story = ForestStory(name="Name of Forest Story")
     self.forest_story.save()
     self.region = Region(name="Region Name",
                          description="This is some region of blackrock.")
     self.region.save()