def tearDown(self): import string [ l.delete() for l in LocationType.objects(name__in=list(string.letters + string.digits)) ] [ l.delete() for l in LocationType.objects(name__in=['ALPHONSE', 'PETER']) ]
class MappLocationModel(unittest.TestCase): def setUp(self): from maps.fixtures.management.commands.create_fixtures import load_data load_data() self.create_locationtype() def tearDown(self): self.location_type.delete() def create_locationtype(self): self.location_type = LocationType(name="test_loctype", view_privacy="everyone") self.location_type.save() self.assertEqual(self.location_type, LocationType.objects.get(name='test_loctype')) def test_creating_location(self): try: loc = Location.objects.get(name='test') loc.delete() except: pass location = Location(name="test", address1="6600 Kalanianaole Hwy",zip="96825",city="Honolulu", state="HI",phone="039485493",location_type=self.location_type) location.save() self.assertEqual(location, Location.objects.get(name='test')) location.delete() def test_location_get_tags(self): for l in Location.objects.filter(name="loc-with-cat2"): l.delete() loc = Location(name="loc-with-cat2") loc.save() cat = Categories(name="food-test2", tagged=[loc]) cat.save() self.assertIn(cat, loc.tags) self.assertEqual(1, len(loc.tags)) loc.delete() cat.delete() pass
def test_mkeobj_a_list_of_mongo_document_objects(self): reader = DictReader(self.file) mkeobj = self.mkeobj(data=reader, mapping=self.mapping, model=LocationType) lt = LocationType(name='1', desc='2', taxonomies='3') self.assertEqual(mkeobj[0].name, lt.name)
def test_add_location_with_type(self): lt = LocationType(name="tksome_new_location", icon="star.png") lt.save() lt_id = str(lt.id) responses.add(responses.GET, self.url_re, body=GEOCODE_BODY, status=200, content_type='application/json') factory = APIRequestFactory() request = factory.post('/api/v1/location/', { 'address1': 'test', 'city': 'Palo Alto', 'state': 'CA', 'location_type': lt_id, 'zip': '94043' }, format='json') resp = AddLocation.as_view()(request) lt.delete() self.assertEquals(resp.status_code, status.HTTP_201_CREATED) # make sure the data was stored id = resp.data['id'] new_loc = Location.objects.get(id=id) self.assertEquals(new_loc.points, { 'coordinates': [-122.0854212, 37.4229181], 'type': 'Point' }) self.assertTrue(new_loc.location_type)
def test_get_point_location_with_serializer(self): lt = LocationType(name="btest_loc_type2", icon="star.png") lt.save() l = Location(name="test", points=[1, 2], location_type=lt) l.save() self.assertEquals(l.points, [1, 2]) serializer = LocationSerializer(l) lt.delete() l.delete() self.assertEquals(serializer.data["points"], [1, 2]) self.assertEquals(serializer.data["location_type"]['name'], 'btest_loc_type2') self.assertEquals(serializer.data["location_type"]['icon'], 'star.png')
def test_mkeobj_handels_date_field(self): file = u"""a,b,c,d 1,2,Jan 15 2015,True""" test_file = StringIO(file) test_mapping = { 'a': 'name', 'b': 'desc', 'c': 'created', 'd': 'allow_galleries' } reader = DictReader(test_file) mkeobj = self.mkeobj(data=reader, mapping=test_mapping, model=LocationType) lt = LocationType(name='1', desc='2', created=datetime.datetime(2015, 1, 15, 0, 0), allow_galleries=True) self.assertEqual(mkeobj[0].created, lt.created)
def test_mkeobj_handels_boolean_field(self): file = u"""a,b,c,d 1,2,False,True""" test_file = StringIO(file) test_mapping = { 'a': 'name', 'b': 'desc', 'c': 'allow_media', 'd': 'allow_galleries' } reader = DictReader(test_file) mkeobj = self.mkeobj(data=reader, mapping=test_mapping, model=LocationType) lt = LocationType(name='1', desc='2', allow_media=False, allow_galleries=True) self.assertEqual(mkeobj[0].allow_media, lt.allow_media) self.assertEqual(mkeobj[0].allow_galleries, lt.allow_galleries)
def test_mkeobj_handles_ref_fields(self): file = u"""name,loctype,c test_location,new_loc_type,3""" loc_file = StringIO(file) loc_mapping = {'name': 'name', 'loctype': 'location_type'} #make a location type try: test_loc_type = LocationType.objects.get(name="new_loc_type") except LocationType.DoesNotExist: test_loc_type = LocationType(name="new_loc_type") test_loc_type.save() try: #upload the bugger reader = DictReader(loc_file) mkeobj = self.mkeobj(data=reader, mapping=loc_mapping, model=Location) self.assertEqual(mkeobj[0].location_type.name, test_loc_type.name) finally: #cleanup test_loc_type.delete()
def create_locationtype(self): self.location_type = LocationType(name="test_loctype", view_privacy="everyone") self.location_type.save() self.assertEqual(self.location_type, LocationType.objects.get(name='test_loctype'))