Exemplo n.º 1
0
    def test_treephoto_dict_to_model(self):
        plot = Plot(geom=Point(0, 0), instance=self.instance)
        plot.save_with_user(self.commander)
        tree = Tree(plot=plot, instance=self.instance)
        tree.save_with_user(self.commander)

        ipath = self.resource_path('tree1.gif')

        tp_dict = json.loads(self.treephoto_blob % ipath)

        self.assertEqual(TreePhoto.objects.count(), 0)

        save_treephoto_blank = self.default_partial(save_treephoto, '')

        save_objects(
            MIGRATION_RULES,
            "treephoto", [tp_dict],
            {'tree': {1: tree.pk},
             'user': {1: self.commander.pk}},
            save_treephoto_blank,
            self.instance)

        self.assertEqual(TreePhoto.objects.count(), 1)
        photo = TreePhoto.objects.all()[0]

        self.assertIsNotNone(photo.image)
        self.assertIsNotNone(photo.thumbnail)
Exemplo n.º 2
0
    def test_species_dict_to_model(self):
        species_dict = json.loads(self.species_blob)

        save_objects(
            MIGRATION_RULES,
            "species", [species_dict], {},
            self.default_partial(save_species),
            self.instance)

        allspecies = Species.objects.filter(instance=self.instance)
        self.assertEqual(len(allspecies), 1)

        species = allspecies[0]

        self.assertEqual(species.otm_code, 'EUVI')
        self.assertEqual(species.genus, 'Eucalyptus')
        self.assertEqual(species.species, 'viminalis')
        self.assertEqual(species.cultivar, '')
        self.assertEqual(species.gender, '')
        self.assertEqual(species.common_name, "Basket willow")
        self.assertEqual(species.native_status, False)
        self.assertEqual(species.bloom_period, None)
        self.assertEqual(species.fruit_period, None)
        self.assertEqual(species.fall_conspicuous, None)
        self.assertEqual(species.flower_conspicuous, None)
        self.assertEqual(species.palatable_human, None)
        self.assertEqual(species.wildlife_value, None)
        self.assertEqual(species.fact_sheet,
                         'http://eol.org/search?q=Salix viminalis')
        self.assertEqual(species.plant_guide, None)
Exemplo n.º 3
0
    def test_userphoto_dict_to_model(self):

        # just use a tree photo - it doesn't matter
        photo_path = self.resource_path('tree1.gif')

        qs = User.objects.exclude(photo="")

        self.assertEqual(qs.count(), 0)

        process_userprofile_blank = self.default_partial(
            process_userprofile, '')

        otm1_user_id = 755
        userprofile_fixture = json.loads(self.userprofile_blob %
                                         (otm1_user_id, photo_path))

        save_objects(
            MIGRATION_RULES,
            "userprofile",
            [userprofile_fixture],
            {'user': {otm1_user_id: self.commander.pk}},
            process_userprofile_blank,
            self.instance)

        self.assertEqual(qs.count(), 1)

        user = qs.get()

        self.assertIsNotNone(user.photo)
        self.assertIsNotNone(user.thumbnail)
Exemplo n.º 4
0
    def test_treephoto_dict_to_model(self):
        plot = Plot(geom=self.instance.center, instance=self.instance)
        plot.save_with_user(self.commander)
        tree = Tree(plot=plot, instance=self.instance)
        tree.save_with_user(self.commander)

        ipath = self.resource_path('tree1.gif')

        tp_dict = json.loads(self.treephoto_blob % ipath)

        self.assertEqual(TreePhoto.objects.count(), 0)

        save_treephoto_blank = self.default_partial(save_treephoto, '')

        save_objects(MIGRATION_RULES, "treephoto", [tp_dict], {
            'tree': {
                1: tree.pk
            },
            'user': {
                1: self.commander.pk
            }
        }, save_treephoto_blank, self.instance)

        self.assertEqual(TreePhoto.objects.count(), 1)
        photo = TreePhoto.objects.all()[0]

        self.assertIsNotNone(photo.image)
        self.assertIsNotNone(photo.thumbnail)
Exemplo n.º 5
0
    def test_userphoto_dict_to_model(self):

        # just use a tree photo - it doesn't matter
        photo_path = self.resource_path('tree1.gif')

        qs = User.objects.exclude(photo="")

        self.assertEqual(qs.count(), 0)

        process_userprofile_blank = self.default_partial(
            process_userprofile, '')

        otm1_user_id = 755
        userprofile_fixture = json.loads(self.userprofile_blob %
                                         (otm1_user_id, photo_path))

        save_objects(MIGRATION_RULES, "userprofile", [userprofile_fixture],
                     {'user': {
                         otm1_user_id: self.commander.pk
                     }}, process_userprofile_blank, self.instance)

        self.assertEqual(qs.count(), 1)

        user = qs.get()

        self.assertIsNotNone(user.photo)
        self.assertIsNotNone(user.thumbnail)
Exemplo n.º 6
0
    def test_species_dict_to_model(self):
        species_dict = json.loads(self.species_blob)

        save_objects(MIGRATION_RULES, "species", [species_dict], {},
                     self.default_partial(save_species), self.instance)

        allspecies = Species.objects.filter(instance=self.instance)
        self.assertEqual(len(allspecies), 1)

        species = allspecies[0]

        self.assertEqual(species.otm_code, '')
        self.assertEqual(species.genus, 'Eucalyptus')
        self.assertEqual(species.species, 'viminalis')
        self.assertEqual(species.cultivar, '')
        self.assertEqual(species.common_name, "Basket willow")
        self.assertEqual(species.is_native, False)
        self.assertEqual(species.flowering_period, '')
        self.assertEqual(species.fruit_or_nut_period, '')
        self.assertEqual(species.fall_conspicuous, None)
        self.assertEqual(species.flower_conspicuous, None)
        self.assertEqual(species.palatable_human, None)
        self.assertEqual(species.has_wildlife_value, None)
        self.assertEqual(species.fact_sheet_url,
                         'http://eol.org/search?q=Salix viminalis')
        self.assertEqual(species.plant_guide_url, '')
Exemplo n.º 7
0
    def test_dont_add_duplicates(self):
        species_dict = json.loads(self.species_blob)
        species_dicts = [species_dict, species_dict, species_dict]

        save_objects(MIGRATION_RULES, "species", species_dicts, {},
                     self.default_partial(save_species), self.instance)

        allspecies = Species.objects.filter(instance=self.instance)
        self.assertEqual(len(allspecies), 1)
Exemplo n.º 8
0
    def test_dont_add_duplicates(self):
        species_dict = json.loads(self.species_blob)
        species_dicts = [species_dict, species_dict, species_dict]

        save_objects(
            MIGRATION_RULES,
            "species", species_dicts, {},
            self.default_partial(save_species),
            self.instance)

        allspecies = Species.objects.filter(instance=self.instance)
        self.assertEqual(len(allspecies), 1)