示例#1
0
    def test_get_restrictions(self):
        restriction_1 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=666, name='bla-bla-name')
        restriction_2 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.GENDER, external_id=667, name='name-2')
        restriction_3 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=668, name='name-3')

        self.assertEqual(storage.restrictions_storage.get_restrictions(relations.TEMPLATE_RESTRICTION_GROUP.RACE), [restriction_1, restriction_3])
        self.assertEqual(storage.restrictions_storage.get_restrictions(relations.TEMPLATE_RESTRICTION_GROUP.GENDER), [restriction_2])
示例#2
0
    def test_add_item(self):
        restriction_1 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=666, name=u"bla-bla-name"
        )

        self.assertEqual(storage.restrictions_storage._data, {restriction_1.id: restriction_1})
        self.assertEqual(storage.restrictions_storage._restrictions, {restriction_1.storage_key(): restriction_1})
        self.assertEqual(storage.restrictions_storage._restrictions_by_group, {restriction_1.group: [restriction_1]})

        restriction_2 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.GENDER, external_id=667, name=u"name-2"
        )
        restriction_3 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=668, name=u"name-3"
        )

        self.assertEqual(
            storage.restrictions_storage._data,
            {restriction_1.id: restriction_1, restriction_2.id: restriction_2, restriction_3.id: restriction_3},
        )
        self.assertEqual(
            storage.restrictions_storage._restrictions,
            {
                restriction_1.storage_key(): restriction_1,
                restriction_2.storage_key(): restriction_2,
                restriction_3.storage_key(): restriction_3,
            },
        )
        self.assertEqual(
            storage.restrictions_storage._restrictions_by_group,
            {restriction_1.group: [restriction_1, restriction_3], restriction_2.group: [restriction_2]},
        )
示例#3
0
    def test_create_restriction__duplicate(self):

        group = random.choice(relations.TEMPLATE_RESTRICTION_GROUP.records)

        logic.create_restriction(group=group, external_id=666, name=u'bla-bla-name')

        with self.check_not_changed(models.Restriction.objects.count):
            with self.check_not_changed(lambda: storage.restrictions_storage._version):
                with self.check_not_changed(storage.restrictions_storage.__len__):
                    with transaction.atomic():
                        self.assertRaises(IntegrityError, logic.create_restriction, group=group, external_id=666, name=u'bla-bla-name')
示例#4
0
    def test_add_item(self):
        restriction_1 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=666, name=u'bla-bla-name')

        self.assertEqual(storage.restrictions_storage._data, {restriction_1.id: restriction_1})
        self.assertEqual(storage.restrictions_storage._restrictions, {restriction_1.storage_key(): restriction_1})
        self.assertEqual(storage.restrictions_storage._restrictions_by_group, {restriction_1.group: [restriction_1]})

        restriction_2 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.GENDER, external_id=667, name=u'name-2')
        restriction_3 = logic.create_restriction(group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=668, name=u'name-3')

        self.assertEqual(storage.restrictions_storage._data, {restriction_1.id: restriction_1,
                                                              restriction_2.id: restriction_2,
                                                              restriction_3.id: restriction_3})
        self.assertEqual(storage.restrictions_storage._restrictions, {restriction_1.storage_key(): restriction_1,
                                                                      restriction_2.storage_key(): restriction_2,
                                                                      restriction_3.storage_key(): restriction_3})
        self.assertEqual(storage.restrictions_storage._restrictions_by_group, {restriction_1.group: [restriction_1, restriction_3],
                                                                               restriction_2.group: [restriction_2]})
示例#5
0
    def test_get_restriction(self):
        restriction_1 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=666, name=u"bla-bla-name"
        )
        restriction_2 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.GENDER, external_id=667, name=u"name-2"
        )
        restriction_3 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE, external_id=668, name=u"name-3"
        )

        self.assertEqual(
            restriction_1, storage.restrictions_storage.get_restriction(relations.TEMPLATE_RESTRICTION_GROUP.RACE, 666)
        )
        self.assertEqual(
            restriction_2,
            storage.restrictions_storage.get_restriction(relations.TEMPLATE_RESTRICTION_GROUP.GENDER, 667),
        )
        self.assertEqual(
            restriction_3, storage.restrictions_storage.get_restriction(relations.TEMPLATE_RESTRICTION_GROUP.RACE, 668)
        )
示例#6
0
    def test_get_restrictions(self):
        restriction_1 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE,
            external_id=666,
            name='bla-bla-name')
        restriction_2 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.GENDER,
            external_id=667,
            name='name-2')
        restriction_3 = logic.create_restriction(
            group=relations.TEMPLATE_RESTRICTION_GROUP.RACE,
            external_id=668,
            name='name-3')

        self.assertEqual(
            storage.restrictions_storage.get_restrictions(
                relations.TEMPLATE_RESTRICTION_GROUP.RACE),
            [restriction_1, restriction_3])
        self.assertEqual(
            storage.restrictions_storage.get_restrictions(
                relations.TEMPLATE_RESTRICTION_GROUP.GENDER), [restriction_2])
