class EcoTest(TestCase): def setUp(self): self.factory = RequestFactory() self.instance, system_user = tm.make_instance_and_system_user() self.user = User(username="******") self.user.save_with_user(system_user) self.user.roles.add(tm.make_commander_role(self.instance)) self.species = Species(symbol='CEDR', genus='cedrus', species='atlantica', max_dbh=2000, max_height=100) self.species.save() p1 = Point(-8515941.0, 4953519.0) self.plot = Plot(geom=p1, instance=self.instance, created_by=self.user) self.plot.save_with_user(self.user) self.tree = Tree(plot=self.plot, instance=self.instance, readonly=False, species=self.species, diameter=1630, created_by=self.user) self.tree.save_with_user(self.user) def test_group_eco(self): pass # TODO: Once filtering has been enabled def test_eco_benefit_sanity(self): req = self.factory.get('/%s/eco/benefit/tree/%s/' % (self.instance.pk, self.tree.pk)) response = tree_benefits(req, instance_id=self.instance.pk, tree_id=self.tree.pk, region='NoEastXXX') self.assertEqual(response.status_code, 200) rslt = json.loads(response.content) bens = rslt['benefits'] def assertBValue(benefit, unit, value): self.assertEqual(bens[benefit]['unit'], unit) self.assertEqual(int(float(bens[benefit]['value'])), value) assertBValue('energy', 'kwh', 1896) assertBValue('airquality', 'lbs/year', 6) assertBValue('stormwater', 'gal', 3185) assertBValue('co2', 'lbs/year', 563)
def test_faulty_data1(self): s1_g = Species(symbol='S1GSC', scientific_name='', family='', genus='g1', species='', cultivar_name='', v_max_dbh=50.0, v_max_height=100.0) s1_g.save() csv = """ | point x | point y | diameter | read only | condition | genus | tree height | | -34.2 | 24.2 | q12 | true | Dead | | | | 323 | 23.2 | 14 | falseo | Critical | | | | 32.1 | 22.4 | 15 | true | Dead | | | | 33.2 | 19.1 | 32 | true | Arg | | | | 33.2 | q19.1 | -33.3 | true | Dead | gfail | | | 32.1 | 12.1 | | false | Dead | g1 | 200 | | 32.1 | 12.1 | 300 | false | Dead | g1 | | | 11.1 | 12.1 | | false | Dead | | | """ gflds = [fields.trees.POINT_X, fields.trees.POINT_Y] sflds = [ fields.trees.GENUS, fields.trees.SPECIES, fields.trees.CULTIVAR ] j = self.run_through_process_views(csv) ierrors = self.extract_errors(j) self.assertEqual( ierrors['0'], [(errors.FLOAT_ERROR[0], [fields.trees.DIAMETER], None), (errors.GEOM_OUT_OF_BOUNDS[0], gflds, None)]) self.assertEqual( ierrors['1'], [(errors.BOOL_ERROR[0], [fields.trees.READ_ONLY], None), (errors.INVALID_GEOM[0], gflds, None)]) self.assertNotIn('2', ierrors) self.assertEqual(ierrors['3'], [(errors.INVALID_CHOICE[0], [fields.trees.TREE_CONDITION], 'conditions')]) self.assertEqual( ierrors['4'], [(errors.POS_FLOAT_ERROR[0], [fields.trees.DIAMETER], None), (errors.FLOAT_ERROR[0], [fields.trees.POINT_Y], None), (errors.MISSING_POINTS[0], gflds, None), (errors.INVALID_SPECIES[0], sflds, 'gfail')]) self.assertEqual(ierrors['5'], [(errors.SPECIES_HEIGHT_TOO_HIGH[0], [fields.trees.TREE_HEIGHT], 100.0)]) self.assertEqual( ierrors['6'], [(errors.SPECIES_DBH_TOO_HIGH[0], [fields.trees.DIAMETER], 50.0)]) self.assertEqual(ierrors['7'], [(errors.EXCL_ZONE[0], gflds, None)])
def commit_row(self): # First validate if not self.validate_row(): return False # Get our data data = self.cleaned species_edited = False # Initially grab species from row if it exists # and edit it species = self.species # If not specified create a new one if species is None: species = Species() # Convert units self.convert_units( data, { fields.species.MAX_DIAMETER: self.import_event.max_diameter_conversion_factor, fields.species.MAX_HEIGHT: self.import_event.max_tree_height_conversion_factor }) #TODO: Update tree count nonsense for modelkey, importdatakey in SpeciesImportRow.SPECIES_MAP.iteritems( ): importdata = data.get(importdatakey, None) if importdata is not None: species_edited = True setattr(species, modelkey, importdata) if species_edited: species.save() resource = data[fields.species.RESOURCE] species.resource.clear() species.resource.add(resource) species.save() resource.save() self.species = species self.status = TreeImportRow.SUCCESS self.save() return True
def commit_row(self): # First validate if not self.validate_row(): return False # Get our data data = self.cleaned species_edited = False # Initially grab species from row if it exists # and edit it species = self.species # If not specified create a new one if species is None: species = Species() # Convert units self.convert_units(data, { fields.species.MAX_DIAMETER: self.import_event.max_diameter_conversion_factor, fields.species.MAX_HEIGHT: self.import_event.max_tree_height_conversion_factor }) #TODO: Update tree count nonsense for modelkey, importdatakey in SpeciesImportRow.SPECIES_MAP.iteritems(): importdata = data.get(importdatakey, None) if importdata is not None: species_edited = True setattr(species, modelkey, importdata) if species_edited: species.save() resource = data[fields.species.RESOURCE] species.resource.clear() species.resource.add(resource) species.save() resource.save() self.species = species self.status = TreeImportRow.SUCCESS self.save() return True
def test_faulty_data1(self): s1_g = Species(symbol='S1GSC', scientific_name='',family='', genus='g1', species='', cultivar_name='', v_max_dbh=50.0, v_max_height=100.0) s1_g.save() csv = """ | point x | point y | diameter | read only | condition | genus | tree height | | -34.2 | 24.2 | q12 | true | Dead | | | | 323 | 23.2 | 14 | falseo | Critical | | | | 32.1 | 22.4 | 15 | true | Dead | | | | 33.2 | 19.1 | 32 | true | Arg | | | | 33.2 | q19.1 | -33.3 | true | Dead | gfail | | | 32.1 | 12.1 | | false | Dead | g1 | 200 | | 32.1 | 12.1 | 300 | false | Dead | g1 | | | 11.1 | 12.1 | | false | Dead | | | """ gflds = [fields.trees.POINT_X, fields.trees.POINT_Y] sflds = [fields.trees.GENUS, fields.trees.SPECIES, fields.trees.CULTIVAR] j = self.run_through_process_views(csv) ierrors = self.extract_errors(j) self.assertEqual(ierrors['0'], [(errors.FLOAT_ERROR[0], [fields.trees.DIAMETER], None), (errors.GEOM_OUT_OF_BOUNDS[0], gflds, None)]) self.assertEqual(ierrors['1'], [(errors.BOOL_ERROR[0], [fields.trees.READ_ONLY], None), (errors.INVALID_GEOM[0], gflds, None)]) self.assertNotIn('2', ierrors) self.assertEqual(ierrors['3'], [(errors.INVALID_CHOICE[0], [fields.trees.TREE_CONDITION], 'conditions')]) self.assertEqual(ierrors['4'], [(errors.POS_FLOAT_ERROR[0], [fields.trees.DIAMETER], None), (errors.FLOAT_ERROR[0], [fields.trees.POINT_Y], None), (errors.MISSING_POINTS[0], gflds, None), (errors.INVALID_SPECIES[0], sflds, 'gfail')]) self.assertEqual(ierrors['5'], [(errors.SPECIES_HEIGHT_TOO_HIGH[0], [fields.trees.TREE_HEIGHT], 100.0)]) self.assertEqual(ierrors['6'], [(errors.SPECIES_DBH_TOO_HIGH[0], [fields.trees.DIAMETER], 50.0)]) self.assertEqual(ierrors['7'], [(errors.EXCL_ZONE[0], gflds, None)])
def test_species_dbh_and_height(self): s1_gsc = Species(symbol='S1G__', scientific_name='', family='', genus='g1', species='s1', cultivar_name='c1', v_max_height=30, v_max_dbh=19) s1_gs = Species(symbol='S1GS_', scientific_name='', family='', genus='g1', species='s1', cultivar_name='', v_max_height=22, v_max_dbh=12) s1_gsc.save() s1_gs.save() row = { 'point x': '16', 'point y': '20', 'genus': 'g1', 'species': 's1', 'diameter': '15', 'tree height': '18' } i = self.mkrow(row) r = i.validate_row() self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH) row['tree height'] = 25 i = self.mkrow(row) r = i.validate_row() self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH) row['cultivar'] = 'c1' i = self.mkrow(row) r = i.validate_row() self.assertNotHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH)
def test_species_matching(self): csv = """ | genus | species | common name | i-tree code | usda symbol | alternative symbol | other part of scientific name | | testus1 | specieius1 | g1 s2 wowza | BDL_OTHER | | | | | genus | blah | common name | BDL_OTHER | s1 | | | | testus1 | specieius1 | g1 s2 wowza | BDL_OTHER | s2 | | | | testus2 | specieius2 | g1 s2 wowza | BDL_OTHER | s1 | a3 | | | genusN | speciesN | gN sN wowza | BDL_OTHER | | | var3 | """ j = self.run_through_process_views(csv) ierrors = self.extract_errors(j) # Errors for multiple species matches self.assertEqual(len(ierrors), 4) ie = SpeciesImportEvent.objects.get(pk=j['pk']) s1, s2, s3 = [s.pk for s in Species.objects.all()] s4s = Species(symbol='gnsn', scientific_name='', family='', genus='genusN', species='speciesN', cultivar_name='', other_part_of_name='var3', v_max_dbh=50.0, v_max_height=100.0) s4s.save() s4 = s4s.pk rows = ie.rows() matches = [] for row in rows: row.validate_row() matches.append(row.cleaned[fields.species.ORIG_SPECIES]) m1, m2, m3, m4, m5 = matches self.assertEqual(m1, {s1}) self.assertEqual(m2, {s1}) self.assertEqual(m3, {s1, s2}) self.assertEqual(m4, {s1, s2, s3}) self.assertEqual(m5, {s4})
def _process_record(self, rec): pk = rec['pk'] fields = rec['fields'] fields['max_height'] = fields['v_max_height'] or 10000 del fields['v_max_height'] fields['max_dbh'] = fields['v_max_dbh'] or 10000 del fields['v_max_dbh'] removed_fields = ['alternate_symbol', 'v_multiple_trunks', 'tree_count', 'resource', 'itree_code'] for f in removed_fields: del fields[f] s = Species(**fields) s.pk = pk s.save()
def test_species_matching(self): csv = """ | genus | species | common name | i-tree code | usda symbol | alternative symbol | other part of scientific name | | testus1 | specieius1 | g1 s2 wowza | BDL_OTHER | | | | | genus | blah | common name | BDL_OTHER | s1 | | | | testus1 | specieius1 | g1 s2 wowza | BDL_OTHER | s2 | | | | testus2 | specieius2 | g1 s2 wowza | BDL_OTHER | s1 | a3 | | | genusN | speciesN | gN sN wowza | BDL_OTHER | | | var3 | """ j = self.run_through_process_views(csv) ierrors = self.extract_errors(j) # Errors for multiple species matches self.assertEqual(len(ierrors), 4) ie = SpeciesImportEvent.objects.get(pk=j['pk']) s1,s2,s3 = [s.pk for s in Species.objects.all()] s4s = Species(symbol='gnsn', scientific_name='',family='', genus='genusN', species='speciesN', cultivar_name='', other_part_of_name='var3', v_max_dbh=50.0, v_max_height=100.0) s4s.save() s4 = s4s.pk rows = ie.rows() matches = [] for row in rows: row.validate_row() matches.append(row.cleaned[fields.species.ORIG_SPECIES]) m1,m2,m3,m4,m5 = matches self.assertEqual(m1, {s1}) self.assertEqual(m2, {s1}) self.assertEqual(m3, {s1,s2}) self.assertEqual(m4, {s1,s2,s3}) self.assertEqual(m5, {s4})
def test_species_dbh_and_height(self): s1_gsc = Species(symbol='S1G__', scientific_name='',family='', genus='g1', species='s1', cultivar_name='c1', v_max_height=30, v_max_dbh=19) s1_gs = Species(symbol='S1GS_', scientific_name='',family='', genus='g1', species='s1', cultivar_name='', v_max_height=22, v_max_dbh=12) s1_gsc.save() s1_gs.save() row = {'point x': '16', 'point y': '20', 'genus': 'g1', 'species': 's1', 'diameter': '15', 'tree height': '18'} i = self.mkrow(row) r = i.validate_row() self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH) row['tree height'] = 25 i = self.mkrow(row) r = i.validate_row() self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH) row['cultivar'] = 'c1' i = self.mkrow(row) r = i.validate_row() self.assertNotHasError(i, errors.SPECIES_DBH_TOO_HIGH) self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH)
def setUp(self): ###### # Request/Render mock ###### def local_render_to_response(*args, **kwargs): from django.template import loader, RequestContext 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 ###### # Content types ###### r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") r7 = ReputationAction(name="add stewardship", description="blah") r8 = ReputationAction(name="remove stewardship", description="blah") self.ra = [r1, r2, r3, r4, r5, r6, r7, r8] for r in self.ra: r.save() ###### # Set up benefit values ###### bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166, voc=4.69, ozone=5.0032, natural_gas=1.25278, nox=12.79, stormwater=0.0078, sox=3.72, bvoc=4.96) bv.save() self.bv = bv dbh = "[1.0, 2.0, 3.0]" rsrc = Resource(meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh, aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh, aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh, co2_storage_dbh=dbh, aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh, bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh, hydro_interception_dbh=dbh, natural_gas_dbh=dbh) rsrc.save() self.rsrc = rsrc ###### # Users ###### u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim", "*****@*****.**", "jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) u.reputation = Reputation(user=u) u.reputation.save() self.u = u ####### # Setup geometries -> Two stacked 100x100 squares ####### 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 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon( Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0)))) z2geom = MultiPolygon( Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100)))) z1 = ZipCode(zip="19107", geometry=z1geom) z2 = ZipCode(zip="10001", geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon( Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n1) agn2 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n2) agn1.save() agn2.save() self.agn1 = agn1 self.agn2 = agn2 self.z1 = z1 self.z2 = z2 self.n1 = n1 self.n2 = n2 ###### # And we could use a few species... ###### s1 = Species(symbol="s1", genus="testus1", species="specieius1") s2 = Species(symbol="s2", genus="testus2", species="specieius2") s1.save() s2.save() self.s1 = s1 self.s2 = s2 ####### # Create some basic plots ####### ie = ImportEvent(file_name='site_add') ie.save() self.ie = ie p1_no_tree = Plot(geometry=Point(50, 50), last_updated_by=u, import_event=ie, present=True, data_owner=u) p1_no_tree.save() p2_tree = Plot(geometry=Point(51, 51), last_updated_by=u, import_event=ie, present=True, data_owner=u) p2_tree.save() p3_tree_species1 = Plot(geometry=Point(50, 100), last_updated_by=u, import_event=ie, present=True, data_owner=u) p3_tree_species1.save() p4_tree_species2 = Plot(geometry=Point(50, 150), last_updated_by=u, import_event=ie, present=True, data_owner=u) p4_tree_species2.save() t1 = Tree(plot=p2_tree, species=None, last_updated_by=u, import_event=ie) t1.present = True t1.save() t2 = Tree(plot=p3_tree_species1, species=s1, last_updated_by=u, import_event=ie) t2.present = True t2.save() t3 = Tree(plot=p4_tree_species2, species=s2, last_updated_by=u, import_event=ie) t3.present = True t3.save() self.p1_no_tree = p1_no_tree self.p2_tree = p2_tree self.p3_tree_species1 = p3_tree_species1 self.p4_tree_species2 = p4_tree_species2 self.plots = [p1_no_tree, p2_tree, p3_tree_species1, p4_tree_species2] self.t1 = t1 self.t2 = t2 self.t3 = t3
def setupTreemapEnv(): settings.GEOSERVER_GEO_LAYER = "" settings.GEOSERVER_GEO_STYLE = "" settings.GEOSERVER_URL = "" r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") for r in [r1, r2, r3, r4, r5, r6]: r.save() bv = BenefitValues( co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166, voc=4.69, ozone=5.0032, natural_gas=1.25278, nox=12.79, stormwater=0.0078, sox=3.72, bvoc=4.96) bv.save() dbh = "[1.0, 2.0, 3.0]" rsrc = Resource( meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh, aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh, aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh, co2_storage_dbh=dbh, aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh, bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh, hydro_interception_dbh=dbh, natural_gas_dbh=dbh) rsrc.save() u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim", "*****@*****.**", "jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) up.save() u.reputation = Reputation(user=u) u.reputation.save() amy_filter_result = User.objects.filter(username="******") if not amy_filter_result: amy = User.objects.create_user("amy", "*****@*****.**", "amy") else: amy = amy_filter_result[0] amy.is_staff = False amy.is_superuser = False amy.save() amy_profile = UserProfile(user=amy) amy_profile.save() amy.reputation = Reputation(user=amy) amy.reputation.save() 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 = Neighborhood( name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood( name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon( Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0)))) z2geom = MultiPolygon( Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100)))) z1 = ZipCode(zip="19107", geometry=z1geom) z2 = ZipCode(zip="10001", geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon( Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n1) agn2 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n2) agn1.save() agn2.save() s1 = Species(symbol="s1", genus="testus1", species="specieius1") s2 = Species(symbol="s2", genus="testus2", species="specieius2") s1.save() s2.save() ie = ImportEvent(file_name='site_add') ie.save()
def setUp(self): ###### # Request/Render mock ###### def local_render_to_response(*args, **kwargs): from django.template import loader, RequestContext 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 ###### # Content types ###### r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") r7 = ReputationAction(name="add stewardship", description="blah") r8 = ReputationAction(name="remove stewardship", description="blah") self.ra = [r1,r2,r3,r4,r5,r6,r7,r8] for r in self.ra: r.save() ###### # Set up benefit values ###### bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166,voc=4.69,ozone=5.0032,natural_gas=1.25278, nox=12.79,stormwater=0.0078,sox=3.72,bvoc=4.96) bv.save() self.bv = bv dbh = "[1.0, 2.0, 3.0]" rsrc = Resource(meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh, aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh, aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh, co2_storage_dbh=dbh,aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh, bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh, hydro_interception_dbh=dbh, natural_gas_dbh=dbh) rsrc.save() self.rsrc = rsrc ###### # Users ###### u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim","*****@*****.**","jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) u.reputation = Reputation(user=u) u.reputation.save() self.u = u ####### # Setup geometries -> Two stacked 100x100 squares ####### 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 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon(Polygon(((0,0),(100,0),(100,100),(0,100),(0,0)))) z2geom = MultiPolygon(Polygon(((0,100),(100,100),(100,200),(0,200),(0,100)))) z1 = ZipCode(zip="19107",geometry=z1geom) z2 = ZipCode(zip="10001",geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon(Polygon(((0,0),(25,0),(25,25),(0,25),(0,0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location = n1) agn2 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location = n2) agn1.save() agn2.save() self.agn1 = agn1 self.agn2 = agn2 self.z1 = z1 self.z2 = z2 self.n1 = n1 self.n2 = n2 ###### # And we could use a few species... ###### s1 = Species(symbol="s1",genus="testus1",species="specieius1") s2 = Species(symbol="s2",genus="testus2",species="specieius2") s1.save() s2.save() self.s1 = s1 self.s2 = s2 ####### # Create some basic plots ####### ie = ImportEvent(file_name='site_add') ie.save() self.ie = ie p1_no_tree = Plot(geometry=Point(50,50), last_updated_by=u, import_event=ie,present=True, data_owner=u) p1_no_tree.save() p2_tree = Plot(geometry=Point(51,51), last_updated_by=u, import_event=ie,present=True, data_owner=u) p2_tree.save() p3_tree_species1 = Plot(geometry=Point(50,100), last_updated_by=u, import_event=ie,present=True, data_owner=u) p3_tree_species1.save() p4_tree_species2 = Plot(geometry=Point(50,150), last_updated_by=u, import_event=ie,present=True, data_owner=u) p4_tree_species2.save() t1 = Tree(plot=p2_tree, species=None, last_updated_by=u, import_event=ie) t1.present = True t1.save() t2 = Tree(plot=p3_tree_species1, species=s1, last_updated_by=u, import_event=ie) t2.present = True t2.save() t3 = Tree(plot=p4_tree_species2, species=s2, last_updated_by=u, import_event=ie) t3.present = True t3.save() self.p1_no_tree = p1_no_tree self.p2_tree = p2_tree self.p3_tree_species1 = p3_tree_species1; self.p4_tree_species2 = p4_tree_species2; self.plots = [p1_no_tree, p2_tree, p3_tree_species1, p4_tree_species2] self.t1 = t1 self.t2 = t2 self.t3 = t3
def setupTreemapEnv(): settings.GEOSERVER_GEO_LAYER = "" settings.GEOSERVER_GEO_STYLE = "" settings.GEOSERVER_URL = "" def local_render_to_response(*args, **kwargs): from django.template import loader, RequestContext 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 r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") r7 = ReputationAction(name="add stewardship", description="blah") r8 = ReputationAction(name="remove stewardship", description="blah") for r in [r1, r2, r3, r4, r5, r6, r7, r8]: r.save() bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166, voc=4.69, ozone=5.0032, natural_gas=1.25278, nox=12.79, stormwater=0.0078, sox=3.72, bvoc=4.96) bv.save() dbh = "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]" dbh2 = "[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]" rsrc1 = Resource(meta_species="BDM OTHER", region="NoEastXXX") rsrc2 = Resource(meta_species="BDL OTHER", region="NoEastXXX") rsrc1.save() rsrc2.save() u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim", "*****@*****.**", "jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) up.save() u.reputation = Reputation(user=u) u.reputation.save() amy_filter_result = User.objects.filter(username="******") if not amy_filter_result: amy = User.objects.create_user("amy", "*****@*****.**", "amy") else: amy = amy_filter_result[0] amy.is_staff = False amy.is_superuser = False amy.save() amy_profile = UserProfile(user=amy) amy_profile.save() amy.reputation = Reputation(user=amy) amy.reputation.save() olivia_filter_result = User.objects.filter(username="******") if not amy_filter_result: olivia = User.objects.create_user("olivia", "*****@*****.**", "olivia") else: olivia = olivia_filter_result[0] olivia.is_staff = False olivia.is_superuser = False olivia.save() olivia_profile = UserProfile(user=olivia) olivia_profile.save() olivia.reputation = Reputation(user=olivia) olivia.reputation.save() 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 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon( Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0)))) z2geom = MultiPolygon( Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100)))) z1 = ZipCode(zip="19107", geometry=z1geom) z2 = ZipCode(zip="10001", geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon( Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n1) agn2 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n2) agn1.save() agn2.save() s1 = Species(symbol="s1", genus="testus1", species="specieius1", cultivar_name='', family='', alternate_symbol='a1') s2 = Species(symbol="s2", genus="testus2", species="specieius2", cultivar_name='', family='', alternate_symbol='a2') s3 = Species(symbol="s3", genus="testus2", species="specieius3", cultivar_name='', family='', alternate_symbol='a3') s1.native_status = 'True' s1.fall_conspicuous = True s1.flower_conspicuous = True s1.palatable_human = True s2.native_status = 'True' s2.fall_conspicuous = False s2.flower_conspicuous = True s2.palatable_human = False s2.wildlife_value = True s3.wildlife_value = True s1.save() s2.save() s3.save() s1.resource.add(rsrc1) s2.resource.add(rsrc2) s3.resource.add(rsrc2) ie = ImportEvent(file_name='site_add') ie.save()
def setupTreemapEnv(): settings.GEOSERVER_GEO_LAYER = "" settings.GEOSERVER_GEO_STYLE = "" settings.GEOSERVER_URL = "" def local_render_to_response(*args, **kwargs): from django.template import loader, RequestContext 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 r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") r7 = ReputationAction(name="add stewardship", description="blah") r8 = ReputationAction(name="remove stewardship", description="blah") for r in [r1, r2, r3, r4, r5, r6, r7, r8]: r.save() bv = BenefitValues( co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166, voc=4.69, ozone=5.0032, natural_gas=1.25278, nox=12.79, stormwater=0.0078, sox=3.72, bvoc=4.96, ) bv.save() dbh = "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]" dbh2 = "[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]" rsrc1 = Resource(meta_species="BDM OTHER", region="NoEastXXX") rsrc2 = Resource(meta_species="BDL OTHER", region="NoEastXXX") rsrc1.save() rsrc2.save() u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim", "*****@*****.**", "jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) up.save() u.reputation = Reputation(user=u) u.reputation.save() amy_filter_result = User.objects.filter(username="******") if not amy_filter_result: amy = User.objects.create_user("amy", "*****@*****.**", "amy") else: amy = amy_filter_result[0] amy.is_staff = False amy.is_superuser = False amy.save() amy_profile = UserProfile(user=amy) amy_profile.save() amy.reputation = Reputation(user=amy) amy.reputation.save() olivia_filter_result = User.objects.filter(username="******") if not amy_filter_result: olivia = User.objects.create_user("olivia", "*****@*****.**", "olivia") else: olivia = olivia_filter_result[0] olivia.is_staff = False olivia.is_superuser = False olivia.save() olivia_profile = UserProfile(user=olivia) olivia_profile.save() olivia.reputation = Reputation(user=olivia) olivia.reputation.save() 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 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon(Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0)))) z2geom = MultiPolygon(Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100)))) z1 = ZipCode(zip="19107", geometry=z1geom) z2 = ZipCode(zip="10001", geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon(Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n1, ) agn2 = AggregateNeighborhood( annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n2, ) agn1.save() agn2.save() s1 = Species(symbol="s1", genus="testus1", species="specieius1", cultivar_name="", family="", alternate_symbol="a1") s2 = Species(symbol="s2", genus="testus2", species="specieius2", cultivar_name="", family="", alternate_symbol="a2") s3 = Species(symbol="s3", genus="testus2", species="specieius3", cultivar_name="", family="", alternate_symbol="a3") s1.native_status = "True" s1.fall_conspicuous = True s1.flower_conspicuous = True s1.palatable_human = True s2.native_status = "True" s2.fall_conspicuous = False s2.flower_conspicuous = True s2.palatable_human = False s2.wildlife_value = True s3.wildlife_value = True s1.save() s2.save() s3.save() s1.resource.add(rsrc1) s2.resource.add(rsrc2) s3.resource.add(rsrc2) ie = ImportEvent(file_name="site_add") ie.save()
def setupTreemapEnv(): Choices(field="plot_type", key="blah", value="blah", key_type="str").save() r1 = ReputationAction(name="edit verified", description="blah") r2 = ReputationAction(name="edit tree", description="blah") r3 = ReputationAction(name="Administrative Action", description="blah") r4 = ReputationAction(name="add tree", description="blah") r5 = ReputationAction(name="edit plot", description="blah") r6 = ReputationAction(name="add plot", description="blah") for r in [r1, r2, r3, r4, r5, r6]: r.save() bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys", electricity=0.1166, voc=4.69, ozone=5.0032, natural_gas=1.25278, nox=12.79, stormwater=0.0078, sox=3.72, bvoc=4.96) bv.save() dbh = "[1.0, 2.0, 3.0]" rsrc = Resource(meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh, aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh, aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh, co2_storage_dbh=dbh, aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh, bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh, hydro_interception_dbh=dbh, natural_gas_dbh=dbh) rsrc.save() u = User.objects.filter(username="******") if u: u = u[0] else: u = User.objects.create_user("jim", "*****@*****.**", "jim") u.is_staff = True u.is_superuser = True u.save() up = UserProfile(user=u) u.reputation = Reputation(user=u) u.reputation.save() 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 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom) n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom) n1.save() n2.save() z1geom = MultiPolygon( Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0)))) z2geom = MultiPolygon( Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100)))) z1 = ZipCode(zip="19107", geometry=z1geom) z2 = ZipCode(zip="10001", geometry=z2geom) z1.save() z2.save() exgeom1 = MultiPolygon( Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0)))) ex1 = ExclusionMask(geometry=exgeom1, type="building") ex1.save() agn1 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n1) agn2 = AggregateNeighborhood(annual_stormwater_management=0.0, annual_electricity_conserved=0.0, annual_energy_conserved=0.0, annual_natural_gas_conserved=0.0, annual_air_quality_improvement=0.0, annual_co2_sequestered=0.0, annual_co2_avoided=0.0, annual_co2_reduced=0.0, total_co2_stored=0.0, annual_ozone=0.0, annual_nox=0.0, annual_pm10=0.0, annual_sox=0.0, annual_voc=0.0, annual_bvoc=0.0, total_trees=0, total_plots=0, location=n2) agn1.save() agn2.save() s1 = Species(symbol="s1", genus="testus1", species="specieius1") s2 = Species(symbol="s2", genus="testus2", species="specieius2") s1.save() s2.save() ie = ImportEvent(file_name='site_add') ie.save()
def test_all_tree_data(self): s1_gsc = Species(symbol='S1G__', scientific_name='',family='', genus='g1', species='s1', cultivar_name='c1') s1_gsc.save() csv = """ | point x | point y | tree owner | tree steward | diameter | tree height | | 45.53 | 31.1 | jimmy | jane | 23.1 | 90.1 | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() self.assertEqual(tree.tree_owner, 'jimmy') self.assertEqual(tree.steward_name, 'jane') self.assertEqual(tree.dbh, 23.1) self.assertEqual(tree.height, 90.1) csv = """ | point x | point y | canopy height | genus | species | cultivar | | 45.59 | 31.1 | 112 | | | | | 45.58 | 33.9 | | g1 | s1 | c1 | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) rows = ie.treeimportrow_set.order_by('idx').all() tree1 = rows[0].plot.current_tree() tree2 = rows[1].plot.current_tree() self.assertEqual(tree1.canopy_height, 112) self.assertIsNone(tree1.species) self.assertEqual(tree2.species.pk, s1_gsc.pk) csv = """ | point x | point y | tree sponsor | date planted | read only | tree url | | 45.12 | 55.12 | treeluvr | 2012-02-03 | true | http://spam | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() dateplanted = date(2012,2,3) self.assertEqual(tree.sponsor, 'treeluvr') self.assertEqual(tree.date_planted, dateplanted) self.assertEqual(tree.readonly, True) self.assertEqual(tree.url, 'http://spam') csv = """ | point x | point y | condition | canopy condition | pests and diseases | local projects | | 45.66 | 53.13 | Dead | %s | %s | %s | """ % ('Full - No Gaps', 'Phytophthora alni', 'San Francisco Landmark') ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() self.assertEqual(tree.condition, '1') self.assertEqual(tree.canopy_condition, '1') self.assertEqual(tree.pests, '9')
def test_all_tree_data(self): s1_gsc = Species(symbol='S1G__', scientific_name='', family='', genus='g1', species='s1', cultivar_name='c1') s1_gsc.save() csv = """ | point x | point y | tree owner | tree steward | diameter | tree height | | 45.53 | 31.1 | jimmy | jane | 23.1 | 90.1 | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() self.assertEqual(tree.tree_owner, 'jimmy') self.assertEqual(tree.steward_name, 'jane') self.assertEqual(tree.dbh, 23.1) self.assertEqual(tree.height, 90.1) csv = """ | point x | point y | canopy height | genus | species | cultivar | | 45.59 | 31.1 | 112 | | | | | 45.58 | 33.9 | | g1 | s1 | c1 | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) rows = ie.treeimportrow_set.order_by('idx').all() tree1 = rows[0].plot.current_tree() tree2 = rows[1].plot.current_tree() self.assertEqual(tree1.canopy_height, 112) self.assertIsNone(tree1.species) self.assertEqual(tree2.species.pk, s1_gsc.pk) csv = """ | point x | point y | tree sponsor | date planted | read only | tree url | | 45.12 | 55.12 | treeluvr | 2012-02-03 | true | http://spam | """ ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() dateplanted = date(2012, 2, 3) self.assertEqual(tree.sponsor, 'treeluvr') self.assertEqual(tree.date_planted, dateplanted) self.assertEqual(tree.readonly, True) self.assertEqual(tree.url, 'http://spam') csv = """ | point x | point y | condition | canopy condition | pests and diseases | local projects | | 45.66 | 53.13 | Dead | %s | %s | %s | """ % ('Full - No Gaps', 'Phytophthora alni', 'San Francisco Landmark') ieid = self.run_through_commit_views(csv) ie = TreeImportEvent.objects.get(pk=ieid) tree = ie.treeimportrow_set.all()[0].plot.current_tree() self.assertEqual(tree.condition, '1') self.assertEqual(tree.canopy_condition, '1') self.assertEqual(tree.pests, '9')