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)
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)
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)
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)
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()
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')
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()
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()
def test_moderate_rights_required(self): ItemPrototype._db_all().update(approved=True) items_storage.refresh() self.request_login(self.account_2.email) self.check_html_ok(self.request_html(self.test_url), texts=[('collections.items.no_edit_rights', 1)])
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()
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()
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)
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)
def test_success__for_moderate(self): ItemPrototype._db_all().update(approved=True) items_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.item_1_1.reload() self.assertEqual(self.item_1_1.caption, 'caption_edited') self.assertEqual(self.item_1_1.text, 'text_edited') self.assertEqual(self.item_1_1.kit_id, self.kit_2.id)
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()), {'next_url': url('collections:collections:show', self.kit_1.collection_id)}) self.assertEqual(ItemPrototype._db_all().count(), 3) item = ItemPrototype._db_get_object(2) self.assertFalse(item.approved) self.assertEqual(item.kit_id, self.kit_1.id) self.assertEqual(item.caption, 'caption_3') self.assertEqual(item.text, 'text_3')
def test_success(self): ItemPrototype._db_all().update(approved=True) items_storage.refresh() self.item_1_1.reload() self.request_login(self.account_3.email) self.assertTrue(self.item_1_1.approved) self.check_ajax_ok(self.post_ajax_json(self.test_url)) self.item_1_1.reload() self.assertFalse(self.item_1_1.approved)
def test_success__for_moderate(self): ItemPrototype._db_all().update(approved=True) items_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.item_1_1.reload() self.assertEqual(self.item_1_1.caption, 'caption_edited') self.assertEqual(self.item_1_1.text, 'text_edited') self.assertEqual(self.item_1_1.kit_id, self.kit_2.id)
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)
def test_no_kits_in_collection(self): ItemPrototype._db_all().delete() KitPrototype._db_all().delete() items_storage.refresh() kits_storage.refresh() self.check_html_ok(self.request_html(self.test_url), texts=[self.collection_2.caption, (self.kit_2.caption, 0), (self.collection_1.caption, 0), (self.kit_1.caption, 0), ('pgf-no-kits-message', 1)])
def test_moderate_rights_required(self): ItemPrototype._db_all().update(approved=True) items_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.items.no_edit_rights') self.item_1_1.reload() self.assertEqual(self.item_1_1.caption, 'item_1_1') self.assertEqual(self.item_1_1.text, 'text_1_1') self.assertEqual(self.item_1_1.kit_id, self.collection_1.id)
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)
def test_moderate_rights_required(self): ItemPrototype._db_all().update(approved=True) items_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.items.no_edit_rights') self.item_1_1.reload() self.assertEqual(self.item_1_1.caption, 'item_1_1') self.assertEqual(self.item_1_1.text, 'text_1_1') self.assertEqual(self.item_1_1.kit_id, self.collection_1.id)
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)
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()), { 'next_url': url('collections:collections:show', self.kit_1.collection_id) }) self.assertEqual(ItemPrototype._db_all().count(), 3) item = ItemPrototype._db_get_object(2) self.assertFalse(item.approved) self.assertEqual(item.kit_id, self.kit_1.id) self.assertEqual(item.caption, 'caption_3') self.assertEqual(item.text, 'text_3')
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)
def test_get_items_count(self): self.assertEqual(get_items_count(ItemPrototype._db_all()), (collections.Counter({ self.kit_2.id: 1, self.kit_3.id: 1 }), { self.collection_2.id: 2 }))
def test_unapproved_item__anonymous(self): item = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='item_text_2_2', approved=False) self.account_1_items.add_item(item) self.account_1_items.save() self.check_html_ok(self.request_html(self.test_url), texts=[(item.caption, 0), (item.text, 0)])
def test_create(self): self.assertTrue(self.item_1_1.id in items_storage) self.assertTrue(self.item_1_2.id in items_storage) with self.check_changed(lambda: items_storage.version): item = ItemPrototype.create(kit=self.kit_2, caption=u'item_3', text=u'description_3') self.assertTrue(item.id in items_storage)
def test_unapproved_item__moderator(self): item = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='item_text_2_2', approved=False) self.account_1_items.add_item(item) self.account_1_items.save() self.request_login(self.account_2.email) self.check_html_ok(self.request_html(self.test_url), texts=[(item.caption, 1), (item.text, 1)])
def create(self): form = EditItemForm(self.request.POST) if not form.is_valid(): return self.json_error('collections.items.create.form_errors', form.errors) item = ItemPrototype.create(kit=form.c.kit, caption=form.c.caption, text=form.c.text) return self.json_ok(data={'next_url': url('collections:collections:show', item.kit.collection_id)})
def test_get_items_count__with_account(self): self.account_1_items.add_item(self.item_3_1) self.account_1_items.save() self.assertEqual( get_items_count( ItemPrototype._db_filter( id__in=self.account_1_items.items_ids())), (collections.Counter({self.kit_3.id: 1}), { self.collection_2.id: 1 }))
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)
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)
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)
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)
def create(self): form = EditItemForm(self.request.POST) if not form.is_valid(): return self.json_error('collections.items.create.form_errors', form.errors) item = ItemPrototype.create(kit=form.c.kit, caption=form.c.caption, text=form.c.text) return self.json_ok( data={ 'next_url': url('collections:collections:show', item.kit.collection_id) })
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.items.no_edit_rights') self.assertEqual(ItemPrototype._db_all().count(), 2)
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.items.no_edit_rights') self.assertEqual(ItemPrototype._db_all().count(), 2)
def test_form_errors(self): self.request_login(self.account_2.email) self.check_ajax_error(self.post_ajax_json(self.test_url, {}), 'collections.items.create.form_errors') self.assertEqual(ItemPrototype._db_all().count(), 2)
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(ItemPrototype._db_all().count(), 2)
def test_save__not_from_storage(self): self.assertRaises(exceptions.SaveNotRegisteredItemError, ItemPrototype.get_by_id(self.item_1_1.id).save)
def test_get_items_count(self): self.assertEqual(get_items_count(ItemPrototype._db_all()), (collections.Counter({self.kit_2.id: 1, self.kit_3.id: 1}), {self.collection_2.id: 2}))
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(ItemPrototype._db_all().count(), 2)
def test_get_items_count__with_account(self): self.account_1_items.add_item(self.item_3_1) self.account_1_items.save() self.assertEqual(get_items_count(ItemPrototype._db_filter(id__in=self.account_1_items.items_ids())), (collections.Counter({self.kit_3.id: 1}), {self.collection_2.id: 1}))