Example #1
0
	def test_pendingmission_set_get_value(self):
		"""
		Test that setting and retrieving a context value through a PendingMission works
		"""

		f = Folk(
			kingdom=self.k,
			first_name="Theon",
			last_name="Greyjoy"
		)
		f.save()

		self.pm.set_value("peon", f)
		self.assertEqual(f, self.pm.get_value("peon"))

		self.pm.set_value("Narnia", self.k)
		self.assertEqual(self.k, self.pm.get_value("Narnia"))

		self.pm.set_value("nompourri", "Kevin")
		self.assertEqual(self.pm.get_value("nompourri"), "Kevin")

		self.pm.set_value("beastnum", 666)
		self.assertEqual(self.pm.get_value("beastnum"), 666)

		self.pm.set_value("void", None)
		self.assertEqual(self.pm.get_value("void"), None)
Example #2
0
	def test_templates_and_folk_details_templatetags(self):
		"""
		Check folk_details template_tags.
		"""
		folk = Folk(first_name="septon", sex=Folk.MALE, kingdom=self.k)
		cat  = QualityCategory(name="boa",description="so")
		cat.save()
		quality = Quality(slug="lol",name="sdf",category=cat)
		quality.save()
		folk.save()

		folk.quality_set.add(quality)

		self.e.text = "{{ septon|folk_details }}"
		self.e.save()

		pe = PendingEvent(
			event=self.e,
			kingdom=self.k,
			started=None
		)

		pe.save()
		pe.set_value("septon", folk)

		pe.started = datetime.now()
		pe.save()

		self.assertTrue(quality.name in pe.text)
		self.assertTrue(str(folk.fight) in pe.text)
		self.assertTrue("<table>" in pe.text)
Example #3
0
	def test_grid_length(self):
		"""
		Check grid length constraint.
		"""

		self.mg.length = 1
		self.mg.save()

		f2 = Folk(
			kingdom=self.k,
			first_name="Cersei",
			last_name="Lannister"
		)
		f2.save()

		pma2 = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=self.mg,
			folk=f2
		)

		# Too many people
		self.assertRaises(ValidationError, pma2.save)

		# Update length, now can be saved
		self.mg.length = 2
		self.mg.save()
		pma2.save()
Example #4
0
	def test_pendingevent_set_get_value(self):
		"""
		Test that setting and retrieving a context value through a Pending Event works
		"""

		pe = PendingEvent(
			event=self.e,
			kingdom=self.k,
		)
		pe.save()

		f = Folk(
			kingdom=self.k,
			first_name="Theon",
			last_name="Greyjoy"
		)
		f.save()

		pe.set_value("peon", f)
		self.assertEqual(f, pe.get_value("peon"))

		pe.set_value("Narnia", self.k)
		self.assertEqual(self.k, pe.get_value("Narnia"))

		pe.set_value("nompourri", "Kevin")
		self.assertEqual(pe.get_value("nompourri"), "Kevin")

		pe.set_value("beastnum", 666)
		self.assertEqual(pe.get_value("beastnum"), 666)

		pe.set_value("void", None)
		self.assertEqual(pe.get_value("void"), None)
Example #5
0
	def test_auto_name_for_folk(self):
		"""
		The name is automatically filled.
		"""

		FirstName(name="Gendry", sex=Folk.MALE).save()
		LastName(name="Baratheon").save()

		f2 = Folk(kingdom=self.k)
		f2.save()

		self.assertEqual(f2.first_name, "Gendry")
		self.assertEqual(f2.last_name, "Baratheon")
Example #6
0
	def test_kingdom_value_store_list_fk(self):
		"""
		Store list of fk values on the kingdom
		"""

		f2 = Folk(kingdom=self.k)
		f2.save()
		datas = [self.f, f2, True, 0, "trololol"]
		self.k.set_value("foo", datas)

		stored_datas = self.k.get_value("foo")
		for r, s in zip(datas, stored_datas):
			self.assertEqual(r, s)
