Ejemplo n.º 1
0
    def test_process_change_power__persons(self):
        self.assertEqual(self.worker.persons_politic_power, [])

        person_1, person_2 = persons_storage.persons.all()[0:2]

        power_info_1 = highlevel.PowerInfo(hero_id=666,
                                           has_place_in_preferences=True,
                                           has_person_in_preferences=False,
                                           person_id=person_1.id,
                                           place_id=None,
                                           power_delta=1)

        self.worker.process_change_power(**power_info_1.kwargs)

        self.assertEqual(self.worker.persons_politic_power, [power_info_1])

        power_info_2 = highlevel.PowerInfo(hero_id=777,
                                           has_place_in_preferences=False,
                                           has_person_in_preferences=True,
                                           person_id=person_2.id,
                                           place_id=None,
                                           power_delta=10)

        self.worker.process_change_power(**power_info_2.kwargs)
        self.assertEqual(self.worker.persons_politic_power,
                         [power_info_1, power_info_2])

        power_info_3 = highlevel.PowerInfo(hero_id=None,
                                           has_place_in_preferences=False,
                                           has_person_in_preferences=False,
                                           person_id=person_1.id,
                                           place_id=None,
                                           power_delta=-100)

        self.worker.process_change_power(**power_info_3.kwargs)
        self.assertEqual(self.worker.persons_politic_power,
                         [power_info_1, power_info_2, power_info_3])

        self.assertEqual(person_1.politic_power.inner_power, 0)
        self.assertEqual(person_1.politic_power.outer_power, 0)
        self.assertEqual(person_2.politic_power.inner_power, 0)
        self.assertEqual(person_2.politic_power.outer_power, 0)
Ejemplo n.º 2
0
    def test_sync_data(self):
        self.assertEqual(self.p1.politic_power.outer_power, 0)
        self.assertEqual(self.p1.politic_power.inner_power, 0)
        self.assertEqual(self.p2.politic_power.outer_power, 0)
        self.assertEqual(self.p2.politic_power.inner_power, 0)
        self.assertEqual(self.p3.politic_power.outer_power, 0)
        self.assertEqual(self.p3.politic_power.inner_power, 0)

        self.assertEqual(Person.objects.filter(place_id=self.p1.id).count(), 3)
        self.assertEqual(Person.objects.filter(place_id=self.p2.id).count(), 3)
        self.assertEqual(Person.objects.filter(place_id=self.p3.id).count(), 3)
        self.assertEqual(len(persons_storage.persons.all()), 9)

        person_1_1 = self.p1.persons[0]
        person_2_1 = self.p2.persons[0]
        person_2_2 = self.p2.persons[1]
        person_3_1 = self.p3.persons[0]
        person_3_2 = self.p3.persons[1]

        power_info = highlevel.PowerInfo(hero_id=666,
                                         has_place_in_preferences=False,
                                         has_person_in_preferences=False,
                                         person_id=None,
                                         place_id=None,
                                         power_delta=0)

        self.worker.process_change_power(
            **power_info.clone(person_id=person_1_1.id, power_delta=1).kwargs)
        self.worker.process_change_power(**power_info.clone(
            person_id=person_2_1.id, power_delta=100).kwargs)
        self.worker.process_change_power(**power_info.clone(
            person_id=person_2_2.id, power_delta=1000).kwargs)
        self.worker.process_change_power(**power_info.clone(
            person_id=person_3_1.id, power_delta=10000).kwargs)
        self.worker.process_change_power(**power_info.clone(
            person_id=person_3_2.id, power_delta=100000).kwargs)

        with self.check_changed(lambda: persons_storage.persons._version):
            with self.check_changed(lambda: places_storage.places._version):
                with mock.patch(
                        'the_tale.game.places.attributes.Attributes.freedom',
                        1):
                    self.worker.sync_data()

        self.assertEqual(self.worker.persons_politic_power, [])
        self.assertEqual(self.worker.places_politic_power, [])

        self.assertTrue(self.p1._modifier.is_NONE)

        self.assertEqual(person_1_1.politic_power.outer_power, 1)
        self.assertEqual(person_2_1.politic_power.outer_power, 100)
        self.assertEqual(person_2_2.politic_power.outer_power, 1000)
        self.assertEqual(person_3_1.politic_power.outer_power, 10000)
        self.assertEqual(person_3_2.politic_power.outer_power, 100000)

        self.assertEqual(self.p1.politic_power.outer_power, 1)
        self.assertEqual(self.p2.politic_power.outer_power, 1100)
        self.assertEqual(self.p3.politic_power.outer_power, 110000)

        self.worker.process_change_power(
            **power_info.clone(place_id=self.p1.id, power_delta=-10).kwargs)
        self.worker.process_change_power(
            **power_info.clone(place_id=self.p2.id, power_delta=-1).kwargs)
        self.worker.process_change_power(**power_info.clone(
            place_id=self.p2.id, power_delta=+10000000).kwargs)
        self.worker.process_change_power(
            **power_info.clone(place_id=self.p3.id, power_delta=-2).kwargs)
        self.worker.process_change_power(
            **power_info.clone(place_id=self.p3.id, power_delta=+20).kwargs)

        with self.check_changed(lambda: persons_storage.persons._version):
            with self.check_changed(lambda: places_storage.places._version):
                with mock.patch(
                        'the_tale.game.places.attributes.Attributes.freedom',
                        1):
                    self.worker.sync_data()

        self.assertEqual(self.worker.persons_politic_power, [])
        self.assertEqual(self.worker.places_politic_power, [])

        self.p1 = places_storage.places[self.p1.id]
        self.p2 = places_storage.places[self.p2.id]
        self.p3 = places_storage.places[self.p3.id]

        self.assertEqual(self.p1.politic_power.outer_power, -9.1)
        self.assertEqual(self.p2.politic_power.outer_power, 10000989)
        self.assertEqual(self.p3.politic_power.outer_power, 99018)