Ejemplo n.º 1
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111')
        self.account_3 = AccountPrototype.get_by_id(account_id)

        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate_item = sync_group('moderate item', ['collections.moderate_item'])

        group_edit = sync_group('edit kit', ['collections.edit_kit'])
        group_moderate = sync_group('moderate kit', ['collections.moderate_kit'])

        group_edit_item.user_set.add(self.account_2._model)
        group_moderate_item.user_set.add(self.account_3._model)

        group_edit.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2')

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True)
        self.kit_2 = KitPrototype.create(collection=self.collection_1, caption=u'kit_2', description=u'description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
Ejemplo n.º 2
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()
        self.account_3 = self.accounts_factory.create_account()

        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate_item = sync_group('moderate item', ['collections.moderate_item'])

        group_edit = sync_group('edit kit', ['collections.edit_kit'])
        group_moderate = sync_group('moderate kit', ['collections.moderate_kit'])

        group_edit_item.user_set.add(self.account_2._model)
        group_moderate_item.user_set.add(self.account_3._model)

        group_edit.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2')

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1', approved=True)
        self.kit_2 = KitPrototype.create(collection=self.collection_1, caption='kit_2', description='description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
Ejemplo n.º 3
0
 def collections(self):
     if self.moderate_collection_permission or self.edit_collection_permission:
         return sorted(CollectionPrototype.all_collections(),
                       key=lambda c: c.caption)
     else:
         return sorted(CollectionPrototype.approved_collections(),
                       key=lambda c: c.caption)
Ejemplo n.º 4
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption='kit_3', description='description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption='item_3_1', text='text_3_1', approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
Ejemplo n.º 5
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption=u'kit_2', description=u'description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption=u'kit_3', description=u'description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_1', text=u'text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_2', text=u'text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption=u'item_3_1', text=u'text_3_1', approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
Ejemplo n.º 6
0
    def test_moderate_rights_required(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()

        self.request_login(self.account_2.email)
        self.check_html_ok(self.request_html(self.test_url),
                           texts=(('collections.collections.no_edit_rights', 1)))
Ejemplo n.º 7
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()
        self.account_3 = self.accounts_factory.create_account()

        group_edit = sync_group('edit item', ['collections.edit_item'])
        group_moderate = sync_group('moderate item',
                                    ['collections.moderate_item'])

        group_edit.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(
            caption='collection_2', description='description_2')

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_2',
                                         description='description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2')
Ejemplo n.º 8
0
    def setUp(self):
        super(ItemsContainerTests, self).setUp()

        self.container = ItemsContainer()

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'text_2_1',
                                             approved=True)
Ejemplo n.º 9
0
    def test_success__for_moderate(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()

        self.request_login(self.account_3.email)
        self.check_html_ok(self.request_html(self.test_url),
                           texts=[self.collection_1.caption,
                                  self.collection_1.description])
Ejemplo n.º 10
0
    def test_success__for_moderate(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()

        self.request_login(self.account_3.email)
        self.check_html_ok(
            self.request_html(self.test_url),
            texts=[self.collection_1.caption, self.collection_1.description])
Ejemplo n.º 11
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_3',
                                         description=u'description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_2',
                                             text=u'text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption=u'item_3_1',
                                             text=u'text_3_1',
                                             approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
Ejemplo n.º 12
0
    def test_moderate_rights_required(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()

        self.request_login(self.account_2.email)
        self.check_ajax_error(self.post_ajax_json(self.test_url, self.get_post_data()),
                              'collections.collections.no_edit_rights')
        self.collection_1.reload()
        self.assertEqual(self.collection_1.caption, 'collection_1')
        self.assertEqual(self.collection_1.description, 'description_1')
Ejemplo n.º 13
0
    def test_success__for_moderate(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()

        self.request_login(self.account_3.email)
        self.check_ajax_ok(self.post_ajax_json(self.test_url, self.get_post_data()))

        self.collection_1.reload()
        self.assertEqual(self.collection_1.caption, 'collection_edited')
        self.assertEqual(self.collection_1.description, 'description_edited')
Ejemplo n.º 14
0
    def test_success(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()
        self.collection_1.reload()

        self.request_login(self.account_3.email)

        self.assertTrue(self.collection_1.approved)
        self.check_ajax_ok(self.post_ajax_json(self.disapprove_url))
        self.collection_1.reload()
        self.assertFalse(self.collection_1.approved)
Ejemplo n.º 15
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_3',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_3 = AccountPrototype.get_by_id(account_id)

        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate_item = sync_group('moderate item',
                                         ['collections.moderate_item'])

        group_edit = sync_group('edit kit', ['collections.edit_kit'])
        group_moderate = sync_group('moderate kit',
                                    ['collections.moderate_kit'])

        group_edit_item.user_set.add(self.account_2._model)
        group_moderate_item.user_set.add(self.account_3._model)

        group_edit.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2', description=u'description_2')

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1',
                                         approved=True)
        self.kit_2 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_2',
                                         description=u'description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
Ejemplo n.º 16
0
    def test_success(self):
        self.request_login(self.account_2.email)

        self.check_ajax_ok(self.post_ajax_json(self.test_url, self.get_post_data()))
        self.assertEqual(CollectionPrototype._db_all().count(), 3)

        collection = CollectionPrototype._db_get_object(2)

        self.assertFalse(collection.approved)
        self.assertEqual(collection.caption, 'caption_3')
        self.assertEqual(collection.description, 'description_3')
Ejemplo n.º 17
0
    def test_success(self):
        CollectionPrototype._db_all().update(approved=True)
        collections_storage.refresh()
        self.collection_1.reload()

        self.request_login(self.account_3.email)

        self.assertTrue(self.collection_1.approved)
        self.check_ajax_ok(self.post_ajax_json(self.disapprove_url))
        self.collection_1.reload()
        self.assertFalse(self.collection_1.approved)
Ejemplo n.º 18
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_3',
                                         description=u'description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_2',
                                             text=u'text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption=u'item_3_1',
                                             text=u'text_3_1',
                                             approved=True)
Ejemplo n.º 19
0
    def setUp(self):
        super(ItemsContainerTests, self).setUp()

        self.container = ItemsContainer()

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2')

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='text_2_1', approved=True)
Ejemplo n.º 20
0
    def setUp(self):
        super(_BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        group_edit = sync_group('edit achievement', ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=0, points=10,
                                                         caption=u'achievement_1', description=u'description_1', approved=True)
        self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=2, points=10,
                                                         caption=u'achievement_2', description=u'description_2', approved=False)
        self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.TIME, barrier=3, points=10,
                                                         caption=u'achievement_3', description=u'description_3', approved=True)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1', approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=True)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(self.achievement_1)
        self.account_achievements_1.save()
Ejemplo n.º 21
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1',
            description=u'description_1',
            approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_3',
                                             text=u'text_1_3',
                                             approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption=u'achievement_1',
            description=u'description_1',
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption=u'achievement_2',
            description=u'description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption=u'achievement_3',
            description=u'description_3',
            approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
Ejemplo n.º 22
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(
            caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption='kit_2',
                                         description='description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption='kit_3',
                                         description='description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption='item_2_1',
                                             text='text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption='item_2_2',
                                             text='text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption='item_3_1',
                                             text='text_3_1',
                                             approved=True)
Ejemplo n.º 23
0
    def test_create(self):
        self.assertTrue(self.collection_1.id in collections_storage)
        self.assertTrue(self.collection_2.id in collections_storage)

        with self.check_changed(lambda: collections_storage.version):
            collection = CollectionPrototype.create(caption=u'collection_3', description=u'description_3')

        self.assertTrue(collection.id in collections_storage)
Ejemplo n.º 24
0
    def setUp(self):
        super(_BaseRequestTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        group_edit = sync_group('edit achievement',
                                ['achievements.edit_achievement'])

        group_edit.user_set.add(self.account_2._model)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=0,
            points=10,
            caption='achievement_1',
            description='description_1',
            approved=True)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption='achievement_2',
            description='description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption='achievement_3',
            description='description_3',
            approved=True)

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=True)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
        self.account_achievements_1.achievements.add_achievement(
            self.achievement_1)
        self.account_achievements_1.save()