Example #7
0
	def test_grid_with_two_grids(self):
		"""
		Check if folks are well put in the grid
		"""
		mg2 = MissionGrid(
			mission=self.m,
			slug='stub_grid2'
		)
		mg2.save()

		self.m.on_resolution = """
status = grids['stub_grid'][0].first_name + " " + grids['stub_grid2'][0].first_name
"""
		self.m.save()

		self.f.first_name = "a"
		self.f.save()

		self.f2 = Folk(
			kingdom=self.k,
			first_name="b"
		)
		self.f2.save()

		self.pma2 = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=mg2,
			folk=self.f2
		)
		self.pma2.save()

		self.pm.start()
		status = self.pm.resolve()
		self.assertEqual(status, 'a b')
Example #8
0
	def test_grid_with_two_people(self):
		"""
		Check if folks are well put in the grid
		"""

		self.m.on_resolution = """
status = grids['stub_grid'][0].first_name + " " + grids['stub_grid'][1].first_name
"""
		self.m.save()

		self.f.first_name = "a"
		self.f.save()

		self.f2 = Folk(
			kingdom=self.k,
			first_name="b"
		)
		self.f2.save()

		self.mg.length = 2
		self.mg.save()

		self.pma2 = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=self.mg,
			folk=self.f2
		)
		self.pma2.save()
		self.pm.start()
		status = self.pm.resolve()
		self.assertEqual(status, 'a b')
Example #9
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()
Example #10
0
	def test_sanity_folk_in_kingdoms(self):
		"""
		The folk in PendingBargainSharedMissionAffectation must be owned by one of the sides of the negotiation.
		"""
		k3 = Kingdom()
		k3.save()

		f2 = Folk(kingdom=k3)
		f2.save()

		pbsma = PendingBargainSharedMissionAffectation(
			pending_bargain_shared_mission=self.pbsm,
			mission_grid=self.mg,
			folk=f2
		)

		# folk.kingdom != pbk.kingdom
		self.assertRaises(IntegrityError, pbsma.save)
Example #11
0
    def setUp(self):
        self.k = Kingdom()
        self.k.save()

        self.f = Folk(first_name="bob", kingdom=self.k)
        self.f.save()

        self.m = Mission(name="Stub mission", slug="stub", on_resolution="")
        self.m.save()
Example #12
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
			first_name="Robert",
			last_name="Baratheon"
		)
		self.f.save()
Example #13
0
	def test_templates_and_feminize_templatetags(self):
		"""
		Check feminize template_tags.
		"""

		f = Folk(first_name="septon", sex=Folk.MALE, kingdom=self.k)
		f.save()
		f2 = Folk(first_name="cersei", sex=Folk.FEMALE, kingdom=self.k)
		f2.save()

		self.e.text = "batard{{ septon|feminize }}, batard{{ cersei|feminize }}"
		self.e.save()

		pe = PendingEvent(
			event=self.e,
			kingdom=self.k,
			started=None
		)
		pe.save()
		pe.set_value("septon", f)
		pe.set_value("cersei", f2)

		pe.started = datetime.now()
		pe.save()

		self.assertEqual(pe.text, "batard, batarde")
Example #14
0
	def test_title_affect_defect(self):
		"""
		Test affect AND defect code are run
		"""

		self.t.on_affect = """
folk.loyalty = 80
folk.save()
"""
		self.t.on_defect = """
folk.loyalty = 20
folk.save()
"""
		self.t.save()

		f2 = Folk(
			first_name="Robb",
			last_name="Stark",
			kingdom=self.k
		)
		f2.save()

		# Sanity check
		self.assertEqual(self.f.loyalty, 0)
		self.assertEqual(f2.loyalty, 0)

		at = AvailableTitle(
			title=self.t,
			kingdom=self.k,
			folk=self.f
		)
		at.save()

		self.assertEqual(self.f.loyalty, 80)

		at.folk = f2
		at.save()

		self.assertEqual(self.f.loyalty, 20)
		self.assertEqual(f2.loyalty, 80)
