class TestMammalModels(TestCase): def setUp(self): self.grade_level = GradeLevel(label="grade_level_here") self.grade_level.save() self.bait = Bait(bait_name="very good nibbles") self.bait.save() self.species = Species(latin_name="official_mouse_name", common_name="blackrock_mouse", about_this_species="too smart for traps",) self.species.save() self.label_menu = LabelMenu(label="label_here") self.label_menu.save() # left off sex of animal, age of animal, scale used # - foreign keys? other details which were booleans # with default left off self.animal = Animal(species=self.species, description="this is a special mouse", tag_number="6789", health="excellent", weight_in_grams=35) self.animal.save() self.trap = Trap(trap_string="ineffective mouse trap", notes="trap has not gotten any mice yet") self.trap.save() self.habitat = Habitat(label="habitat label", blurb="this is a habitat", image_path_for_legend="/path/here", color_for_map="111") self.habitat.save() self.school = School(name="school", address="school address", contact_1_name="contact 1 for school", contact_1_phone="000-000-0000", contact_1_email="*****@*****.**", contact_2_name="contact 2 for school", contact_2_phone="111-111-1111", contact_2_email="*****@*****.**", notes="this student has appropriate information") self.school.save() def test_grade_level_uni(self): gl = str(self.grade_level) self.assertEqual(gl, "grade_level_here") self.new_grade_level = GradeLevel() self.assertEqual(type(GradeLevel()), type(self.new_grade_level)) self.assertTrue(hasattr(self.new_grade_level, 'label')) self.new_grade_level.label = "value of label" self.new_grade_level.save() self.assertTrue(self.new_grade_level.id) self.assertEqual(str(self.new_grade_level), "value of label") self.another_grade_level = GradeLevel() self.assertEqual(self.another_grade_level.label, "") # try: # self.another_grade_level.label = "a" * 267 # self.another_grade_level.save() # self.fail() # except DatabaseError: # pass # expected self.assertIn("label", self.new_grade_level.dir()) def test_grade_level_no_self(self): new_grade_level = GradeLevel() self.assertEqual(type(GradeLevel()), type(new_grade_level)) self.assertTrue(hasattr(new_grade_level, 'label')) new_grade_level.label = "value of label" new_grade_level.save() self.assertTrue(new_grade_level.id) self.assertEqual(str(new_grade_level), "value of label") another_grade_level = GradeLevel() self.assertEqual(another_grade_level.label, "") # try: # another_grade_level.label = "a" * 267 # another_grade_level.save() # self.fail() # except DatabaseError: # pass # expected self.assertIn("label", new_grade_level.dir()) def test_grade_level_dir(self): gl = self.grade_level.dir() self.assertEqual(type(gl), list) self.assertIn("dir", gl) def test_species_uni(self): sp_uni = str(self.species) self.assertEqual(sp_uni, "blackrock_mouse") self.assertNotEqual(sp_uni, "blkms") self.assertIsNot(sp_uni, "blkms") self.new_species = Species() self.new_species.common_name = "blkms" self.assertEqual(str(self.new_species), "blkms") def test_species_dir(self): sp = self.species.dir() self.assertEqual(type(sp), list) self.assertIn("dir", sp) def test_trap_uni(self): trap_uni = str(self.trap) self.assertEqual(trap_uni, "ineffective mouse trap") def test_trap_dir(self): trap_dir = self.trap.dir() self.assertEqual(type(trap_dir), list) self.assertIn("trap_string", trap_dir) self.assertIn("notes", trap_dir) def test_bait_uni(self): bait_uni = str(self.bait) self.assertEqual(bait_uni, "very good nibbles") self.assertEqual(str(self.bait), "very good nibbles") self.new_bait = Bait() self.assertEqual(type(Bait()), type(self.new_bait)) self.assertTrue(hasattr(self.new_bait, "bait_name")) def test_bait_dir(self): bait_dir = self.bait.dir() self.assertEqual(type(bait_dir), list) self.assertIn("bait_name", bait_dir) def test_label_menu_uni(self): label_level_uni = str(self.label_menu) self.assertEqual(label_level_uni, self.label_menu.label) self.assertEqual(label_level_uni, "label_here") def test_animal_uni_dir(self): animal_uni = str(self.animal) self.assertEqual(animal_uni, "blackrock_mouse") animal_dir = self.animal.dir() self.assertIn("age", animal_dir) def test_habitat_uni_dir(self): habitat_uni = str(self.habitat) self.assertEqual(habitat_uni, self.habitat.label) habitat_dir = self.habitat.dir() self.assertIn("label", habitat_dir) self.assertIn("blurb", habitat_dir) self.assertIn("image_path_for_legend", habitat_dir) self.assertIn("color_for_map", habitat_dir) def test_school_uni(self): school_uni = str(self.school) self.assertEqual(school_uni, self.school.name) self.new_school = School() self.new_school.name = "new school" self.assertEqual(str(self.new_school), "new school")
class TestMammalModels(TestCase): def setUp(self): self.grade_level = GradeLevel(label="grade_level_here") self.grade_level.save() self.bait = Bait(bait_name="very good nibbles") self.bait.save() self.species = Species( latin_name="official_mouse_name", common_name="blackrock_mouse", about_this_species="too smart for traps", ) self.species.save() self.label_menu = LabelMenu(label="label_here") self.label_menu.save() # left off sex of animal, age of animal, scale used # - foreign keys? other details which were booleans # with default left off self.animal = Animal(species=self.species, description="this is a special mouse", tag_number="6789", health="excellent", weight_in_grams=35) self.animal.save() self.trap = Trap(trap_string="ineffective mouse trap", notes="trap has not gotten any mice yet") self.trap.save() self.habitat = Habitat(label="habitat label", blurb="this is a habitat", image_path_for_legend="/path/here", color_for_map="111") self.habitat.save() self.school = School(name="school", address="school address", contact_1_name="contact 1 for school", contact_1_phone="000-000-0000", contact_1_email="*****@*****.**", contact_2_name="contact 2 for school", contact_2_phone="111-111-1111", contact_2_email="*****@*****.**", notes="this student has appropriate information") self.school.save() def test_grade_level_uni(self): gl = self.grade_level.__unicode__() self.assertEquals(gl, "grade_level_here") self.new_grade_level = GradeLevel() self.failUnlessEqual(type(GradeLevel()), type(self.new_grade_level)) self.failUnless(hasattr(self.new_grade_level, 'label')) self.new_grade_level.label = "value of label" self.new_grade_level.save() self.failUnless(self.new_grade_level.id) self.assertEquals(unicode(self.new_grade_level), "value of label") self.another_grade_level = GradeLevel() self.assertEquals(self.another_grade_level.label, "") # try: # self.another_grade_level.label = "a" * 267 # self.another_grade_level.save() # self.fail() # except DatabaseError: # pass # expected self.assertIn("label", self.new_grade_level.dir()) def test_grade_level_no_self(self): new_grade_level = GradeLevel() self.failUnlessEqual(type(GradeLevel()), type(new_grade_level)) self.failUnless(hasattr(new_grade_level, 'label')) new_grade_level.label = "value of label" new_grade_level.save() self.failUnless(new_grade_level.id) self.assertEquals(unicode(new_grade_level), "value of label") another_grade_level = GradeLevel() self.assertEquals(another_grade_level.label, "") # try: # another_grade_level.label = "a" * 267 # another_grade_level.save() # self.fail() # except DatabaseError: # pass # expected self.assertIn("label", new_grade_level.dir()) def test_grade_level_dir(self): gl = self.grade_level.dir() self.assertEquals(type(gl), list) self.assertIn("dir", gl) def test_species_uni(self): sp_uni = self.species.__unicode__() self.assertEquals(sp_uni, "blackrock_mouse") self.assertNotEquals(sp_uni, "blkms") self.assertIsNot(sp_uni, "blkms") self.new_species = Species() self.new_species.common_name = "blkms" self.assertEquals(unicode(self.new_species), "blkms") def test_species_dir(self): sp = self.species.dir() self.assertEquals(type(sp), list) self.assertIn("dir", sp) def test_trap_uni(self): trap_uni = self.trap.__unicode__() self.assertEquals(trap_uni, "ineffective mouse trap") def test_trap_dir(self): trap_dir = self.trap.dir() self.assertEquals(type(trap_dir), list) self.assertIn("trap_string", trap_dir) self.assertIn("notes", trap_dir) def test_bait_uni(self): bait_uni = self.bait.__unicode__() self.assertEquals(bait_uni, "very good nibbles") self.assertEquals(unicode(self.bait), "very good nibbles") self.new_bait = Bait() self.failUnlessEqual(type(Bait()), type(self.new_bait)) self.failUnless(hasattr(self.new_bait, "bait_name")) def test_bait_dir(self): bait_dir = self.bait.dir() self.assertEquals(type(bait_dir), list) self.assertIn("bait_name", bait_dir) def test_label_menu_uni(self): label_level_uni = self.label_menu.__unicode__() self.assertEquals(label_level_uni, self.label_menu.label) self.assertEquals(label_level_uni, "label_here") def test_animal_uni_dir(self): animal_uni = self.animal.__unicode__() self.assertEquals(animal_uni, "blackrock_mouse") animal_dir = self.animal.dir() self.assertIn("age", animal_dir) def test_habitat_uni_dir(self): habitat_uni = self.habitat.__unicode__() self.assertEquals(habitat_uni, self.habitat.label) habitat_dir = self.habitat.dir() self.assertIn("label", habitat_dir) self.assertIn("blurb", habitat_dir) self.assertIn("image_path_for_legend", habitat_dir) self.assertIn("color_for_map", habitat_dir) def test_school_uni(self): school_uni = self.school.__unicode__() self.assertEquals(school_uni, self.school.name) self.new_school = School() self.new_school.name = "new school" self.assertEquals(unicode(self.new_school), "new school")
class TestMoreMammalModels(TestCase): def setUp(self): ''' trying to create sighting leaving out attibtutes whic are key or objects - location = objects = species = date = observers = observation_type = how_many_observed = notes =''' self.sighting = Sighting() self.sighting.save() self.expedition = Expedition() self.expedition.save() # objects = models.GeoManager() self.trap_location = TrapLocation( expedition=self.expedition, notes_about_location="Notes about the location", team_letter='C', whether_a_trap_was_set_here=True, bait_still_there=False, notes_about_outcome='This is a good place for a trap.', student_names='Student 1, Student 2, Student 3') self.trap_location.save() self.species = Species(latin_name="official_mouse_name", common_name="blackrock_mouse", about_this_species="too smart for traps",) self.species.save() # left off sex of animal, age of animal, scale used - foreign keys? # other details which were booleans with default left off self.animal_1 = Animal(species=self.species, description="this is a special mouse", tag_number="6789", health="excellent", weight_in_grams=35) self.animal_1.save() # left off sex of animal, age of animal, scale used - foreign # keys? other details which were booleans with default left off self.animal_2 = Animal(species=self.species, description="this is a naughty mouse", tag_number="8355", health="excellent", weight_in_grams=45) self.animal_2.save() # left off sex of animal, age of animal, scale used - foreign keys? # other details which were booleans with default left off self.animal_3 = Animal(species=self.species, description="this is a super mouse", tag_number="8888", health="excellent", weight_in_grams=15) self.animal_3.save() self.another_expedition = Expedition( start_date_of_expedition=datetime.now(), end_date_of_expedition=datetime.now()) self.another_expedition.save() self.habitat = Habitat(label="habitat label", blurb="this is a habitat", image_path_for_legend="/path/here", color_for_map="111") self.habitat.save() self.trap_1 = TrapLocation(expedition=self.another_expedition, team_letter="A", team_number=1, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_1) self.trap_1.save() self.trap_2 = TrapLocation(expedition=self.another_expedition, team_letter="B", team_number=2, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_2) self.trap_2.save() self.trap_3 = TrapLocation(expedition=self.another_expedition, team_letter="C", team_number=3, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_3) self.trap_3.save() self.trap_4 = TrapLocation(expedition=self.another_expedition, team_letter="D", team_number=4, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat) self.trap_4.save() self.another_expedition.save() self.timed_expedition = Expedition( end_date_of_expedition=datetime.now()) self.timed_expedition.save() self.time_trap = TrapLocation(expedition=self.timed_expedition, team_letter="team name here", team_number=6, habitat=self.habitat, whether_a_trap_was_set_here=True, bait_still_there=False, animal=self.animal_1) self.time_trap.save() self.new_sighting = Sighting(species=self.species, date=datetime.now()) self.new_sighting.save() self.grid_point_nw = GridPoint() self.grid_point_nw.save() self.grid_point_ne = GridPoint() self.grid_point_ne.save() self.grid_point_sw = GridPoint() self.grid_point_sw.save() self.grid_point_se = GridPoint() self.grid_point_se.save() self.grid_point_center = GridPoint() self.grid_point_center.save() self.grid_square = GridSquare( NW_corner=self.grid_point_nw, NE_corner=self.grid_point_ne, SW_corner=self.grid_point_sw, SE_corner=self.grid_point_se, center=self.grid_point_center, display_this_square=False, row=1, column=0, access_difficulty=3, terrain_difficulty=4) self.grid_square.save() def test_sighting_methods(self): self.new_sighting.set_lat_long([5.0, 8.0]) self.assertIsNotNone(self.new_sighting.location) self.assertEquals(self.new_sighting.lat(), 5.0) # make sure blank sightings returns None self.assertEquals(self.sighting.lat(), None) self.assertEquals(self.new_sighting.lon(), 8.0) self.assertEquals(self.sighting.lon(), None) self.assertIsNotNone(self.new_sighting.date_for_solr()) def test_species_has_attributes(self): species_attributes = self.species.dir() self.assertIn("latin_name", species_attributes) self.assertIn("common_name", species_attributes) self.assertIn("about_this_species", species_attributes) self.assertEquals(self.species.latin_name, "official_mouse_name") self.assertEquals(self.species.common_name, "blackrock_mouse") self.assertEquals(self.species.about_this_species, "too smart for traps") self.other_species = Species() self.other_species.latin_name = "official_name" self.other_species.common_name = "blackrock" self.other_species.about_this_species = "too smart for traps" self.assertEquals(self.other_species.latin_name, "official_name") self.assertEquals(self.other_species.common_name, "blackrock") self.assertEquals(self.other_species.about_this_species, "too smart for traps") def test_grid_point_assignments_dir_and_uni(self): self.grid_point_nw.set_lat_long([4, 5]) gp_dir = self.grid_point_nw.dir() self.grid_point_nw.save() self.assertIn("geo_point", gp_dir) self.assertIn("objects", gp_dir) self.assertEquals(self.grid_point_nw.lat(), 4.0) self.assertEquals(self.grid_point_nw.lon(), 5.0) self.assertEquals(self.grid_point_nw.NSlat(), '%0.5F N' % abs(self.grid_point_nw.lat())) self.assertEquals(self.grid_point_nw.EWlon(), '%0.5F E' % abs(self.grid_point_nw.lon())) self.assertEquals(self.grid_point_nw.gps_coords(), "%s, %s" % (self.grid_point_nw.NSlat(), self.grid_point_nw.EWlon())) self.assertEquals(unicode(self.grid_point_nw), self.grid_point_nw.gps_coords()) self.assertEquals(type(self.grid_point_nw.create([6, 7])), type(GridPoint())) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_se.save() self.assertEquals(self.grid_point_se.NSlat(), '%0.5F S' % abs(self.grid_point_se.lat())) self.assertEquals(self.grid_point_se.EWlon(), '%0.5F W' % abs(self.grid_point_se.lon())) self.assertEquals(self.grid_point_se.lat(), self.grid_point_se.geo_point.coords[0]) self.assertEquals(self.grid_point_se.lon(), self.grid_point_se.geo_point.coords[1]) def test_sighting_has_attributes(self): contains = dir(self.sighting) self.assertIn("set_lat_long", contains) self.assertIn("lat", contains) self.assertIn("lon", contains) self.assertIn("date_for_solr", contains) def test_expedition_has_attributes(self): contains = dir(self.expedition) self.assertIn("get_absolute_url", contains) self.assertIn("how_many_mammals_caught", contains) self.assertIn("team_points", contains) self.assertIn("set_end_time_if_none", contains) self.assertIn("end_minute_string", contains) self.assertIn("end_hour_string", contains) self.assertIn("set_end_time_from_strings", contains) self.assertIn("transects_json", contains) def test_expedition_dir(self): contains = self.expedition.dir() self.assertIn("get_absolute_url", contains) self.assertIn("how_many_mammals_caught", contains) self.assertIn("team_points", contains) self.assertIn("set_end_time_if_none", contains) self.assertIn("end_minute_string", contains) self.assertIn("end_hour_string", contains) self.assertIn("set_end_time_from_strings", contains) self.assertIn("transects_json", contains) def test_trap_location_has_attributes(self): contains = dir(self.trap_location) self.assertIn("create_from_obj", contains) self.assertIn("recreate_point_obj", contains) self.assertIn("date", contains) self.assertIn("date_for_solr", contains) self.assertIn("trap_nickname", contains) self.assertIn("transect_endpoints", contains) self.assertIn("set_transect_bearing_wrt_magnetic_north", contains) self.assertIn("transect_bearing_wrt_magnetic_north", contains) self.assertIn("set_suggested_lat_long", contains) self.assertIn("set_actual_lat_long", contains) def test_trap_location_date_none(self): the_date = self.trap_location.date() self.assertIsNotNone(the_date) the_date_solr = self.trap_location.date_for_solr() self.assertIsNotNone(the_date_solr) def test_trap_location_date_exists(self): date = self.time_trap.date() self.assertIsNotNone(date) date_solr = self.time_trap.date_for_solr() self.assertIsNotNone(date_solr) def test_trap_location_nickname(self): team_nickname = self.time_trap.trap_nickname() self.assertEquals(team_nickname, (self.time_trap.team_letter + str(self.time_trap.team_number))) def test_trap_location_species(self): species_does_not_exist = self.trap_location.species_if_any() self.assertIsNone(species_does_not_exist) has_species = self.time_trap.species_if_any() self.assertIsNotNone(has_species) self.assertEquals(has_species, "blackrock_mouse") def test_trap_location_habitat(self): no_habitat = self.trap_location.habitat_if_any() self.assertIsNone(no_habitat) has_habitat = self.time_trap.habitat_if_any() self.assertIsNotNone(has_habitat) self.assertEquals(has_habitat, "habitat label") def test_habitat_id(self): no_habitat_id = self.trap_location.habitat_id_if_any() self.assertIsNone(no_habitat_id) has_habitat_id = self.time_trap.habitat_id_if_any() self.assertIsNotNone(has_habitat_id) def test_trap_location_dir(self): dir_test = self.time_trap.dir() self.assertIn("habitat_if_any", dir_test) self.assertIn("habitat_id_if_any", dir_test) self.assertIn("species_if_any", dir_test) def test_create_observation_type(self): observation = ObservationType() self.failUnlessEqual(type(ObservationType()), type(observation)) def test_create_observation_self(self): self.observation = ObservationType() self.observation.save() self.failUnlessEqual(type(ObservationType()), type(self.observation)) def test_grid_square_uni_dir(self): self.assertEquals(unicode(self.grid_square), "Row %d, column %d" % (self.grid_square.row, self.grid_square.column)) dir_test = self.grid_square.dir() self.assertIn("row", dir_test) self.assertIn("column", dir_test) self.assertIn("access_difficulty", dir_test) self.assertIn("corner_names", dir_test) self.assertIn("corners", dir_test) self.assertIn("corner_obj", dir_test) self.assertIn("corner_obj_json", dir_test) self.assertIn("info_for_display", dir_test) self.assertIn("block_json", dir_test) def test_grid_square_corner_names_method(self): corner_names = self.grid_square.corner_names() self.assertEquals( ['SW_corner', 'NW_corner', 'NE_corner', 'SE_corner', 'center'], corner_names) '''There may be a typo in the actual program says for corner_name may be supposed to be corner_names''' # def test_grid_square_corners(self): # #corner_names = self.grid_square.corner_names() # corners = self.grid_square.corners() # self.assertIn( "SW_corner", corners) # self.assertIn( type(GridPoint()), corners) def test_corner_obj(self): self.grid_point_nw.set_lat_long([4, 5]) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_sw.set_lat_long([-8, -9]) self.grid_point_ne.set_lat_long([-8, -9]) self.grid_point_center.set_lat_long([-8, -9]) corner_objects = self.grid_square.corner_obj() self.assertEquals([[-8.0, -9.0], [4.0, 5.0], [-8.0, -9.0], [-8.0, -9.0], [-8.0, -9.0]], corner_objects) def test_corner_obj_json(self): self.grid_point_nw.set_lat_long([4, 5]) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_sw.set_lat_long([-8, -9]) self.grid_point_ne.set_lat_long([-8, -9]) self.grid_point_center.set_lat_long([-8, -9]) corner_obj_json = self.grid_square.corner_obj_json() self.assertIn("[4.0, 5.0]", corner_obj_json) self.assertEquals(('[[-8.0, -9.0], [4.0, 5.0], [-8.0, -9.0], ' '[-8.0, -9.0], [-8.0, -9.0]]'), corner_obj_json) def test_battleship_coords(self): battleship_coordinates = self.grid_square.battleship_coords() self.assertIsNotNone(battleship_coordinates) # Test More Expedition Methods def test_trap_locations(self): '''Test methods requiring TrapLocations, Animals, and Teams''' '''This is not a good test - the unicode returns the gps coordinates so it is returning TrapLocation objects but need to verify that they have team letter and number''' ae = self.another_expedition trap_location_team = ae.trap_locations_ordered_by_team() self.assertEquals(1, trap_location_team[0].team_number) self.assertEquals('A', trap_location_team[0].team_letter) self.assertEquals(2, trap_location_team[1].team_number) self.assertEquals('B', trap_location_team[1].team_letter) self.assertEquals(3, trap_location_team[2].team_number) self.assertEquals('C', trap_location_team[2].team_letter) self.assertEquals(4, trap_location_team[3].team_number) self.assertEquals('D', trap_location_team[3].team_letter) def test_mammals(self): '''Only return trap locations which have caught an animal. In this case the first three as in above method test_trap_locations. Should exclude trap 4.''' animals_trapped = self.another_expedition.animal_locations() self.assertEquals(1, animals_trapped[0].team_number) self.assertEquals("blackrock_mouse", animals_trapped[0].animal.species.common_name) self.assertEquals('A', animals_trapped[0].team_letter) self.assertEquals(2, animals_trapped[1].team_number) self.assertEquals('B', animals_trapped[1].team_letter) self.assertEquals(3, animals_trapped[2].team_number) self.assertEquals('C', animals_trapped[2].team_letter) def test_expedition_unicode(self): self.assertEquals( unicode(self.another_expedition), "Expedition %d started on %s" % ( self.another_expedition.id, self.another_expedition.start_date_of_expedition.strftime( "%m/%d/%y"))) def test_expedition_absolute_url(self): self.assertEquals( self.another_expedition.get_absolute_url(), "/mammals/expedition/%i/" % self.another_expedition.id) def test_number_of_mammals(self): number_of_mammals = self.another_expedition.how_many_mammals_caught() self.assertEquals(number_of_mammals, 3) def test_team_points(self): '''Takes a team_letter and returns matching trap locations with letter''' team_a = self.another_expedition.team_points('A') self.assertEquals(team_a[0].team_letter, 'A') team_b = self.another_expedition.team_points('B') self.assertEquals(team_b[0].team_letter, 'B') team_c = self.another_expedition.team_points('C') self.assertEquals(team_c[0].team_letter, 'C') def test_end_minute_string(self): self.new_expedition = Expedition(field_notes="some field notes here") self.new_expedition.save() end_minute_string = self.new_expedition.end_minute_string() self.assertIsNotNone(end_minute_string) self.assertEquals( end_minute_string, "%02d" % self.new_expedition.end_date_of_expedition.minute) def test_end_hour_string(self): self.new_expedition = Expedition(field_notes="some field notes here") self.new_expedition.save() end_hour_string = self.new_expedition.end_hour_string() self.assertIsNotNone(end_hour_string) self.assertEquals( end_hour_string, "%02d" % self.new_expedition.end_date_of_expedition.hour) def test_expedition_set_time_from_strings(self): # not sure how to check actual contents of the time, # keeps giving type errors self.another_expedition.set_end_time_from_strings("5", "45") self.assertIsNotNone(self.another_expedition.end_date_of_expedition) # Now test TrapLocation methods def test_points_trap_location(self): self.trap_4.set_suggested_lat_long([4, 5]) self.trap_4.set_actual_lat_long([6, 7]) self.trap_4.save() actual_lat = self.trap_4.actual_lat() actual_lon = self.trap_4.actual_lon() self.assertEquals(actual_lat, 6) self.assertEquals(actual_lon, 7) suggested_lon = self.trap_4.suggested_lon() suggested_lat = self.trap_4.suggested_lat() self.assertEquals(suggested_lat, 4) self.assertEquals(suggested_lon, 5) def test_points_trap_location_when_none(self): self.assertIsNone(self.time_trap.suggested_lat()) self.assertIsNone(self.time_trap.suggested_lon()) self.assertIsNone(self.time_trap.actual_lat()) self.assertIsNone(self.time_trap.actual_lon()) def test_trap_location_unicode(self): self.assertEquals(unicode(self.trap_4), self.trap_4.gps_coords()) def test_trap_location_suggested_gps_coords(self): self.assertEquals( self.trap_4.suggested_gps_coords(), "%s, %s" % (self.trap_4.suggested_NSlat(), self.trap_4.suggested_EWlon())) def test_trap_location_actual_gps_coords(self): self.assertEquals( self.trap_4.actual_gps_coords(), "%s, %s" % (self.trap_4.actual_NSlat(), self.trap_4.actual_EWlon())) def test_trap_location_suggested_NSlat_EWlon_positive_values(self): self.trap_4.set_suggested_lat_long([4, 5]) self.trap_4.save() self.assertEquals( self.trap_4.suggested_NSlat(), '%0.5F N' % abs(self.trap_4.suggested_lat())) self.assertEquals( self.trap_4.suggested_EWlon(), '%0.5F E' % abs(self.trap_4.suggested_lon())) def test_trap_location_suggested_NSlat_EWlon_negative_values(self): self.trap_4.set_suggested_lat_long([-3, -4]) self.trap_4.save() self.assertEquals( self.trap_4.suggested_NSlat(), '%0.5F S' % abs(self.trap_4.suggested_lat())) self.assertEquals( self.trap_4.suggested_EWlon(), '%0.5F W' % abs(self.trap_4.suggested_lon())) def test_trap_location_suggested_NSlat_EWlon_None(self): self.assertIsNone(self.time_trap.suggested_lat()) self.assertIsNone(self.time_trap.suggested_lon()) def test_trap_location_actual_NSlat_EWlon_positve_values(self): self.trap_4.set_actual_lat_long([4, 5]) self.trap_4.save() self.assertEquals( self.trap_4.actual_NSlat(), '%0.5F N' % abs(self.trap_4.actual_lat())) self.assertEquals( self.trap_4.actual_EWlon(), '%0.5F E' % abs(self.trap_4.actual_lon())) def test_trap_location_actual_NSlat_EWlon_negative_values(self): self.trap_4.set_actual_lat_long([-3, -4]) self.trap_4.save() self.assertEquals( self.trap_4.actual_NSlat(), '%0.5F S' % abs(self.trap_4.actual_lat())) self.assertEquals( self.trap_4.actual_EWlon(), '%0.5F W' % abs(self.trap_4.actual_lon())) def test_trap_location_actual_NSlat_EWlon_None(self): self.assertIsNone(self.time_trap.actual_lat()) self.assertIsNone(self.time_trap.actual_lon()) def test_trap_location_school(self): self.school = School(name="school", address="school address", contact_1_name="contact 1 for school", contact_1_phone="000-000-0000", contact_1_email="*****@*****.**", contact_2_name="contact 2 for school", contact_2_phone="111-111-1111", contact_2_email="*****@*****.**", notes="this student has appropriate information") self.school.save() self.another_expedition.school = self.school self.assertIsNotNone(self.trap_4.school_if_any()) self.assertEquals(self.trap_4.school_if_any(), "school") self.assertIsNone(self.time_trap.school_if_any()) def test_sightings_date_for_solr(self): self.new_sighting = Sighting(species=self.species, date=datetime.now()) self.new_sighting.save() self.assertIsNotNone(self.new_sighting.date_for_solr()) def tearDown(self): self.sighting.delete() self.expedition.delete() self.trap_location.delete() self.timed_expedition.delete() self.time_trap.delete()
class TestMoreMammalModels(TestCase): def setUp(self): ''' trying to create sighting leaving out attibtutes whic are key or objects - location = objects = species = date = observers = observation_type = how_many_observed = notes =''' self.sighting = Sighting() self.sighting.save() self.expedition = Expedition() self.expedition.save() # objects = models.GeoManager() self.trap_location = TrapLocation( expedition=self.expedition, notes_about_location="Notes about the location", team_letter='C', whether_a_trap_was_set_here=True, bait_still_there=False, notes_about_outcome='This is a good place for a trap.', student_names='Student 1, Student 2, Student 3') self.trap_location.save() self.species = Species( latin_name="official_mouse_name", common_name="blackrock_mouse", about_this_species="too smart for traps", ) self.species.save() # left off sex of animal, age of animal, scale used - foreign keys? # other details which were booleans with default left off self.animal_1 = Animal(species=self.species, description="this is a special mouse", tag_number="6789", health="excellent", weight_in_grams=35) self.animal_1.save() # left off sex of animal, age of animal, scale used - foreign # keys? other details which were booleans with default left off self.animal_2 = Animal(species=self.species, description="this is a naughty mouse", tag_number="8355", health="excellent", weight_in_grams=45) self.animal_2.save() # left off sex of animal, age of animal, scale used - foreign keys? # other details which were booleans with default left off self.animal_3 = Animal(species=self.species, description="this is a super mouse", tag_number="8888", health="excellent", weight_in_grams=15) self.animal_3.save() self.another_expedition = Expedition( start_date_of_expedition=datetime.now(), end_date_of_expedition=datetime.now()) self.another_expedition.save() self.habitat = Habitat(label="habitat label", blurb="this is a habitat", image_path_for_legend="/path/here", color_for_map="111") self.habitat.save() self.trap_1 = TrapLocation(expedition=self.another_expedition, team_letter="A", team_number=1, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_1) self.trap_1.save() self.trap_2 = TrapLocation(expedition=self.another_expedition, team_letter="B", team_number=2, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_2) self.trap_2.save() self.trap_3 = TrapLocation(expedition=self.another_expedition, team_letter="C", team_number=3, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat, animal=self.animal_3) self.trap_3.save() self.trap_4 = TrapLocation(expedition=self.another_expedition, team_letter="D", team_number=4, whether_a_trap_was_set_here=True, bait_still_there=False, habitat=self.habitat) self.trap_4.save() self.another_expedition.save() self.timed_expedition = Expedition( end_date_of_expedition=datetime.now()) self.timed_expedition.save() self.time_trap = TrapLocation(expedition=self.timed_expedition, team_letter="team name here", team_number=6, habitat=self.habitat, whether_a_trap_was_set_here=True, bait_still_there=False, animal=self.animal_1) self.time_trap.save() self.new_sighting = Sighting(species=self.species, date=datetime.now()) self.new_sighting.save() self.grid_point_nw = GridPoint() self.grid_point_nw.save() self.grid_point_ne = GridPoint() self.grid_point_ne.save() self.grid_point_sw = GridPoint() self.grid_point_sw.save() self.grid_point_se = GridPoint() self.grid_point_se.save() self.grid_point_center = GridPoint() self.grid_point_center.save() self.grid_square = GridSquare(NW_corner=self.grid_point_nw, NE_corner=self.grid_point_ne, SW_corner=self.grid_point_sw, SE_corner=self.grid_point_se, center=self.grid_point_center, display_this_square=False, row=1, column=0, access_difficulty=3, terrain_difficulty=4) self.grid_square.save() def test_sighting_methods(self): self.new_sighting.set_lat_long([5.0, 8.0]) self.assertIsNotNone(self.new_sighting.location) self.assertEquals(self.new_sighting.lat(), 5.0) # make sure blank sightings returns None self.assertEquals(self.sighting.lat(), None) self.assertEquals(self.new_sighting.lon(), 8.0) self.assertEquals(self.sighting.lon(), None) self.assertIsNotNone(self.new_sighting.date_for_solr()) def test_species_has_attributes(self): species_attributes = self.species.dir() self.assertIn("latin_name", species_attributes) self.assertIn("common_name", species_attributes) self.assertIn("about_this_species", species_attributes) self.assertEquals(self.species.latin_name, "official_mouse_name") self.assertEquals(self.species.common_name, "blackrock_mouse") self.assertEquals(self.species.about_this_species, "too smart for traps") self.other_species = Species() self.other_species.latin_name = "official_name" self.other_species.common_name = "blackrock" self.other_species.about_this_species = "too smart for traps" self.assertEquals(self.other_species.latin_name, "official_name") self.assertEquals(self.other_species.common_name, "blackrock") self.assertEquals(self.other_species.about_this_species, "too smart for traps") def test_grid_point_assignments_dir_and_uni(self): self.grid_point_nw.set_lat_long([4, 5]) gp_dir = self.grid_point_nw.dir() self.grid_point_nw.save() self.assertIn("geo_point", gp_dir) self.assertIn("objects", gp_dir) self.assertEquals(self.grid_point_nw.lat(), 4.0) self.assertEquals(self.grid_point_nw.lon(), 5.0) self.assertEquals(self.grid_point_nw.NSlat(), '%0.5F N' % abs(self.grid_point_nw.lat())) self.assertEquals(self.grid_point_nw.EWlon(), '%0.5F E' % abs(self.grid_point_nw.lon())) self.assertEquals( self.grid_point_nw.gps_coords(), "%s, %s" % (self.grid_point_nw.NSlat(), self.grid_point_nw.EWlon())) self.assertEquals(unicode(self.grid_point_nw), self.grid_point_nw.gps_coords()) self.assertEquals(type(self.grid_point_nw.create([6, 7])), type(GridPoint())) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_se.save() self.assertEquals(self.grid_point_se.NSlat(), '%0.5F S' % abs(self.grid_point_se.lat())) self.assertEquals(self.grid_point_se.EWlon(), '%0.5F W' % abs(self.grid_point_se.lon())) self.assertEquals(self.grid_point_se.lat(), self.grid_point_se.geo_point.coords[0]) self.assertEquals(self.grid_point_se.lon(), self.grid_point_se.geo_point.coords[1]) def test_sighting_has_attributes(self): contains = dir(self.sighting) self.assertIn("set_lat_long", contains) self.assertIn("lat", contains) self.assertIn("lon", contains) self.assertIn("date_for_solr", contains) def test_expedition_has_attributes(self): contains = dir(self.expedition) self.assertIn("get_absolute_url", contains) self.assertIn("how_many_mammals_caught", contains) self.assertIn("team_points", contains) self.assertIn("set_end_time_if_none", contains) self.assertIn("end_minute_string", contains) self.assertIn("end_hour_string", contains) self.assertIn("set_end_time_from_strings", contains) self.assertIn("transects_json", contains) def test_expedition_dir(self): contains = self.expedition.dir() self.assertIn("get_absolute_url", contains) self.assertIn("how_many_mammals_caught", contains) self.assertIn("team_points", contains) self.assertIn("set_end_time_if_none", contains) self.assertIn("end_minute_string", contains) self.assertIn("end_hour_string", contains) self.assertIn("set_end_time_from_strings", contains) self.assertIn("transects_json", contains) def test_trap_location_has_attributes(self): contains = dir(self.trap_location) self.assertIn("create_from_obj", contains) self.assertIn("recreate_point_obj", contains) self.assertIn("date", contains) self.assertIn("date_for_solr", contains) self.assertIn("trap_nickname", contains) self.assertIn("transect_endpoints", contains) self.assertIn("set_transect_bearing_wrt_magnetic_north", contains) self.assertIn("transect_bearing_wrt_magnetic_north", contains) self.assertIn("set_suggested_lat_long", contains) self.assertIn("set_actual_lat_long", contains) def test_trap_location_date_none(self): the_date = self.trap_location.date() self.assertIsNotNone(the_date) the_date_solr = self.trap_location.date_for_solr() self.assertIsNotNone(the_date_solr) def test_trap_location_date_exists(self): date = self.time_trap.date() self.assertIsNotNone(date) date_solr = self.time_trap.date_for_solr() self.assertIsNotNone(date_solr) def test_trap_location_nickname(self): team_nickname = self.time_trap.trap_nickname() self.assertEquals( team_nickname, (self.time_trap.team_letter + str(self.time_trap.team_number))) def test_trap_location_species(self): species_does_not_exist = self.trap_location.species_if_any() self.assertIsNone(species_does_not_exist) has_species = self.time_trap.species_if_any() self.assertIsNotNone(has_species) self.assertEquals(has_species, "blackrock_mouse") def test_trap_location_habitat(self): no_habitat = self.trap_location.habitat_if_any() self.assertIsNone(no_habitat) has_habitat = self.time_trap.habitat_if_any() self.assertIsNotNone(has_habitat) self.assertEquals(has_habitat, "habitat label") def test_habitat_id(self): no_habitat_id = self.trap_location.habitat_id_if_any() self.assertIsNone(no_habitat_id) has_habitat_id = self.time_trap.habitat_id_if_any() self.assertIsNotNone(has_habitat_id) def test_trap_location_dir(self): dir_test = self.time_trap.dir() self.assertIn("habitat_if_any", dir_test) self.assertIn("habitat_id_if_any", dir_test) self.assertIn("species_if_any", dir_test) def test_create_observation_type(self): observation = ObservationType() self.failUnlessEqual(type(ObservationType()), type(observation)) def test_create_observation_self(self): self.observation = ObservationType() self.observation.save() self.failUnlessEqual(type(ObservationType()), type(self.observation)) def test_grid_square_uni_dir(self): self.assertEquals( unicode(self.grid_square), "Row %d, column %d" % (self.grid_square.row, self.grid_square.column)) dir_test = self.grid_square.dir() self.assertIn("row", dir_test) self.assertIn("column", dir_test) self.assertIn("access_difficulty", dir_test) self.assertIn("corner_names", dir_test) self.assertIn("corners", dir_test) self.assertIn("corner_obj", dir_test) self.assertIn("corner_obj_json", dir_test) self.assertIn("info_for_display", dir_test) self.assertIn("block_json", dir_test) def test_grid_square_corner_names_method(self): corner_names = self.grid_square.corner_names() self.assertEquals( ['SW_corner', 'NW_corner', 'NE_corner', 'SE_corner', 'center'], corner_names) '''There may be a typo in the actual program says for corner_name may be supposed to be corner_names''' # def test_grid_square_corners(self): # #corner_names = self.grid_square.corner_names() # corners = self.grid_square.corners() # self.assertIn( "SW_corner", corners) # self.assertIn( type(GridPoint()), corners) def test_corner_obj(self): self.grid_point_nw.set_lat_long([4, 5]) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_sw.set_lat_long([-8, -9]) self.grid_point_ne.set_lat_long([-8, -9]) self.grid_point_center.set_lat_long([-8, -9]) corner_objects = self.grid_square.corner_obj() self.assertEquals([[-8.0, -9.0], [4.0, 5.0], [-8.0, -9.0], [-8.0, -9.0], [-8.0, -9.0]], corner_objects) def test_corner_obj_json(self): self.grid_point_nw.set_lat_long([4, 5]) self.grid_point_se.set_lat_long([-8, -9]) self.grid_point_sw.set_lat_long([-8, -9]) self.grid_point_ne.set_lat_long([-8, -9]) self.grid_point_center.set_lat_long([-8, -9]) corner_obj_json = self.grid_square.corner_obj_json() self.assertIn("[4.0, 5.0]", corner_obj_json) self.assertEquals(('[[-8.0, -9.0], [4.0, 5.0], [-8.0, -9.0], ' '[-8.0, -9.0], [-8.0, -9.0]]'), corner_obj_json) def test_battleship_coords(self): battleship_coordinates = self.grid_square.battleship_coords() self.assertIsNotNone(battleship_coordinates) # Test More Expedition Methods def test_trap_locations(self): '''Test methods requiring TrapLocations, Animals, and Teams''' '''This is not a good test - the unicode returns the gps coordinates so it is returning TrapLocation objects but need to verify that they have team letter and number''' ae = self.another_expedition trap_location_team = ae.trap_locations_ordered_by_team() self.assertEquals(1, trap_location_team[0].team_number) self.assertEquals('A', trap_location_team[0].team_letter) self.assertEquals(2, trap_location_team[1].team_number) self.assertEquals('B', trap_location_team[1].team_letter) self.assertEquals(3, trap_location_team[2].team_number) self.assertEquals('C', trap_location_team[2].team_letter) self.assertEquals(4, trap_location_team[3].team_number) self.assertEquals('D', trap_location_team[3].team_letter) def test_mammals(self): '''Only return trap locations which have caught an animal. In this case the first three as in above method test_trap_locations. Should exclude trap 4.''' animals_trapped = self.another_expedition.animal_locations() self.assertEquals(1, animals_trapped[0].team_number) self.assertEquals("blackrock_mouse", animals_trapped[0].animal.species.common_name) self.assertEquals('A', animals_trapped[0].team_letter) self.assertEquals(2, animals_trapped[1].team_number) self.assertEquals('B', animals_trapped[1].team_letter) self.assertEquals(3, animals_trapped[2].team_number) self.assertEquals('C', animals_trapped[2].team_letter) def test_expedition_unicode(self): self.assertEquals( unicode(self.another_expedition), "Expedition %d started on %s" % (self.another_expedition.id, self.another_expedition.start_date_of_expedition.strftime( "%m/%d/%y"))) def test_expedition_absolute_url(self): self.assertEquals( self.another_expedition.get_absolute_url(), "/mammals/expedition/%i/" % self.another_expedition.id) def test_number_of_mammals(self): number_of_mammals = self.another_expedition.how_many_mammals_caught() self.assertEquals(number_of_mammals, 3) def test_team_points(self): '''Takes a team_letter and returns matching trap locations with letter''' team_a = self.another_expedition.team_points('A') self.assertEquals(team_a[0].team_letter, 'A') team_b = self.another_expedition.team_points('B') self.assertEquals(team_b[0].team_letter, 'B') team_c = self.another_expedition.team_points('C') self.assertEquals(team_c[0].team_letter, 'C') def test_end_minute_string(self): self.new_expedition = Expedition(field_notes="some field notes here") self.new_expedition.save() end_minute_string = self.new_expedition.end_minute_string() self.assertIsNotNone(end_minute_string) self.assertEquals( end_minute_string, "%02d" % self.new_expedition.end_date_of_expedition.minute) def test_end_hour_string(self): self.new_expedition = Expedition(field_notes="some field notes here") self.new_expedition.save() end_hour_string = self.new_expedition.end_hour_string() self.assertIsNotNone(end_hour_string) self.assertEquals( end_hour_string, "%02d" % self.new_expedition.end_date_of_expedition.hour) def test_expedition_set_time_from_strings(self): # not sure how to check actual contents of the time, # keeps giving type errors self.another_expedition.set_end_time_from_strings("5", "45") self.assertIsNotNone(self.another_expedition.end_date_of_expedition) # Now test TrapLocation methods def test_points_trap_location(self): self.trap_4.set_suggested_lat_long([4, 5]) self.trap_4.set_actual_lat_long([6, 7]) self.trap_4.save() actual_lat = self.trap_4.actual_lat() actual_lon = self.trap_4.actual_lon() self.assertEquals(actual_lat, 6) self.assertEquals(actual_lon, 7) suggested_lon = self.trap_4.suggested_lon() suggested_lat = self.trap_4.suggested_lat() self.assertEquals(suggested_lat, 4) self.assertEquals(suggested_lon, 5) def test_points_trap_location_when_none(self): self.assertIsNone(self.time_trap.suggested_lat()) self.assertIsNone(self.time_trap.suggested_lon()) self.assertIsNone(self.time_trap.actual_lat()) self.assertIsNone(self.time_trap.actual_lon()) def test_trap_location_unicode(self): self.assertEquals(unicode(self.trap_4), self.trap_4.gps_coords()) def test_trap_location_suggested_gps_coords(self): self.assertEquals( self.trap_4.suggested_gps_coords(), "%s, %s" % (self.trap_4.suggested_NSlat(), self.trap_4.suggested_EWlon())) def test_trap_location_actual_gps_coords(self): self.assertEquals( self.trap_4.actual_gps_coords(), "%s, %s" % (self.trap_4.actual_NSlat(), self.trap_4.actual_EWlon())) def test_trap_location_suggested_NSlat_EWlon_positive_values(self): self.trap_4.set_suggested_lat_long([4, 5]) self.trap_4.save() self.assertEquals(self.trap_4.suggested_NSlat(), '%0.5F N' % abs(self.trap_4.suggested_lat())) self.assertEquals(self.trap_4.suggested_EWlon(), '%0.5F E' % abs(self.trap_4.suggested_lon())) def test_trap_location_suggested_NSlat_EWlon_negative_values(self): self.trap_4.set_suggested_lat_long([-3, -4]) self.trap_4.save() self.assertEquals(self.trap_4.suggested_NSlat(), '%0.5F S' % abs(self.trap_4.suggested_lat())) self.assertEquals(self.trap_4.suggested_EWlon(), '%0.5F W' % abs(self.trap_4.suggested_lon())) def test_trap_location_suggested_NSlat_EWlon_None(self): self.assertIsNone(self.time_trap.suggested_lat()) self.assertIsNone(self.time_trap.suggested_lon()) def test_trap_location_actual_NSlat_EWlon_positve_values(self): self.trap_4.set_actual_lat_long([4, 5]) self.trap_4.save() self.assertEquals(self.trap_4.actual_NSlat(), '%0.5F N' % abs(self.trap_4.actual_lat())) self.assertEquals(self.trap_4.actual_EWlon(), '%0.5F E' % abs(self.trap_4.actual_lon())) def test_trap_location_actual_NSlat_EWlon_negative_values(self): self.trap_4.set_actual_lat_long([-3, -4]) self.trap_4.save() self.assertEquals(self.trap_4.actual_NSlat(), '%0.5F S' % abs(self.trap_4.actual_lat())) self.assertEquals(self.trap_4.actual_EWlon(), '%0.5F W' % abs(self.trap_4.actual_lon())) def test_trap_location_actual_NSlat_EWlon_None(self): self.assertIsNone(self.time_trap.actual_lat()) self.assertIsNone(self.time_trap.actual_lon()) def test_trap_location_school(self): self.school = School(name="school", address="school address", contact_1_name="contact 1 for school", contact_1_phone="000-000-0000", contact_1_email="*****@*****.**", contact_2_name="contact 2 for school", contact_2_phone="111-111-1111", contact_2_email="*****@*****.**", notes="this student has appropriate information") self.school.save() self.another_expedition.school = self.school self.assertIsNotNone(self.trap_4.school_if_any()) self.assertEquals(self.trap_4.school_if_any(), "school") self.assertIsNone(self.time_trap.school_if_any()) def test_sightings_date_for_solr(self): self.new_sighting = Sighting(species=self.species, date=datetime.now()) self.new_sighting.save() self.assertIsNotNone(self.new_sighting.date_for_solr()) def tearDown(self): self.sighting.delete() self.expedition.delete() self.trap_location.delete() self.timed_expedition.delete() self.time_trap.delete()