def test_LocationSiteFormUpdateView_post_data(self): location_context_path = staticfiles_storage.path( 'data/location_context_document.json') location_context_file = open(location_context_path) location_context_document = json.load(location_context_file) post_data = self.post_data post_data['refined_geomorphological_zone'] = '' loc_type = LocationTypeF(name='PointObservation', allowed_geometry='POINT') user = UserF.create(id=1) self.client.login( username=user.username, password='******', ) location_site = LocationSiteF.create( location_type=loc_type, creator=user, location_context_document=location_context_document) post_data['id'] = location_site.id self.client.post('/location-site-form/update/?id={}'.format( location_site.id), post_data, follow=True) updated_location_site = LocationSite.objects.get(id=location_site.id) updated_location_context = LocationContext.objects.filter( site=location_site) self.assertEqual(updated_location_site.river.name, 'NXAMAGELE') self.assertTrue( updated_location_context.filter( group__key__icontains='catchment_area').exists()) self.assertTrue( updated_location_context.filter( group__key='geo_class_recoded').exists()) self.assertTrue( updated_location_context.value_from_key('geo_class_recoded') == 'Mountain headwater stream') # Test if there are no location context data location_site_2 = LocationSiteF.create( location_type=loc_type, creator=user, ) post_data['id'] = location_site_2.id post_request_2 = self.client.post( '/location-site-form/update/?id={}'.format(location_site_2.id), post_data, follow=True) updated_location_context_2 = LocationContext.objects.filter( site=location_site_2) self.assertTrue( updated_location_context_2.filter( group__key__icontains='catchment_area').exists()) self.assertTrue( updated_location_context_2.value_from_key('geo_class_recoded') == 'Mountain headwater stream') self.assertTrue( post_request_2.redirect_chain[0][0], '/location-site-form/update/?id={}'.format(location_site_2.id))
def test_LocationSiteFormView_delete(self): loc_type = LocationTypeF(name='PointObservation', allowed_geometry='POINT') user = UserF.create(id=1) location_site_2 = LocationSiteF.create( location_type=loc_type, creator=user, ) self.client.login( username=user.username, password='******', ) post_data = {} post_request_2 = self.client.post( '/location-site-form/delete/{}/'.format(location_site_2.id), post_data, follow=True) self.assertFalse( LocationSite.objects.filter(id=location_site_2.id).exists()) self.assertEqual(post_request_2.redirect_chain[0][0], reverse('location-site-form')) location_site_3 = LocationSiteF.create(location_type=loc_type, ) self.client.post('/location-site-form/delete/{}/'.format( location_site_3.id), post_data, follow=True) self.assertTrue( LocationSite.objects.filter(id=location_site_3.id).exists())
def test_LocationSite_read(self): """ Tests location site model read """ location_type = LocationTypeF.create(name=u'custom type', ) model = LocationSiteF.create(location_type=location_type) self.assertTrue(model.location_type.name == 'custom type')
def test_LocationType_delete(self): """ Tests location type model delete """ model = LocationTypeF.create() model.delete() # check if deleted self.assertTrue(model.pk is None)
def test_LocationType_read(self): """ Tests location type model read """ model = LocationTypeF.create( name=u'custom location', description=u'custom description', ) self.assertTrue(model.name == 'custom location') self.assertTrue(model.description == 'custom description')
def test_LocationType_update(self): """ Tests location type model update """ model = LocationTypeF.create() new_data = {'name': u'new name', 'description': u'new description'} model.__dict__.update(new_data) model.save() # check if updated for key, val in new_data.items(): self.assertEqual(model.__dict__.get(key), val)
def test_LocationType_create(self): """ Tests location type creation """ model = LocationTypeF.create() # check if pk exists self.assertTrue(model.pk is not None) # check if name exists self.assertTrue(model.name is not None) # check if description exists self.assertTrue(model.description is not None)
def test_LocationSite_update(self): """ Tests location site model update """ location_type = LocationTypeF.create(name=u'custom type', ) model = LocationSiteF.create() new_data = { 'location_type': location_type, } model.__dict__.update(new_data) model.save() # check if updated for key, val in new_data.items(): self.assertEqual(model.__dict__.get(key), val)