def test_create_new_mapstory(self): user = User.objects.create_user(username='******', email='*****@*****.**', password='******') mapstory = MapStory() self.assertIsInstance(mapstory, MapStory) mapstory.title = "Test story" mapstory.owner = user mapstory.save()
def handle(self, *args, **options): # private function to launder story name in case it contains special characters def launder(string): return re.sub('[^0-9a-zA-Z]+', '_', string.lower()) old_stories = Map.objects.filter(story__isnull=True) stories_updated = 0 if old_stories.exists(): for old_story in old_stories.iterator(): # create the new story model object, populating it with data from old map in some cases. new_story = MapStory(owner=old_story.owner, title=old_story.title, abstract=old_story.abstract) new_story_print = launder(new_story.title) if options['dry-run'] is False: new_story.save() new_story.set_default_permissions() else: self.stdout.write( 'New Mapstory Object: {0}'.format(new_story_print)) self.stdout.write('Title: {0}'.format(new_story_print)) # create the foreign key link to the new story and set it to the first chapter old_story.story = new_story old_story.chapter_index = 0 if options['dry-run'] is False: old_story.save() stories_updated += 1 if options['dry-run'] is False: self.stdout.write( 'Converted old mapstory: {0}'.format(new_story_print)) else: self.stdout.write( 'Converted old mapstory: {0}, but did not save'.format(new_story_print)) self.stdout.write( '{0} stories converted to new model'.format(stories_updated)) else: self.stdout.write('No Chapters found without a Mapstory')
class TestMapstory(TestCase): """ Mapstory Model Tests """ def setUp(self): self.mapstory = MapStory() self.assertIsInstance(self.mapstory, MapStory, "Should be instance of MapStory") self.mapstory.title = "Test story" self.mapstory.owner = testUser def test_save_and_retrieve(self): """ Should save in database """ self.client.login(username=testUser.username, password="******") self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) saved_mapstory = MapStory.objects.all()[0] self.assertEqual(saved_mapstory.title, "Test story", "Should have the same title") self.assertEqual(saved_mapstory.owner, self.mapstory.owner, "Should have the same owner") def test_remove(self): self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) MapStory.objects.filter(id=self.mapstory.id).delete() self.assertEqual(0, MapStory.objects.all().count()) @skip def test_get_abosolute_url(self): self.assertIsNotNone(self.mapstory.get_absolute_url()) @skip def test_update_from_viewer(self): conf = {} conf.title = "Test" conf.abstract = "Test abstract" conf.is_published = True self.mapstory.update_from_viewer(conf) def test_create_new_mapstory(self): user = User.objects.create_user(username='******', email='*****@*****.**', password='******') mapstory = MapStory() self.assertIsInstance(mapstory, MapStory) mapstory.title = "Test story" mapstory.owner = user mapstory.save() def test_create_new_map(self): test_map = Map() self.assertIsInstance(test_map, Map)
def add_mapstory(self): mapstory = MapStory() mapstory.name = "test_case1" mapstory.owner = self.admin_user mapstory.uuid = str(uuid.uuid1()) mapstory.save() map = Map() map.story = mapstory map.chapter_index = 0 map.title = "test_case" map.projection = 'EPSG:4326' map.owner = mapstory.owner map.uuid = str(uuid.uuid1()) map.zoom = 4 map.center_x = 0 map.center_y = 0 map.set_bounds_from_center_and_zoom(map.center_x, map.center_y, map.zoom) map.save() mapstory.chapter_list.add(map) mapstory.save() # background maplayer_background = MapLayer() maplayer_background.map = map maplayer_background.name = "control-room" maplayer_background.stack_order = 4 maplayer_background.opacity = 1.0 maplayer_background.fixed = False maplayer_background.visibility = True maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}' maplayer_background.layer_config = "" maplayer_background.group = "background" maplayer_background.save() # map.layers.add(maplayer) map.save() return mapstory
def add_mapstory(self): mapstory = MapStory() mapstory.name = "test_case1" mapstory.owner = self.admin_user mapstory.uuid = str(uuid.uuid1()) mapstory.save() map = Map() map.story = mapstory map.chapter_index = 0 map.title = "test_case" map.projection = 'EPSG:4326' map.owner = mapstory.owner map.uuid = str(uuid.uuid1()) map.zoom = 4 map.center_x = 0 map.center_y = 0 map.set_bounds_from_center_and_zoom( map.center_x, map.center_y, map.zoom) map.save() mapstory.chapter_list.add(map) mapstory.save() # background maplayer_background = MapLayer() maplayer_background.map = map maplayer_background.name = "control-room" maplayer_background.stack_order = 4 maplayer_background.opacity = 1.0 maplayer_background.fixed = False maplayer_background.visibility = True maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}' maplayer_background.layer_config = "" maplayer_background.group = "background" maplayer_background.save() # map.layers.add(maplayer) map.save() return mapstory
class TestMapstory(TestCase): """ Mapstory Model Tests """ def setUp(self): self.mapstory = MapStory() self.assertIsInstance(self.mapstory, MapStory, "Should be instance of MapStory") self.mapstory.title = "Test story" self.mapstory.owner = testUser def test_save_and_retrieve(self): """ Should save in database """ self.client.login(username=testUser.username, password="******") self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) saved_mapstory = MapStory.objects.all()[0] self.assertEqual(saved_mapstory.title, "Test story", "Should have the same title") self.assertEqual(saved_mapstory.owner, self.mapstory.owner, "Should have the same owner") def test_remove(self): self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) MapStory.objects.filter(id=self.mapstory.id).delete() self.assertEqual(0, MapStory.objects.all().count()) @skip("TODO: Fix") def test_get_abosolute_url(self): self.assertIsNotNone(self.mapstory.get_absolute_url()) @skip("TODO: Fix this test") def test_update_from_viewer(self): conf = {} conf.title = "Test" conf.abstract = "Test abstract" conf.is_published = True self.mapstory.update_from_viewer(conf)
def handle(self, *args, **options): # private function to launder story name in case it contains special characters def launder(string): return re.sub('[^0-9a-zA-Z]+', '_', string.lower()) old_stories = Map.objects.filter(story__isnull=True) stories_updated = 0 if old_stories.exists(): for old_story in old_stories.iterator(): # create the new story model object, populating it with data from old map in some cases. new_story = MapStory(owner=old_story.owner, title=old_story.title, abstract=old_story.abstract) new_story_print = launder(new_story.title) if options['dry-run'] is False: new_story.save() new_story.set_default_permissions() else: self.stdout.write( 'New Mapstory Object: {0}'.format(new_story_print)) self.stdout.write('Title: {0}'.format(new_story_print)) # create the foreign key link to the new story and set it to the first chapter old_story.story = new_story old_story.chapter_index = 0 if options['dry-run'] is False: old_story.save() stories_updated += 1 if options['dry-run'] is False: self.stdout.write( 'Converted old mapstory: {0}'.format(new_story_print)) else: self.stdout.write( 'Converted old mapstory: {0}, but did not save'.format( new_story_print)) self.stdout.write( '{0} stories converted to new model'.format(stories_updated)) else: self.stdout.write('No Chapters found without a Mapstory')
class TestMapstory(TestCase): """ Mapstory Model Tests """ def setUp(self): self.mapstory = MapStory() self.assertIsInstance(self.mapstory, MapStory, "Should be instance of MapStory") self.mapstory.title = "Test story" self.mapstory.owner = testUser def test_save_and_retrieve(self): """ Should save in database """ self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) saved_mapstory = MapStory.objects.all()[0] self.assertEqual(saved_mapstory.title, "Test story", "Should have the same title") self.assertEqual(saved_mapstory.owner, self.mapstory.owner, "Should have the same owner") def test_remove(self): self.assertEqual(0, MapStory.objects.all().count()) self.mapstory.save() self.assertEqual(1, MapStory.objects.all().count()) MapStory.objects.filter(id=self.mapstory.id).delete() self.assertEqual(0, MapStory.objects.all().count()) @skip("TODO: Fix") def test_get_abosolute_url(self): self.assertIsNotNone(self.mapstory.get_absolute_url()) @skip("TODO: Fix this test") def test_update_from_viewer(self): conf = {} conf.title = "Test" conf.abstract = "Test abstract" conf.is_published = True self.mapstory.update_from_viewer(conf)
def setUp(self): self.mapstory = MapStory() self.assertIsInstance(self.mapstory, MapStory, "Should be instance of MapStory") self.mapstory.title = "Test story" self.mapstory.owner = testUser