Ejemplo n.º 1
0
def setupTreemapEnv():
    def local_render_to_response(*args, **kwargs):
        from django.template import loader
        from django.http import HttpResponse

        httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
        hr = HttpResponse(
            loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

        if hasattr(args[1], 'dicts'):
            hr.request_context = args[1].dicts

        return hr

    django.shortcuts.render_to_response = local_render_to_response

    instance = make_instance(is_public=True)
    create_stewardship_udfs(instance)

    make_user_with_default_role(instance, 'jim')
    commander = make_commander_user(instance, 'commander')
    make_apprentice_user(instance, 'apprentice')

    n1geom = MultiPolygon(Polygon(
        ((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))

    n2geom = MultiPolygon(
        Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Boundary(name="n1", category='blah', sort_order=4, geom=n1geom)
    n2 = Boundary(name="n2", category='blah', sort_order=4, geom=n2geom)

    n1.save()
    n2.save()

    s1 = Species(otm_code="s1", genus="testus1", species="specieius1",
                 cultivar='', instance=instance)
    s2 = Species(otm_code="s2", genus="testus2", species="specieius2",
                 cultivar='', instance=instance)
    s3 = Species(otm_code="s3", genus="testus2", species="specieius3",
                 cultivar='', instance=instance)

    s1.is_native = True
    s1.fall_conspicuous = True
    s1.flower_conspicuous = True
    s1.palatable_human = True

    s2.is_native = True
    s2.fall_conspicuous = False
    s2.flower_conspicuous = True
    s2.palatable_human = False
    s2.has_wildlife_value = True

    s3.has_wildlife_value = True

    s1.save_with_user(commander)
    s2.save_with_user(commander)
    s3.save_with_user(commander)

    return instance
Ejemplo n.º 2
0
    def setUp(self):
        self.instance = make_instance()
        datatype = [
            {'type': 'choice', 'choices': ['love', 'hug'], 'name': 'action'},
            {'type': 'int', 'name': 'times'},
            {'type': 'date', 'name': 'day'},
        ]
        create_stewardship_udfs(self.instance)
        make_collection_udf(self.instance, model='Plot', name='Caring',
                            datatype=datatype)
        make_collection_udf(self.instance, model='Tree', name='Caring',
                            datatype=datatype)

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'string'}),
            iscollection=False,
            name='Name')

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Tree',
            datatype=json.dumps({'type': 'int'}),
            iscollection=False,
            name='Man Units')
