示例#1
0
class TestPlugin(unittest.TestCase):

    def setUp(self):
        self.plugin = UserItems(object(), plugins.runtime.DB.instance,
                                plugins.runtime.AUTH.instance)

    def test_serialize(self):
        corpus = dict(name='intercorp_en', id='intercorp_en')
        f = FavoriteItem(data=dict(name='xxx', corpora=[
                         corpus], size=100, size_info='0.1k', subcorpus_id='foo'))
        ans = self.plugin.serialize(f)
        data = json.loads(ans)
        self.assertDictEqual(data['corpora'][0], corpus)
        self.assertEqual(data['name'], 'xxx')
        self.assertEqual(data['size'], 100)
        self.assertEqual(data['size_info'], '0.1k')
        self.assertEqual(data['subcorpus_id'], 'foo')

    def test_get_user_items(self):
        papi = PluginApi()
        papi.user_id = 7
        item1 = {'size': 150426, 'name': 'susanne - the testing one', 'subcorpus_id': '',
                 'corpora': [{'name': 'A) susanne - the testing one', 'id': 'susanne'}],
                 'id': '6287f558d64ba0e0885d0e89492e457f', 'size_info': '150k'}
        plugins.runtime.DB.instance.hash_set(
            'favitems:user:7',
            '6287f558d64ba0e0885d0e89492e457f',
            item1
        )
        item2 = {'size': 120748715, 'name': 'SYN2015 (local)', 'subcorpus_id': '',
                 'corpora': [{'name': 'B) SYN2015 (local)', 'id': 'syn2015'}],
                 'id': 'f68842708bb9a89690793106738e8690', 'size_info': '121M'}
        plugins.runtime.DB.instance.hash_set(
            'favitems:user:7',
            'f68842708bb9a89690793106738e8690',
            item2
        )
        items = self.plugin.get_user_items(papi)
        self.assertEqual(item1['size'], items[0].size)
        self.assertEqual(item1['size_info'], items[0].size_info)
        self.assertEqual(item1['name'], items[0].name)
        self.assertEqual(item1['subcorpus_id'], items[0].subcorpus_id)
        self.assertEqual(item1['id'], items[0].ident)
        self.assertEqual(item1['corpora'], items[0].corpora)
        self.assertEqual(item2['size'], items[1].size)
        self.assertEqual(item2['size_info'], items[1].size_info)
        self.assertEqual(item2['name'], items[1].name)
        self.assertEqual(item2['subcorpus_id'], items[1].subcorpus_id)
        self.assertEqual(item2['id'], items[1].ident)
        self.assertEqual(item2['corpora'], items[1].corpora)
示例#2
0
class TestPlugin(unittest.TestCase):

    def setUp(self):
        self.plugin = UserItems(object(), plugins.runtime.DB.instance,
                                plugins.runtime.AUTH.instance)

    def test_serialize(self):
        corpus = dict(name='intercorp_en', id='intercorp_en')
        f = FavoriteItem(data=dict(name='xxx', corpora=[
                         corpus], size=100, size_info='0.1k', subcorpus_id='foo'))
        ans = self.plugin.serialize(f)
        data = json.loads(ans)
        self.assertDictEqual(data['corpora'][0], corpus)
        self.assertEqual(data['name'], 'xxx')
        self.assertEqual(data['size'], 100)
        self.assertEqual(data['size_info'], '0.1k')
        self.assertEqual(data['subcorpus_id'], 'foo')

    def test_get_user_items(self):
        papi = PluginApi()
        papi.user_id = 7
        item1 = {'size': 150426, 'name': 'susanne - the testing one', 'subcorpus_id': '',
                 'corpora': [{'name': 'A) susanne - the testing one', 'id': 'susanne'}],
                 'id': '6287f558d64ba0e0885d0e89492e457f', 'size_info': '150k'}
        plugins.runtime.DB.instance.hash_set(
            'favitems:user:7',
            '6287f558d64ba0e0885d0e89492e457f',
            item1
        )
        item2 = {'size': 120748715, 'name': 'SYN2015 (local)', 'subcorpus_id': '',
                 'corpora': [{'name': 'B) SYN2015 (local)', 'id': 'syn2015'}],
                 'id': 'f68842708bb9a89690793106738e8690', 'size_info': '121M'}
        plugins.runtime.DB.instance.hash_set(
            'favitems:user:7',
            'f68842708bb9a89690793106738e8690',
            item2
        )
        items = self.plugin.get_user_items(papi)
        self.assertEqual(item1['size'], items[0].size)
        self.assertEqual(item1['size_info'], items[0].size_info)
        self.assertEqual(item1['name'], items[0].name)
        self.assertEqual(item1['subcorpus_id'], items[0].subcorpus_id)
        self.assertEqual(item1['id'], items[0].ident)
        self.assertEqual(item1['corpora'], items[0].corpora)
        self.assertEqual(item2['size'], items[1].size)
        self.assertEqual(item2['size_info'], items[1].size_info)
        self.assertEqual(item2['name'], items[1].name)
        self.assertEqual(item2['subcorpus_id'], items[1].subcorpus_id)
        self.assertEqual(item2['id'], items[1].ident)
        self.assertEqual(item2['corpora'], items[1].corpora)
示例#3
0
 def setUp(self):
     self.plugin = UserItems(object(), plugins.runtime.DB.instance,
                             plugins.runtime.AUTH.instance)
示例#4
0
 def setUp(self):
     self.plugin = UserItems(object(), plugins.runtime.DB.instance,
                             plugins.runtime.AUTH.instance)