Example #15
0
	def test_templates_and_title_context(self):
		"""
		Check templating works on event and EventAction with default context title.
		"""
		from title.models import Title, AvailableTitle
		t = Title(name="Maître espion", slug="maitre_espion", description=" ")
		t.save()
		f = Folk(first_name="septon", kingdom=self.k)
		f.save()
		at = AvailableTitle(kingdom=self.k, title=t, folk=f)
		at.save()

		self.e.text = "{{ title.maitre_espion.first_name }}"
		self.e.save()

		pe = PendingEvent(
			event=self.e,
			kingdom=self.k,
		)
		pe.save()

		self.assertEqual(pe.text, "septon")
Example #16
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.m = Message(
			kingdom=self.k,
			content="some content"
		)
		self.m.save()
Example #17
0
	def test_state_reverted_on_affectation_changed(self):
		"""
		PendingBargainKingdom states are reverted if an affectation is updated.
		"""
		pbsma = PendingBargainSharedMissionAffectation(
			pending_bargain_shared_mission=self.pbsm,
			mission_grid=self.mg,
			folk=self.f
		)
		pbsma.save()

		# Kingdom1 is OK.
		self.pbk1.state = PendingBargainKingdom.OK
		self.pbk1.save()

		# Deal breaker
		f2 = Folk(kingdom=self.k2)
		f2.save()

		pbsma.folk = f2
		pbsma.save()

		self.assertEqual(PendingBargainKingdom.PENDING, PendingBargainKingdom.objects.get(pk=self.pbk1.pk).state)
Example #18
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.qc = QualityCategory(
			name="Stub quality category",
			description="A stub."
		)
		self.qc.save()
Example #19
0
	def setUp(self):
		self.k1 = Kingdom()
		self.k1.save()

		self.k2 = Kingdom()
		self.k2.save()

		self.f = Folk(kingdom=self.k1)
		self.f.save()

		self.m = Mission(
			name="Stub mission",
			slug="stub",
			on_resolution="",
		)
		self.m.save()

		self.mg = MissionGrid(
			mission=self.m,
			allow_empty=True,
		)
		self.mg.save()

		self.pb = PendingBargain()
		self.pb.save()

		self.pbk1 = PendingBargainKingdom(
			pending_bargain=self.pb,
			kingdom=self.k1
		)
		self.pbk1.save()

		self.pbk2 = PendingBargainKingdom(
			pending_bargain=self.pb,
			kingdom=self.k2
		)
		self.pbk2.save()

		self.pm = PendingMission(
			kingdom=self.k1,
			mission=self.m
		)
		self.pm.save()

		self.pbsm = PendingBargainSharedMission(
			pending_mission=self.pm,
			pending_bargain=self.pb
		)
		self.pbsm.save()
Example #20
0
	def test_cant_affect_after_mission_start(self):
		"""
		A folk can't be affected to a mission after it started.
		"""

		# Start the pendingmission
		self.pm.started = datetime.now()
		self.pm.save()

		f2 = Folk(
			first_name="Hot",
			last_name="Pie",
			kingdom=self.k
		)
		f2.save()

		pma2 = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=self.mg,
			folk=f2
		)

		# Can't affect after start
		self.assertRaises(ValidationError, pma2.save)
Example #21
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.t = Title(
			name="Dummy title",
			slug="dummy_title",
			description="Nothing to say."
		)
		self.t.save()