示例#7
0
    def test_sync_restrictions(self):
        key = keys.LEXICON_KEY.HERO_COMMON_JOURNAL_LEVEL_UP

        group_1, group_2, group_3 = random.sample(relations.TEMPLATE_RESTRICTION_GROUP.records, 3)

        restriction_1_1 = logic.create_restriction(group=group_1, external_id=100500, name='name-1-1')
        restriction_1_2 = logic.create_restriction(group=group_1, external_id=200500, name='name-1-2')
        restriction_2_1 = logic.create_restriction(group=group_2, external_id=100500, name='name-2-1')
        restriction_2_2 = logic.create_restriction(group=group_2, external_id=200500, name='name-2-2')
        restriction_2_3 = logic.create_restriction(group=group_2, external_id=300500, name='name-2-3')
        restriction_3_1 = logic.create_restriction(group=group_3, external_id=100500, name='name-3-1')

        template_1 = prototypes.TemplatePrototype.create(key=key, raw_template=self.text_1, utg_template=self.template_1,
                                                         verificators=[],  author=self.account_1,
                                                         restrictions=(('hero', restriction_1_1.id), ('hero', restriction_2_2.id)))

        template_2 = prototypes.TemplatePrototype.create(key=key, raw_template=self.text_1, utg_template=self.template_1,
                                                         verificators=[],  author=self.account_1,
                                                         restrictions=(('hero', restriction_1_2.id), ('level', restriction_2_1.id), ('hero', restriction_3_1.id)))

        template_1.update(restrictions=(('level', restriction_2_3.id), ('hero', restriction_2_2.id), ('level', restriction_2_1.id)))

        self.assertEqual(models.TemplateRestriction.objects.count(), 6)

        existed_restrictions = frozenset(models.TemplateRestriction.objects.values_list('template_id', 'variable', 'restriction_id'))

        expected_restrictions = frozenset([(template_1.id, 'hero', restriction_2_2.id),
                                           (template_1.id, 'level', restriction_2_1.id),
                                           (template_1.id, 'level', restriction_2_3.id),
                                           (template_2.id, 'hero', restriction_1_2.id),
                                           (template_2.id, 'level', restriction_2_1.id),
                                           (template_2.id, 'hero', restriction_3_1.id)])

        self.assertEqual(existed_restrictions, expected_restrictions)
示例#8
0
    def test_sync_restrictions(self):
        key = keys.LEXICON_KEY.HERO_COMMON_JOURNAL_LEVEL_UP

        group_1, group_2, group_3 = random.sample(relations.TEMPLATE_RESTRICTION_GROUP.records, 3)

        restriction_1_1 = logic.create_restriction(group=group_1, external_id=100500, name='name-1-1')
        restriction_1_2 = logic.create_restriction(group=group_1, external_id=200500, name='name-1-2')
        restriction_2_1 = logic.create_restriction(group=group_2, external_id=100500, name='name-2-1')
        restriction_2_2 = logic.create_restriction(group=group_2, external_id=200500, name='name-2-2')
        restriction_2_3 = logic.create_restriction(group=group_2, external_id=300500, name='name-2-3')
        restriction_3_1 = logic.create_restriction(group=group_3, external_id=100500, name='name-3-1')

        template_1 = prototypes.TemplatePrototype.create(key=key, raw_template=self.text_1, utg_template=self.template_1,
                                                         verificators=[],  author=self.account_1,
                                                         restrictions=(('hero', restriction_1_1.id), ('hero', restriction_2_2.id)))

        template_2 = prototypes.TemplatePrototype.create(key=key, raw_template=self.text_1, utg_template=self.template_1,
                                                         verificators=[],  author=self.account_1,
                                                         restrictions=(('hero', restriction_1_2.id), ('level', restriction_2_1.id), ('hero', restriction_3_1.id)))

        template_1.update(restrictions=(('level', restriction_2_3.id), ('hero', restriction_2_2.id), ('level', restriction_2_1.id)))

        self.assertEqual(models.TemplateRestriction.objects.count(), 6)

        existed_restrictions = frozenset(models.TemplateRestriction.objects.values_list('template_id', 'variable', 'restriction_id'))

        expected_restrictions = frozenset([(template_1.id, 'hero', restriction_2_2.id),
                                           (template_1.id, 'level', restriction_2_1.id),
                                           (template_1.id, 'level', restriction_2_3.id),
                                           (template_2.id, 'hero', restriction_1_2.id),
                                           (template_2.id, 'level', restriction_2_1.id),
                                           (template_2.id, 'hero', restriction_3_1.id)])

        self.assertEqual(existed_restrictions, expected_restrictions)
示例#9
0
    def test_sync_restriction__exists(self):
        group = random.choice(relations.TEMPLATE_RESTRICTION_GROUP.records)

        restriction = logic.create_restriction(group=group, external_id=666, name=u'bla-bla-name')

        with self.check_not_changed(models.Restriction.objects.count):
            with self.check_changed(lambda: storage.restrictions_storage._version):
                with self.check_not_changed(storage.restrictions_storage.__len__):
                    synced_restriction = logic.sync_restriction(group=group, external_id=666, name=u'new-name')

        self.assertEqual(synced_restriction.name, u'new-name')

        model = models.Restriction.objects.get(id=restriction.id)

        loaded_restriction = objects.Restriction.from_model(model)

        self.assertEqual(loaded_restriction, synced_restriction)
示例#10
0
    def test_create_restriction(self):

        group = random.choice(relations.TEMPLATE_RESTRICTION_GROUP.records)

        with self.check_delta(models.Restriction.objects.count, 1):
            with self.check_changed(lambda: storage.restrictions_storage._version):
                with self.check_delta(storage.restrictions_storage.__len__, 1):
                    restriction = logic.create_restriction(group=group,
                                                           external_id=666,
                                                           name=u'bla-bla-name')

        self.assertEqual(restriction.group, group)
        self.assertEqual(restriction.external_id, 666)
        self.assertEqual(restriction.name, u'bla-bla-name')

        model = models.Restriction.objects.get(id=restriction.id)

        loaded_restriction = objects.Restriction.from_model(model)

        self.assertEqual(loaded_restriction, restriction)