Esempio n. 1
0
    def test_populate_stories_with_themes(self):
        #' initialize a list of story OrderedDict objects
        story_ids = [
            "movie: A Trip to the Moon (1902)",
            "movie: The Wizard of Oz (1939)", "movie: Robot Monster (1953)"
        ]
        story_titles = [
            "A Trip to the Moon (1902)", "The Wizard of Oz (1939)",
            "Robot Monster (1953)"
        ]
        story_dates = ["1902-10-04", "1939-08-25", "1953-06-24"]
        story_description = "A classic film."
        source_path = json.dumps({'source': './a/token/path'})
        story_od_1 = OrderedDict()
        story_od_1['story-id'] = story_ids[0]
        story_od_1['title'] = story_titles[0]
        story_od_1['date'] = story_dates[0]
        story_od_2 = OrderedDict()
        story_od_2['story-id'] = story_ids[1]
        story_od_2['title'] = story_titles[1]
        story_od_2['date'] = story_dates[1]
        story_od_3 = OrderedDict()
        story_od_3['story-id'] = story_ids[2]
        story_od_3['title'] = story_titles[2]
        story_od_3['date'] = story_dates[2]
        story_od_1['description'] = story_od_2['description'] = story_od_3[
            'description'] = story_description
        story_od_1['source'] = story_od_2['source'] = story_od_3[
            'source'] = source_path
        story_od_1['themes'] = story_od_2['themes'] = story_od_3['themes'] = []
        stories_list = [story_od_1, story_od_2, story_od_3]

        #' initialize a list of StoryTheme objects
        storythemeobj_1 = webobject.StoryTheme(
            name1='movie: Robot Monster (1953)',
            name2='the desire for vengeance',
            weight='major',
            motivation=
            'So-and-so sought to make so-and-so pay for this or that.')
        storythemeobj_2 = webobject.StoryTheme(
            name1='movie: The Wizard of Oz (1939)',
            name2='romantic love',
            weight='minor',
            motivation='So-and-so was besotted with so-and-so.')
        storythemeobjs_list = [storythemeobj_1, storythemeobj_2]

        #' test thematically annotate Robot Monster (1953) with "the desire for vengeance"
        updated_stories_list = webtask.cache_data.populate_stories_with_themes(
            stories_list, storythemeobjs_list)
        self.assertEqual(updated_stories_list[2]['themes'][0]['name'],
                         storythemeobj_1.name2)
        self.assertEqual(updated_stories_list[2]['themes'][0]['level'],
                         storythemeobj_1.weight)
        self.assertEqual(updated_stories_list[2]['themes'][0]['motivation'],
                         storythemeobj_1.motivation)
Esempio n. 2
0
 def test_init_thematic_annotation_od(self):
     #' test to confirm that a StoryTheme object is correctly converted into an orderdict entry
     storythemeobj = webobject.StoryTheme(
         name1='story id',
         name2='the desire for vengeance',
         weight='major',
         motivation='So-and-so sought to make so-and-so pay for this or that.')
     storytheme_od = webtask.cache_stories.init_thematic_annotation_od(storythemeobj)
     self.assertEqual(storytheme_od.items()[0], ('name', storythemeobj.name2))
     self.assertEqual(storytheme_od.items()[1], ('level', storythemeobj.weight))
     self.assertEqual(storytheme_od.items()[2], ('motivation', storythemeobj.motivation))
Esempio n. 3
0
    def test_populate_collections_with_themes(self):
        #' initialize a list of two collection OrderedDict objects
        collection_ids = ['Collection: Akira Kurosawa', 'Collection: X-men']
        collection_titles = ['Akira Kurosawa', 'X-men']
        collection_dates = ['1949-1985', '2000-2019']
        collection_descriptions = [
            'Films written or directed by Akira Kurosawa.',
            'The X-Men is an American superhero film series.'
        ]
        source_path = json.dumps({'source': './a/token/path'})
        collection_od_1 = OrderedDict()
        collection_od_1['collection-id'] = collection_ids[0]
        collection_od_1['title'] = collection_titles[0]
        collection_od_1['date'] = collection_dates[0]
        collection_od_1['description'] = collection_descriptions[0]
        collection_od_1['themes'] = []
        collection_od_2 = OrderedDict()
        collection_od_2['collection-id'] = collection_ids[1]
        collection_od_2['title'] = collection_titles[1]
        collection_od_2['date'] = collection_dates[1]
        collection_od_2['description'] = collection_descriptions[1]
        collection_od_2['themes'] = []
        collection_od_1['source'] = collection_od_2['source'] = source_path
        collections_list = [collection_od_1, collection_od_2]

        #' initialize a list of StoryTheme objects
        storythemeobj = webobject.StoryTheme(
            name1='Collection: X-men',
            name2='speculative ability',
            weight='major',
            motivation='Each X-man has a signature superpower.')
        storythemeobjs_list = [storythemeobj]

        #' test the X-men collection is thematically annotated with "speculative ability"
        expected_themes = ['speculative ability']
        updated_collections_list = webtask.cache_collections.populate_collections_with_themes(
            collections_list, storythemeobjs_list)
        #self.assertEqual(updated_collections_list[1]['themes'][0]['name'], storythemeobj.name2)
        self.assertEqual(updated_collections_list[1]['themes'][0]['name'],
                         storythemeobj.name2)
        self.assertEqual(updated_collections_list[1]['themes'][0]['level'],
                         storythemeobj.weight)
        self.assertEqual(
            updated_collections_list[1]['themes'][0]['motivation'],
            storythemeobj.motivation)