Example #22
0
	def setUp(self):
		self.u = User(username="******")
		self.u.set_password("pwd")
		self.u.save()

		self.k = Kingdom(user=self.u)
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.t = Title(
			name="Stub title",
			description="My description.")
		self.t.save()

		self.at = AvailableTitle(
			title=self.t,
			kingdom=self.k,
			folk=self.f
		)
		self.at.save()

		self.m = Mission(
			name="Stub mission",
			slug="stub",
			on_resolution="",
			title=self.t,
		)
		self.m.save()

		self.mg = MissionGrid(
			mission=self.m,
			slug='stub_grid',
			allow_empty=True
		)
		self.mg.save()

		self.pm = PendingMission(
			mission=self.m,
			kingdom=self.k
		)
		self.pm.save()

		self.c = Client()
		self.c.login(username=self.u.username, password="******")
Example #23
0
	def test_sum_stats(self):
		"""
		Verify if sum is correct
		"""

		self.f2 = Folk(
			kingdom=self.k,
			fight=10,
			first_name="aa",
			last_name="bb"
		)
		self.f2.save()
		self.f.fight = 5
		self.f.save()

		self.assertEqual(15, sum_stats([self.f, self.f2], "fight"))
Example #24
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.t = Title(
			name="Stub title",
			description="My description.")
		self.t.save()

		self.at = AvailableTitle(
			title=self.t,
			kingdom=self.k,
			folk=self.f
		)
		self.at.save()

		self.m = Mission(
			name="Stub mission",
			slug="stub",
			on_resolution="",
			title=self.t,
		)
		self.m.save()

		self.mg = MissionGrid(
			mission=self.m,
			slug='stub_grid'
		)
		self.mg.save()

		self.pm = PendingMission(
			mission=self.m,
			kingdom=self.k
		)
		self.pm.save()

		self.pma = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=self.mg,
			folk=self.f
		)
		self.pma.save()
Example #25
0
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
			first_name="Robert",
			last_name="Baratheon"
		)
		self.f.save()

		self.t = Trigger(
			slug='Trigger_internal_test',
			name='Trigger_internal_test',
			prestige_threshold=10,
			population_threshold=10,
			money_threshold=10,
		)
		self.t.save()
Example #26
0
	def test_avg_stats(self):
		"""
		Verify if avg is correct
		"""

		self.f2 = Folk(
			kingdom=self.k,
			fight=10,
			first_name="aa",
			last_name="bb"
		)
		self.f2.save()
		self.f.fight = 6
		self.f.save()

		# Average code
		self.assertEqual(8, avg_stats([self.f, self.f2], "fight"))

		# Empty list
		self.assertEqual(0, avg_stats([], "fight"))
Example #27
0
	def test_templates_and_folks_list_templatetags(self):
		"""
		Check folks_list template_tags.
		"""
		f = Folk(first_name="septon", kingdom=self.k)
		f.save()
		f2 = Folk(first_name="cersei", kingdom=self.k)
		f2.save()

		self.e.text = "{{ folks|folks_list:'short' }}"
		self.e.save()

		pe = PendingEvent(
			event=self.e,
			kingdom=self.k,
			started=None
		)
		pe.save()
		pe.set_value("folks", [f, f2])

		pe.started = datetime.now()
		pe.save()

		self.assertEqual(pe.text, "septon et cersei")
