def test_ban(self): dbfile = pathlib.Path( tempfile.gettempdir()) / "tale_test_accdb_{0:f}.sqlite".format( time.time()) actor = Living("normal", gender="f") wizard = Living("wizz", gender="f") wizard.privileges.add("wizard") try: accounts = MudAccounts(str(dbfile)) stats = Stats.from_race("elf", gender='f') accounts.create("testname", "s3cr3t", "test@invalid", stats, {"wizard"}) account = accounts.get("testname") self.assertFalse(account.banned) with self.assertRaises(ActionRefused): accounts.ban("testname", actor) with self.assertRaises(LookupError): accounts.ban("zerp", wizard) accounts.ban("testname", wizard) account = accounts.get("testname") self.assertTrue(account.banned) with self.assertRaises(LookupError): accounts.unban("zerp", wizard) accounts.unban("testname", wizard) account = accounts.get("testname") self.assertFalse(account.banned) finally: dbfile.unlink()
def test_playernaming(self): n = PlayerNaming() n.gender = "m" n.name = "RINZWIND" n.description = "a wizard" n.money = 999 n.stats = Stats.from_race("elemental") n.title = "grand master" self.assertEqual("rinzwind", n.name) p = Player("dummy", "f") p.privileges.add("wiz") n.apply_to(p) self.assertEqual("rinzwind", p.name) self.assertEqual("m", p.gender) self.assertEqual({"wiz"}, p.privileges) self.assertEqual("a wizard", p.description) self.assertEqual(999, p.money) self.assertEqual("elemental", p.stats.race) self.assertEqual(races.B_NEBULOUS, p.stats.bodytype) self.assertEqual("grand master", p.title)
def test_storydata(self): dbfile = pathlib.Path( tempfile.gettempdir()) / "tale_test_accdb_{0:f}.sqlite".format( time.time()) try: accounts = MudAccounts(str(dbfile)) stats = Stats.from_race("elf", gender='f') accounts.create("testname", "s3cr3t", "test@invalid", stats, {"wizard"}) account = accounts.get("testname") self.assertEqual({}, account.story_data) account.story_data = {"test": 42, "thing": [1.2, 3.4]} with self.assertRaises(TypeError): accounts.save_story_data("testname", "must_be_dictionary") accounts.save_story_data("testname", account.story_data) account = accounts.get("testname") self.assertEqual({ "test": 42, "thing": [1.2, 3.4] }, account.story_data) finally: dbfile.unlink()
def test_dbcreate(self): dbfile = pathlib.Path( tempfile.gettempdir()) / "tale_test_accdb_{0:f}.sqlite".format( time.time()) try: accounts = MudAccounts(str(dbfile)) stats = Stats.from_race("elf", gender='f') account = accounts.create("testname", "s3cr3t", "test@invalid", stats, {"wizard"}) self.assertEqual(60.0, account.stats.weight) accs = list(accounts.all_accounts()) self.assertEqual(1, len(accs)) account = accs[0] self.assertEqual("testname", account.name) self.assertEqual({"wizard"}, account.privileges) self.assertEqual({}, account.story_data) self.assertEqual("f", account.stats.gender) self.assertEqual(races.BodyType.HUMANOID, account.stats.bodytype) self.assertEqual(60.0, account.stats.weight) self.assertEqual(races.BodySize.HUMAN_SIZED, account.stats.size) self.assertEqual("Edhellen", account.stats.language) finally: dbfile.unlink()
def test_accountcreate_fail(self): stats = Stats() # uninitialized stats accounts = MudAccounts(":memory:") with self.assertRaises(ValueError): accounts.create("testname", "s3cr3t", "test@invalid", stats, {"wizard"})