def test_unicode_string_and_repr_SpeciesQuerySet(self): query_set = SpeciesQuerySet(items=[ Species(name='species1'), Species(name='species2'), ]) self.assertEqual(repr(query_set), '<SpeciesQuerySet - 2>') self.assertEqual(str(query_set), '<SpeciesQuerySet - 2>') self.assertEqual(u"%s" % query_set, '<SpeciesQuerySet - 2>')
def populate_crops(): for common_name in CROPS: common_name = common_name family = CROPS[common_name][0] genus = CROPS[common_name][1] species = CROPS[common_name][2] existing_family = Family.objects.filter(name=family) if existing_family.count() > 0: print " Family ", family, " already exists in database." existing_family = existing_family[0] else: f = Family(name=family) f.save() existing_family = f print " Saved", family, "as Family." existing_genus = Genus.objects.filter(name=genus) if existing_genus.count() > 0: print " Genus ", genus, " already exists in database." existing_genus = existing_genus[0] else: g = Genus(name=genus, family=existing_family) g.save() existing_genus = g print " Saved", genus, "as Genus." existing_species = Species.objects.filter(species=species, genus=existing_genus) if existing_species.count() > 0: print " Species ", species, " already exists in database." existing_species = existing_species[0] else: s = Species(species=species, genus=existing_genus) s.save() existing_species = s print " Saved", species, "as Species." existing_crop = Crop.objects.filter(species=existing_species) if existing_crop.count() > 0: print " Crop ", common_name, " already exists in database." existing_crop = existing_crop[0] else: c = Crop(species=existing_species) c.save() existing_crop = c print " Saved", common_name, "as Crop." existing_common_name = CommonName.objects.filter(crop=existing_crop, name=common_name) if existing_common_name.count() > 0: print " Common name for ", species, " already exists in database." existing_common_name = existing_common_name[0] else: cn = CommonName(crop=existing_crop, name=common_name, preferred=True) cn.save() existing_common_name = cn print " Saved", common_name, " for ", species, "as CommonName."
def test_get_all_species_1(self) : species = Species.get_all() species_name = [species[i].name for i in range(len(species))] expected = ['Krevaaki', 'Jawa', 'Ewok', 'Rodian', 'Kiffar', 'Talz', 'Gand', 'Noghri', 'Aqualish', 'Bothan', 'Kubaz', 'Quarren', 'Sullustan', 'Ssi-ruuk', 'Chevin', 'Khommite', 'Hutt', 'Chadra-Fan', 'Bith', 'Kowakian monkey-lizard', 'Gran', 'Chiss', 'Trandoshan', 'Wookiee', "Twi'lek", 'Dathomirian', 'Omwati', 'Shistavanen', 'Klatooinian', 'Whiphid', 'Human', 'Firrerreo', 'Anzati', 'Ithorian', 'Devaronian', "Yoda's species", 'Rybet', 'Gamorrean'] # comparing the two list elements ignoring order result = not set(species_name).isdisjoint(expected) self.assertEqual(result, True)
def test_species_model(self): species_to_test = Species(name='myspeciesname') self.assertEqual(species_to_test.name, 'myspeciesname') self.assertEqual(repr(species_to_test), '<Species - myspeciesname>') self.assertEqual(str(species_to_test), '<Species - myspeciesname>') self.assertEqual(u"%s" % species_to_test, '<Species - myspeciesname>')
def test_get_all_species_classification (self) : species = Species.get_all() species_classification = [species[i].classification for i in range(len(species))] expected = ['Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Insectoid', 'Unknown', 'Amphibian', 'Mammal', 'Mammalian', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Craniopod', 'Reptilian', 'Unknown', 'Unknown', 'Unknown', 'Mammal', 'Unknown', 'Unknown', 'Near-Human', 'Unknown', 'Unknown', 'Unknown', 'Mammal', 'Unknown', 'Humanoid', 'Unknown', 'Unknown', 'Unknown', 'Unknown', 'Unknown'] # comparing the two list elements ignoring order result = not set(species_classification).isdisjoint(expected) self.assertEqual(result, True)
def test_get_all_species_language (self) : species = Species.get_all() species_language = [species[i].language for i in range(len(species))] expected = ['Unknown', 'Jawaese', 'Ewokese', 'Rodese, Basic, Huttese', 'Unknown', 'Talzzi', 'Gand', 'Honoghran', 'Aqualish\nGalactic Basic Standard', 'Bothese \nBotha \nGalactic Basic Standard', 'Kubazian', 'Quarrenese', 'Sullustese', 'Ssi-ruuvi', 'Chevin', 'Galactic Basic Standard', 'Huttese', 'Chadra-Fan', 'Bith', 'Unknown', 'Gran', 'Cheunh\nSy Bisti\nMinnisiat\nOther trade languages', 'Dosh', 'Shyriiwook\nXaczik\nThykarann', "Twi'leki, Basic, Lekku", 'Galactic Basic Standard', 'Omwatese', 'Shistavanen \nBasic', 'Huttese\nKlatooinian', 'Whiphid', 'Galactic Basic Standard\nOthers', 'Unknown', 'Anzat language\nGalactic Basic Standard', 'Ithorese', 'Devaronese', 'Unknown', 'Rybese', 'Gamorrese'] # comparing the two list elements ignoring order result = not set(species_language).isdisjoint(expected) self.assertEqual(result, True)
def test_get_all_species_planets (self) : species = Species.get_all() species_planets = [species[i].planet for i in range(len(species))] expected = ['Kashyyyk', 'Coruscant', "Clak'dor VII", 'Omwat'] # comparing the two list elements ignoring order result = not set(species_planets).isdisjoint(expected) self.assertEqual(result, True)
def postSpecies(request): if request.method == 'POST': body = json.loads(request.body) common_name = body['common_name'] newSpecies = Species(common_name=common_name) newSpecies.save() if body.has_key("flower_color"): flower_color = Color.objects.get(color="yellow-green") newSpecies.flower_color.add(flower_color) newSpecies.save() species_serialized = json.dumps(newSpecies.as_dict()) return HttpResponse(species_serialized) return HttpResponse("No body")
def test_species_repr_2(self): actual = str(Species.get("Hutt")) self.assertEqual(actual, "<name Hutt>")
def test_species_repr_1(self): actual = str(Species.get("Wookiee")) self.assertEqual(actual, "<name Wookiee>")
def csvToDB(request): if request.method == 'POST': file = request.FILES['file'] reader = csv.DictReader(file) result = [] for row in reader: newSpecies = Species( common_name=row['Common Name'], scientific_name=row['Scientific Name'], usda_symbol=row['Symbol'], base_age_height=strToFloat(row['Height at Base Age, Maximum (feet)']), mature_height=strToFloat(row['Height, Mature (feet)']), fire_resistant=yesNoToBool(row['Fire Resistance']), flower_conspicuous=yesNoToBool(row['Flower Conspicuous']), allelopathic=yesNoToBool(row['Known Allelopath']), leaf_retentive=yesNoToBool(row['Leaf Retention']), resproutable=yesNoToBool(row['Resprout Ability']), ) newSpecies.save() if row['County']: counties = row['County'].split(", ") for county in counties: newCounty = County.objects.get(county=county) newSpecies.county.add(newCounty) if row['Flower Color']: newFlowerColor = Color.objects.get(color= row['Flower Color'].lower()) newSpecies.flower_color.add(newFlowerColor) if row['Shape and Orientation']: newShape = Shape.objects.get(shape=row['Shape and Orientation'].lower()) newSpecies.shape.add(newShape) if row['Category']: newCategory = Category.objects.get(category=row['Category'].lower()) newSpecies.category.add(newCategory) if row['Duration']: durations = row['Duration'].split(", ") for duration in durations: newDuration = Duration.objects.get(duration=duration.lower()) newSpecies.duration.add(newDuration) if row['Active Growth Period']: if(row['Active Growth Period'] == "Year Round"): row['Active Growth Period'] = "Spring, Summer, Fall, Winter" replaced = row['Active Growth Period'].replace(" and ", ", ") growth_periods = replaced.split(", ") for growth_period in growth_periods: newActiveGrowthPeriod = ActiveGrowthPeriod.objects.get(active_growth_period=growth_period.lower()) newSpecies.active_growth_period.add(newActiveGrowthPeriod) if row['Growth Habit']: growth_habits = row['Growth Habit'].split(", ") if 'and' in row['Growth Habit']: growth_habits = row['Growth Habit'].split(" and ") for growth_habit in growth_habits: newGrowthHabit = GrowthHabit.objects.get(growth_habit=growth_habit.lower()) newSpecies.growth_habit.add(newGrowthHabit) if row['Growth Form']: newGrowthForm = GrowthForm.objects.get(growth_form=row['Growth Form'].lower()) newSpecies.growth_form.add(newGrowthForm) if row['Growth Rate']: newGrothRate = GrowthRate.objects.get(growth_rate=row['Growth Rate'].lower()) newSpecies.growth_rate.add(newGrothRate) if row['Lifespan']: newLifespan = Lifespan.objects.get(lifespan=row['Lifespan'].lower()) newSpecies.lifespan.add(newLifespan) if row['Toxicity']: newToxicity = Toxicity.objects.get(toxicity=row['Toxicity'].lower()) newSpecies.toxicity.add(newToxicity) newSpecies.save() result.append(newSpecies) return JsonResponse(result, safe=False)