Ejemplo n.º 3
0
def setupTreemapEnv():
    def local_render_to_response(*args, **kwargs):
        from django.template import loader
        from django.http import HttpResponse

        hr = HttpResponse(loader.render_to_string(*args, **kwargs))

        if hasattr(args[1], 'dicts'):
            hr.request_context = args[1].dicts

        return hr

    django.shortcuts.render_to_response = local_render_to_response

    instance = make_instance(is_public=True)
    create_stewardship_udfs(instance)

    make_user_with_default_role(instance, 'jim')
    commander = make_commander_user(instance, 'commander')
    make_apprentice_user(instance, 'apprentice')

    n1geom = MultiPolygon(Polygon(
        ((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))

    n2geom = MultiPolygon(
        Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Boundary(name="n1", category='blah', sort_order=4, geom=n1geom)
    n2 = Boundary(name="n2", category='blah', sort_order=4, geom=n2geom)

    n1.save()
    n2.save()

    s1 = Species(otm_code="s1", genus="testus1", species="specieius1",
                 cultivar='', instance=instance)
    s2 = Species(otm_code="s2", genus="testus2", species="specieius2",
                 cultivar='', instance=instance)
    s3 = Species(otm_code="s3", genus="testus2", species="specieius3",
                 cultivar='', instance=instance)

    s1.is_native = True
    s1.fall_conspicuous = True
    s1.flower_conspicuous = True
    s1.palatable_human = True

    s2.is_native = True
    s2.fall_conspicuous = False
    s2.flower_conspicuous = True
    s2.palatable_human = False
    s2.has_wildlife_value = True

    s3.has_wildlife_value = True

    s1.save_with_user(commander)
    s2.save_with_user(commander)
    s3.save_with_user(commander)

    return instance
Ejemplo n.º 4
0
    def setUp(self):
        User._system_user.save_base()

        self.instance = make_instance()
        create_stewardship_udfs(self.instance)
        self.user = make_commander_user(self.instance)

        set_write_permissions(self.instance, self.user, "Plot", ["udf:Test choice"])

        self.udf = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
            iscollection=False,
            name="Test choice",
        )
Ejemplo n.º 5
0
    def setUp(self):
        self.instance = make_instance()
        datatype = [
            {
                'type': 'choice',
                'choices': ['love', 'hug'],
                'name': 'action'
            },
            {
                'type': 'int',
                'name': 'times'
            },
            {
                'type': 'date',
                'name': 'day'
            },
        ]
        create_stewardship_udfs(self.instance)
        make_collection_udf(self.instance,
                            model='Plot',
                            name='Caring',
                            datatype=datatype)
        make_collection_udf(self.instance,
                            model='Tree',
                            name='Caring',
                            datatype=datatype)

        UserDefinedFieldDefinition.objects.create(instance=self.instance,
                                                  model_type='Plot',
                                                  datatype=json.dumps(
                                                      {'type': 'string'}),
                                                  iscollection=False,
                                                  name='Name')

        UserDefinedFieldDefinition.objects.create(instance=self.instance,
                                                  model_type='Tree',
                                                  datatype=json.dumps(
                                                      {'type': 'int'}),
                                                  iscollection=False,
                                                  name='Man Units')
Ejemplo n.º 6
0
    def setUp(self):
        # for some reason, the call to this helper
        # in setup_databases() on the test runner
        # is not executing in this context.
        # this is required to make the test work.
        create_mock_system_user()

        super(TreemapUITestCase, self).setUp()

        instance_name = 'autotest_instance'

        Instance.objects.filter(name=instance_name).delete()

        self.instance = create_instance(name=instance_name,
                                        is_public=False,
                                        url_name='autotest-instance',
                                        edge_length=20000)
        create_stewardship_udfs(self.instance)

        self.user = make_commander_user(instance=self.instance,
                                        username='******')

        self.profile = RegistrationProfile.objects.create_profile(self.user)
Ejemplo n.º 7
0
    def setUp(self):
        # for some reason, the call to this helper
        # in setup_databases() on the test runner
        # is not executing in this context.
        # this is required to make the test work.
        create_mock_system_user()

        super(TreemapUITestCase, self).setUp()

        instance_name = 'autotest_instance'

        Instance.objects.filter(name=instance_name).delete()

        self.instance = create_instance(
            name=instance_name,
            is_public=False,
            url_name='autotest-instance',
            edge_length=20000)
        create_stewardship_udfs(self.instance)

        self.user = make_commander_user(instance=self.instance,
                                        username='******')

        self.profile = RegistrationProfile.objects.create_profile(self.user)
Ejemplo n.º 8
0
    def setUp(self):
        # Just in case - cleanup other bad test cases
        Instance.objects.all().delete()

        self.instance = make_instance()
        plot_stew, tree_stew = tuple(
            create_stewardship_udfs(self.instance))
        self.cudf = plot_stew
        self.user = make_commander_user(self.instance)

        self.udf = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'choice',
                                 'choices': ['a', 'b', 'c']}),
            iscollection=False,
            name='Test choice')

        self.plot = Plot(instance=self.instance, geom=self.instance.center)

        set_write_permissions(self.instance, self.user,
                              'Plot', ['udf:Test choice', 'udf:Stewardship'])
Ejemplo n.º 9
0
    def setUp(self):
        # Just in case - cleanup other bad test cases
        Instance.objects.all().delete()

        self.instance = make_instance()
        plot_stew, tree_stew = tuple(create_stewardship_udfs(self.instance))
        self.cudf = plot_stew
        self.user = make_commander_user(self.instance)

        self.udf = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({
                'type': 'choice',
                'choices': ['a', 'b', 'c']
            }),
            iscollection=False,
            name='Test choice')

        self.plot = Plot(instance=self.instance, geom=self.instance.center)

        set_write_permissions(self.instance, self.user, 'Plot',
                              ['udf:Test choice', 'udf:Stewardship'])
Ejemplo n.º 10
0
 def setUp(self):
     super(CommentUITest, self).setUp()
     create_stewardship_udfs(self.instance)
Ejemplo n.º 11
0
 def test_plot_detail(self):
     create_stewardship_udfs(self.instance)
     plot = self.make_plot()
     url = self.prefix + 'features/%s/' % plot.id
     self.assert_template(url, 'treemap/partials/plot_detail.html')
     self.assert_template(url, 'treemap/map_feature_detail.html')
Ejemplo n.º 12
0
 def test_map_feature_accordion(self):
     create_stewardship_udfs(self.instance)
     plot = self.make_plot()
     self.assert_template(self.prefix + 'features/%s/accordion' % plot.id,
                          'treemap/partials/map_feature_accordion.html')
