Esempio n. 1
0
    def test_other_keywords(self):
        os.mkdir(os.path.join(self.dir_name, 'zub'))
        with open(os.path.join(self.dir_name, 'zub/data.csv'), 'wt') as output:
            output.write(
                'Title,Keywords,Colour keywords,URL\n'
                'Harlequin,cat,black white,http://www.flickr.com/photos/jeremy_dennis/4217338130/\n'
                'Teasel,cat,black,http://www.flickr.com/photos/jeremy_dennis/3713607489/')

        lib = LibrarySet(self.dir_name)['zub']
        link = lib.all_links[0]
        self.assertEqual(set(['black', 'white']), link.facet_keywords['colour'])
        self.assertEqual(set(['cat']), link.facet_keywords['main'])
        link = lib.all_links[1]
        self.assertEqual(set(['black']), link.facet_keywords['colour'])
        self.assertEqual(set(['cat']), link.facet_keywords['main'])

        self.assertEqual(1, len(lib.filtered_links({'colour': set(['white'])})))
        self.assertEqual(2, len(lib.filtered_links({'colour': set(['black'])})))

        self.assertEqual('cat+colour:black+colour:white', lib.urlencode_keywords(
            {'colour': ['black', 'white'], 'main': ['cat']}))
        self.assertEqual(
            {'colour': set(['black', 'white']), 'main': set(['cat'])},
            lib.urldecode_keywords('cat+colour:black+colour:white'),
        )
Esempio n. 2
0
    def test_tagging(self):
        os.mkdir(os.path.join(self.dir_name, 'quux'))
        with open(os.path.join(self.dir_name, 'quux/data.csv'), 'wt') as output:
            output.write(
                'Title,Description,Keywords,URL\n'
                'Crumbs,Crummy,cake,http://example.org/\n'
                'Slime,Slimy,goo,http://example.com/\n'
                'Slimy crumbs,Slimy and crumby,cake goo,http://example.net/')

        lib = LibrarySet(self.dir_name)['quux']
        self.assertEqual(set(['cake', 'goo']), lib.main_keywords)
        self.assertEqual(3, len(lib.all_links))

        cake_links = lib.filtered_links(['cake'])
        self.assertEqual(2, len(cake_links))
        self.assertEqual('Crumbs', list(cake_links)[0].title)
        self.assertEqual('Slimy crumbs', list(cake_links)[1].title)

        # Equivalewnt to invoking with the special facet named ‘main’
        cake_links = lib.filtered_links({'main': ['cake']})
        self.assertEqual(2, len(cake_links))
        self.assertEqual('Crumbs', list(cake_links)[0].title)
        self.assertEqual('Slimy crumbs', list(cake_links)[1].title)

        goo_links = lib.filtered_links(['goo'])
        self.assertEqual(2, len(goo_links))
        self.assertEqual('Slime', list(goo_links)[0].title)
        self.assertEqual('Slimy crumbs', list(goo_links)[1].title)

        cake_goo_links = lib.filtered_links(['cake', 'goo'])
        self.assertEqual(1, len(cake_goo_links))
        self.assertEqual('Slimy crumbs', list(cake_goo_links)[0].title)

        self.assertEqual('', lib.urlencode_keywords([]))
        self.assertEqual('cake', lib.urlencode_keywords({'main': ['cake']}))
        self.assertEqual('cake+goo', lib.urlencode_keywords({'main': ['goo', 'cake']}))

        self.assertEqual(set(['cake']), lib.urldecode_keywords('cake')['main'])
        self.assertEqual(set(['cake', 'goo']), lib.urldecode_keywords('cake+goo')['main'])
        self.assertEqual({'main': set()}, lib.urldecode_keywords(''))