Example #28
0
class ApiTest(TestCase):
	"""
	API tests for missions
	"""

	def setUp(self):
		self.u = User(username="******")
		self.u.set_password("pwd")
		self.u.save()

		self.k = Kingdom(user=self.u)
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.t = Title(
			name="Stub title",
			description="My description.")
		self.t.save()

		self.at = AvailableTitle(
			title=self.t,
			kingdom=self.k,
			folk=self.f
		)
		self.at.save()

		self.m = Mission(
			name="Stub mission",
			slug="stub",
			on_resolution="",
			title=self.t,
		)
		self.m.save()

		self.mg = MissionGrid(
			mission=self.m,
			slug='stub_grid',
			allow_empty=True
		)
		self.mg.save()

		self.pm = PendingMission(
			mission=self.m,
			kingdom=self.k
		)
		self.pm.save()

		self.c = Client()
		self.c.login(username=self.u.username, password="******")


	def test_grid_affect(self):
		"""
		A folk can be affected
		"""

		r = self.c.post(reverse('mission.views.pending_mission_grid_affect', args=(self.pm.pk, self.mg.pk)), {'folk': self.f.pk})
		self.assertEqual(200, r.status_code)
		self.assertEqual(PendingMissionAffectation.objects.all().count(), 1)

	def test_grid_defect(self):
		"""
		A folk can be defected
		"""
		pma = PendingMissionAffectation(
			pending_mission=self.pm,
			mission_grid=self.mg,
			folk=self.f
		)
		pma.save()

		r = self.c.post(reverse('mission.views.pending_mission_grid_defect', args=(pma.pk,)))
		self.assertEqual(200, r.status_code)
		self.assertEqual(PendingMissionAffectation.objects.all().count(), 0)

	def test_target(self):
		"""
		A target can be defined
		"""
		self.m.has_target = True
		self.m.save()

		k2 = Kingdom()
		k2.save()

		r = self.c.post(reverse('mission.views.pending_mission_set_target', args=(self.pm.pk,)), {'target': k2.pk})
		self.assertEqual(200, r.status_code)
		self.assertEqual(PendingMission.objects.get(pk=self.pm.pk).target, k2)


	def test_value(self):
		"""
		A value can be defined
		"""
		self.m.has_value = True
		self.m.save()

		r = self.c.post(reverse('mission.views.pending_mission_set_value', args=(self.pm.pk,)), {'value': 100})
		self.assertEqual(200, r.status_code)
		self.assertEqual(PendingMission.objects.get(pk=self.pm.pk).value, 100)

	def test_start(self):
		"""
		PendingMission can be started
		"""
		r = self.c.post(reverse('mission.views.pending_mission_start', args=(self.pm.pk,)))
		self.assertEqual(200, r.status_code)
		self.assertIsNotNone(PendingMission.objects.get(pk=self.pm.pk).started)

	def test_cancel(self):
		"""
		PendingMission can be cancelled
		"""
		r = self.c.post(reverse('mission.views.pending_mission_cancel', args=(self.pm.pk,)))
		self.assertEqual(200, r.status_code)
		self.assertRaises(PendingMission.DoesNotExist, lambda: PendingMission.objects.get(pk=self.pm.pk))

	def test_availablemission_start(self):
		"""
		AvailableMission can be started
		"""
		am = AvailableMission(
			mission=self.m,
			kingdom=self.k
		)
		am.save()

		r = self.c.post(reverse('mission.views.available_mission_start', args=(am.pk,)))
		self.assertEqual(200, r.status_code)
		self.assertEqual(PendingMission.objects.all().count(), 2)