Ejemplo n.º 25
0
    def create(self):
        form = EditCollectionForm(self.request.POST)

        if not form.is_valid():
            return self.json_error('collections.collections.create.form_errors', form.errors)

        collection = CollectionPrototype.create(caption=form.c.caption,
                                          description=form.c.description)

        return self.json_ok(data={'next_url': url('collections:collections:show', collection.id)})
Ejemplo n.º 26
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1',
                                         approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_3',
                                             text='text_1_3',
                                             approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption='achievement_1',
            description='description_1',
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption='achievement_2',
            description='description_2',
            approved=False)
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption='achievement_3',
            description='description_3',
            approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(
            self.account_1.id)
Ejemplo n.º 27
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption='kit_3', description='description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption='item_3_1', text='text_3_1', approved=True)
Ejemplo n.º 28
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption=u'kit_2', description=u'description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption=u'kit_3', description=u'description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_1', text=u'text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_2', text=u'text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption=u'item_3_1', text=u'text_3_1', approved=True)
Ejemplo n.º 29
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()
        self.account_3 = self.accounts_factory.create_account()
        self.account_4 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)
        self.account_2_items = AccountItemsPrototype.get_by_account_id(self.account_2.id)
        self.account_3_items = AccountItemsPrototype.get_by_account_id(self.account_3.id)

        group_edit_kit = sync_group('edit kit', ['collections.edit_kit'])
        group_edit = sync_group('edit collection', ['collections.edit_collection'])
        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate = sync_group('moderate collection', ['collections.moderate_collection'])
        group_moderate_kit = sync_group('moderate kit', ['collections.moderate_kit'])
        group_moderate_item = sync_group('moderate item', ['collections.moderate_item'])

        group_edit_kit.user_set.add(self.account_2._model)
        group_edit.user_set.add(self.account_2._model)
        group_edit_item.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)
        group_moderate_kit.user_set.add(self.account_3._model)
        group_moderate_item.user_set.add(self.account_3._model)


        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='item_text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='item_text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='item_text_2_1', approved=True)