Ejemplo n.º 13
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise Exception('Expected instance name as the first argument')

        name = args[0]

        if not options['user']:
            raise Exception('An admin user must be specified. with "--user"')

        if options.get('center', None) and options.get('geojson', None):
            raise Exception('You must specifiy only one of '
                            '"center" and "geojson"')
        elif (not options.get('center', None)
              and not options.get('geojson', None)):
            raise Exception('You must specifiy at least one of '
                            '"center" and "geojson"')

        if options['center']:
            center = options['center'].split(',')
            if len(center) != 2:
                raise Exception('Center should be a lon,lat pair')

            center_pt = Point(float(center[0]), float(center[1]), srid=4326)

            # Bounding box built in web mercator to have units in meters
            center_pt.transform(3857)
            x = center_pt.x
            y = center_pt.y
            instance_bounds = InstanceBounds.create_from_point(x, y)
        else:
            geom = GEOSGeometry(open(options['geojson'], srid=4326).read())
            instance_bounds = InstanceBounds.objects.create(geom=geom)

        if not options.get('url_name', None):
            raise Exception('You must specify a "url_name" starting with a '
                            'lowercase letter and containing lowercase '
                            'letters, numbers, and dashes ("-")')
        url_name = options.get('url_name')

        instance = Instance(config={},
                            name=name,
                            bounds=instance_bounds,
                            is_public=True,
                            url_name=url_name)

        instance.seed_with_dummy_default_role()
        instance.full_clean()
        instance.save()

        instance.boundaries = Boundary.objects.filter(
            geom__intersects=instance_bounds.geom)

        role = Role.objects.create(
            name='user',
            instance=instance,
            rep_thresh=0,
            default_permission_level=FieldPermission.WRITE_DIRECTLY)

        create_stewardship_udfs(instance)

        add_species_to_instance(instance)

        add_default_permissions(instance, roles=[role])
        add_instance_permissions([role])

        eco_benefits_conversion = \
            BenefitCurrencyConversion.get_default_for_instance(instance)
        if eco_benefits_conversion:
            eco_benefits_conversion.save()
            instance.eco_benefits_conversion = eco_benefits_conversion

        instance.default_role = role
        instance.save()

        user = User.objects.get(username=options['user'])
        InstanceUser(instance=instance, user=user, role=role,
                     admin=True).save_with_user(user)
Ejemplo n.º 14
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise Exception(
                'Expected instance name as the first argument')

        name = args[0]

        if not options['user']:
            raise Exception('An admin user must be specified. with "--user"')

        if options.get('center', None) and options.get('geojson', None):
            raise Exception('You must specifiy only one of '
                            '"center" and "geojson"')
        elif (not options.get('center', None) and
              not options.get('geojson', None)):
            raise Exception('You must specifiy at least one of '
                            '"center" and "geojson"')

        if options['center']:
            center = options['center'].split(',')
            if len(center) != 2:
                raise Exception('Center should be a lon,lat pair')

            center_pt = Point(float(center[0]), float(center[1]), srid=4326)

            # Bounding box built in web mercator to have units in meters
            center_pt.transform(3857)
            x = center_pt.x
            y = center_pt.y
            instance_bounds = InstanceBounds.create_from_point(x, y)
        else:
            geom = GEOSGeometry(open(options['geojson'], srid=4326).read())
            instance_bounds = InstanceBounds.objects.create(geom=geom)

        if not options.get('url_name', None):
            raise Exception('You must specify a "url_name" starting with a '
                            'lowercase letter and containing lowercase '
                            'letters, numbers, and dashes ("-")')
        url_name = options.get('url_name')

        instance = Instance(
            config={},
            name=name,
            bounds=instance_bounds,
            is_public=True,
            url_name=url_name)

        instance.seed_with_dummy_default_role()
        instance.full_clean()
        instance.save()

        instance.boundaries = Boundary.objects.filter(
            geom__intersects=instance_bounds.geom)

        role = Role.objects.create(
            name='user', instance=instance, rep_thresh=0,
            default_permission=FieldPermission.WRITE_DIRECTLY)

        create_stewardship_udfs(instance)

        add_species_to_instance(instance)

        add_default_permissions(instance, roles=[role])

        eco_benefits_conversion = \
            BenefitCurrencyConversion.get_default_for_point(Point(x, y))
        if eco_benefits_conversion:
            eco_benefits_conversion.save()

        instance.eco_benefits_conversion = eco_benefits_conversion

        instance.default_role = role
        instance.save()

        user = User.objects.get(username=options['user'])
        InstanceUser(
            instance=instance,
            user=user,
            role=role,
            admin=True).save_with_user(user)
Ejemplo n.º 15
0
 def setUp(self):
     super(CommentUITest, self).setUp()
     create_stewardship_udfs(self.instance)
Ejemplo n.º 16
0
 def test_map_feature_accordion(self):
     create_stewardship_udfs(self.instance)
     plot = self.make_plot()
     self.assert_template(
         self.prefix + 'features/%s/accordion' % plot.id,
         'treemap/partials/map_feature_accordion.html')
Ejemplo n.º 17
0
 def test_plot_detail(self):
     create_stewardship_udfs(self.instance)
     plot = self.make_plot()
     url = self.prefix + 'features/%s/' % plot.id
     self.assert_template(url, 'treemap/partials/plot_detail.html')
     self.assert_template(url, 'treemap/map_feature_detail.html')
Ejemplo n.º 18
0
    def setUp(self):
        self.instance = make_instance()
        self.plot_stew, self.tree_stew = tuple(
            create_stewardship_udfs(self.instance))

        self.user = make_commander_user(self.instance)
Ejemplo n.º 19
0
    def setUp(self):
        self.instance = make_instance()
        self.plot_stew, self.tree_stew = tuple(
            create_stewardship_udfs(self.instance))

        self.user = make_commander_user(self.instance)