Example #29
0
class UnitTest(TestCase):
	"""
	Unit tests for kingdom.
	"""
	
	def setUp(self):
		self.k = Kingdom()
		self.k.save()

		self.f = Folk(
			kingdom=self.k,
		)
		self.f.save()

		self.qc = QualityCategory(
			name="Stub quality category",
			description="A stub."
		)
		self.qc.save()

	def test_money_threshold(self):
		"""
		Money should be positive
		"""
		self.k.money = 20
		self.k.save()
		self.assertEqual(self.k.money, 20)

		self.k.money = -1
		self.k.save()
		self.assertEqual(self.k.money, 0)

	def test_prestige_threshold(self):
		"""
		Prestige should be positive
		"""
		self.k.prestige = 20
		self.k.save()
		self.assertEqual(self.k.prestige, 20)

		self.k.prestige = -1
		self.k.save()
		self.assertEqual(self.k.prestige, 0)

	def test_population_threshold(self):
		"""
		Population should be positive
		"""
		self.k.population = 20
		self.k.save()
		self.assertEqual(self.k.population, 20)

		self.k.population = -1
		self.k.save()
		self.assertEqual(self.k.population, 0)

	def test_death_after_birth(self):
		"""
		Should raise an ValidationError if death < birth
		"""
		self.f.death = datetime(year=2000, month=1, day=1)

		self.assertRaises(ValidationError, self.f.save)

	def test_folk_sex(self):
		"""
		Sex should be MALE or FEMALE
		"""
		self.f.sex = Folk.MALE
		self.f.save()

		self.f.sex = Folk.FEMALE
		self.f.save()

		self.f.sex = 't'
		self.assertRaises(ValidationError, self.f.save)

	def test_mother_sex(self):
		"""
		Mother should be a woman
		"""

		self.f.sex = Folk.FEMALE
		self.f.save()
		# Sanity check
		Folk(
			kingdom=self.k,
			mother=self.f,
			first_name="My mother is a female",
			last_name="---"
		).save()

		# Insanity check
		self.f.sex = Folk.MALE
		self.f.save()
		weirdos = Folk(
			kingdom=self.k,
			mother=self.f,
			first_name="My mother is a male",
			last_name="---"
		)

		self.assertRaises(ValidationError, weirdos.save)

	def test_father_sex(self):
		"""
		Father should be a male
		"""
		self.f.sex = Folk.MALE
		self.f.save()
		# Sanity check
		Folk(
			kingdom=self.k,
			father=self.f,
			first_name="My mother is a male",
			last_name="---"
		).save()

		# Insanity check
		self.f.sex = Folk.FEMALE
		self.f.save()
		weirdos = Folk(
			kingdom=self.k,
			father=self.f,
			first_name="My mother is a female",
			last_name="---"
		)

		self.assertRaises(ValidationError, weirdos.save)

	def test_fight_threshold(self):
		"""
		Fight should be restricted within [0, 20]
		"""
		self.f.fight = 21
		self.f.save()
		self.assertEqual(self.f.fight, 20)

		self.f.fight = -1
		self.f.save()
		self.assertEqual(self.f.fight, 1)

	def test_diplomacy_threshold(self):
		"""
		Diplomacy should be restricted within [0, 20]
		"""
		self.f.diplomacy = 21
		self.f.save()
		self.assertEqual(self.f.diplomacy, 20)

		self.f.diplomacy = -1
		self.f.save()
		self.assertEqual(self.f.diplomacy, 1)

	def test_plot_threshold(self):
		"""
		Plot should be restricted within [0, 20]
		"""
		self.f.plot = 21
		self.f.save()
		self.assertEqual(self.f.plot, 20)

		self.f.plot = -1
		self.f.save()
		self.assertEqual(self.f.plot, 1)

	def test_scholarship_threshold(self):
		"""
		Scholarship should be restricted within [0, 20]
		"""
		self.f.scholarship = 21
		self.f.save()
		self.assertEqual(self.f.scholarship, 20)

		self.f.scholarship = -1
		self.f.save()
		self.assertEqual(self.f.scholarship, 1)

	def test_loyalty_threshold(self):
		"""
		Loyalty should be restricted within [0, 20]
		"""
		self.f.loyalty = 101
		self.f.save()
		self.assertEqual(self.f.loyalty, 100)

		self.f.loyalty = -1
		self.f.save()
		self.assertEqual(self.f.loyalty, 0)

	def test_folk_deletion(self):
		"""
		Deleted people do not CASCADE on their family, only set to None.
		"""
		son = Folk(kingdom=self.k)
		son.father = self.f
		son.save()

		pupil = Folk(kingdom=self.k)
		pupil.mentor = self.f
		pupil.save()

		wife = Folk(kingdom=self.k)
		wife.spouse = self.f
		wife.save()

		# Sanity check
		self.assertEqual(4, Folk.objects.count())
		self.assertEqual(son.father, self.f)
		self.assertEqual(pupil.mentor, self.f)
		self.assertEqual(wife.spouse, self.f)

		self.f.delete()
		
		self.assertEqual(3, Folk.objects.count())
		self.assertIsNone(Folk.objects.get(pk=son.pk).father)
		self.assertIsNone(Folk.objects.get(pk=pupil.pk).mentor)
		self.assertIsNone(Folk.objects.get(pk=wife.pk).spouse)

	def test_claim_level(self):
		"""
		Claim level should be REACHABLE, CLAIM or VENDETTA.
		"""
		k2 = Kingdom()
		k2.save()

		c = Claim(offender=self.k, offended=k2)
		c.save()

		c.level = c.REACHABLE
		c.save()

		c.level = c.CLAIM
		c.save()

		c.level = c.VENDETTA
		c.save()

		c.level = 10
		self.assertRaises(ValidationError, c.save)

	def test_claim_unicity(self):
		"""
		You can't have two claims on the same kingdom.
		"""
		k2 = Kingdom()
		k2.save()

		Claim(
			offender=self.k,
			offended=k2
		).save()

		c = Claim(
			offender=self.k,
			offended=k2
		)
		self.assertRaises(IntegrityError, c.save)

	def test_incompatible_qualities(self):
		"""
		You can't have two incompatible qualities.
		"""
		
		q = Quality(
			category=self.qc,
			name="Avare",
			slug="avare",
			description="Jamais donner argent !")
		q.save()

		q2 = Quality(
			category=self.qc,
			name="Généreux",
			slug="genereux",
			description="Toujours donner argent !")
		q2.save()

		q.incompatible_qualities.add(q2)

		self.f.quality_set.add(q)

		self.assertRaises(ValidationError, (lambda: self.f.quality_set.add(q2)))

	def test_quality_on_affect(self):
		"""
		Test on affect code is executed.
		"""

		q = Quality(
			category=self.qc,
			name="Avare",
			slug="avare",
			description="Jamais donner argent !")
		q.on_affect = """
folk.kingdom.money = 15
folk.kingdom.save()
"""
		q.save()

		# Sanity check
		self.assertEqual(self.k.money, 0)
		
		self.f.quality_set.add(q)
		self.assertEqual(self.k.money, 15)

	def test_quality_on_defect(self):
		"""
		Test on_defect code is executed.
		"""

		q = Quality(
			category=self.qc,
			name="Avare",
			slug="avare",
			description="Jamais donner argent !")
		q.on_defect = """
folk.kingdom.money = 15
folk.kingdom.save()
"""
		q.save()

		self.f.quality_set.add(q)
		# Sanity check
		self.assertEqual(self.k.money, 0)

		self.f.quality_set.remove(q)
		self.assertEqual(self.k.money, 15)

	def test_quality_name_for(self):
		q = Quality(
			category=self.qc,
			name="male",
			female_name="female"
		)
		q.save()

		self.f.sex = Folk.MALE
		self.assertEqual("male", q.name_for(self.f))

		self.f.sex = Folk.FEMALE
		self.assertEqual("female", q.name_for(self.f))
Example #30
0
	def test_folk_deletion(self):
		"""
		Deleted people do not CASCADE on their family, only set to None.
		"""
		son = Folk(kingdom=self.k)
		son.father = self.f
		son.save()

		pupil = Folk(kingdom=self.k)
		pupil.mentor = self.f
		pupil.save()

		wife = Folk(kingdom=self.k)
		wife.spouse = self.f
		wife.save()

		# Sanity check
		self.assertEqual(4, Folk.objects.count())
		self.assertEqual(son.father, self.f)
		self.assertEqual(pupil.mentor, self.f)
		self.assertEqual(wife.spouse, self.f)

		self.f.delete()
		
		self.assertEqual(3, Folk.objects.count())
		self.assertIsNone(Folk.objects.get(pk=son.pk).father)
		self.assertIsNone(Folk.objects.get(pk=pupil.pk).mentor)
		self.assertIsNone(Folk.objects.get(pk=wife.pk).spouse)