Ejemplo n.º 30
0
    def create(self):
        form = EditCollectionForm(self.request.POST)

        if not form.is_valid():
            return self.json_error(
                'collections.collections.create.form_errors', form.errors)

        collection = CollectionPrototype.create(caption=form.c.caption,
                                                description=form.c.description)

        return self.json_ok(
            data={
                'next_url': url('collections:collections:show', collection.id)
            })
Ejemplo n.º 31
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user("test_user_1", "*****@*****.**", "111111")
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.collection_1 = CollectionPrototype.create(
            caption=u"collection_1", description=u"description_1", approved=True
        )
        self.kit_1 = KitPrototype.create(
            collection=self.collection_1, caption=u"kit_1", description=u"description_1", approved=True
        )
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_1", text=u"text_1_1", approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_2", text=u"text_1_2", approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1, caption=u"item_1_3", text=u"text_1_3", approved=True)

        self.achievement_1 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=1,
            points=10,
            caption=u"achievement_1",
            description=u"description_1",
            approved=True,
            item_1=self.item_1_1,
            item_2=self.item_1_2,
        )
        self.achievement_2 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.MONEY,
            type=ACHIEVEMENT_TYPE.MONEY,
            barrier=2,
            points=10,
            caption=u"achievement_2",
            description=u"description_2",
            approved=False,
        )
        self.achievement_3 = AchievementPrototype.create(
            group=ACHIEVEMENT_GROUP.TIME,
            type=ACHIEVEMENT_TYPE.TIME,
            barrier=3,
            points=10,
            caption=u"achievement_3",
            description=u"description_3",
            approved=True,
        )

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
Ejemplo n.º 32
0
    def setUp(self):
        super(AccountAchievementsPrototypeTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1', approved=True)
        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1', approved=True)
        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_1_3 = ItemPrototype.create(kit=self.kit_1, caption='item_1_3', text='text_1_3', approved=True)


        self.achievement_1 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=1, points=10,
                                                         caption='achievement_1', description='description_1', approved=True,
                                                         item_1=self.item_1_1, item_2=self.item_1_2)
        self.achievement_2 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.MONEY, type=ACHIEVEMENT_TYPE.MONEY, barrier=2, points=10,
                                                         caption='achievement_2', description='description_2', approved=False)
        self.achievement_3 = AchievementPrototype.create(group=ACHIEVEMENT_GROUP.TIME, type=ACHIEVEMENT_TYPE.TIME, barrier=3, points=10,
                                                         caption='achievement_3', description='description_3', approved=True)

        self.account_achievements_1 = AccountAchievementsPrototype.get_by_account_id(self.account_1.id)
Ejemplo n.º 33
0
 def test_form_errors(self):
     self.request_login(self.account_2.email)
     self.check_ajax_error(self.post_ajax_json(self.test_url, {}),
                           'collections.collections.create.form_errors')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)
Ejemplo n.º 34
0
 def test_form_errors(self):
     self.request_login(self.account_2.email)
     self.check_ajax_error(self.post_ajax_json(self.test_url, {}),
                           'collections.collections.create.form_errors')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)
Ejemplo n.º 35
0
 def test_edit_rights_required(self):
     self.request_login(self.account_1.email)
     self.check_ajax_error(
         self.post_ajax_json(self.test_url, self.get_post_data()),
         'collections.collections.no_edit_rights')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)
Ejemplo n.º 36
0
 def test_login_required(self):
     self.check_ajax_error(
         self.post_ajax_json(self.test_url, self.get_post_data()),
         'common.login_required')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)
Ejemplo n.º 37
0
 def test_save__not_from_storage(self):
     self.assertRaises(exceptions.SaveNotRegisteredCollectionError, CollectionPrototype.get_by_id(self.collection_1.id).save)
Ejemplo n.º 38
0
 def collections(self):
     if self.moderate_collection_permission or self.edit_collection_permission:
         return sorted(CollectionPrototype.all_collections(), key=lambda c: c.caption)
     else:
         return sorted(CollectionPrototype.approved_collections(), key=lambda c: c.caption)
Ejemplo n.º 39
0
 def test_edit_rights_required(self):
     self.request_login(self.account_1.email)
     self.check_ajax_error(self.post_ajax_json(self.test_url, self.get_post_data()),
                           'collections.collections.no_edit_rights')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)
Ejemplo n.º 40
0
 def test_login_required(self):
     self.check_ajax_error(self.post_ajax_json(self.test_url, self.get_post_data()),
                           'common.login_required')
     self.assertEqual(CollectionPrototype._db_all().count(), 2)