コード例 #1
0
 def test_pwhash(self):
     pw, salt = MudAccounts._pwhash("secret")
     pw2, salt2 = MudAccounts._pwhash("secret")
     self.assertNotEqual(pw, pw2)
     self.assertNotEqual(salt, salt2)
     pw, salt = MudAccounts._pwhash("secret", "some salt")
     pw2, salt2 = MudAccounts._pwhash("secret", "some salt")
     self.assertEqual(pw, pw2)
     self.assertEqual(salt, salt2)
コード例 #2
0
 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()
コード例 #3
0
 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()
コード例 #4
0
 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()
コード例 #5
0
 def test_accountcreate_fail(self):
     stats = Stats()  # uninitialized stats
     accounts = MudAccounts(":memory:")
     with self.assertRaises(ValueError):
         accounts.create("testname", "s3cr3t", "test@invalid", stats,
                         {"wizard"})
コード例 #6
0
 def test_accept_password(self):
     pw = "hello3"
     self.assertEqual(pw, MudAccounts.accept_password(pw))
     pw = "hello this is a long pass pharse 12345"
     self.assertEqual(pw, MudAccounts.accept_password(pw))
     pw = "he44zzz"
     self.assertEqual(pw, MudAccounts.accept_password(pw))
     pw = "   test  2  "
     self.assertEqual(pw, MudAccounts.accept_password(pw))
     with self.assertRaises(ValueError):
         MudAccounts.accept_password("")
     with self.assertRaises(ValueError):
         MudAccounts.accept_password("shrt2")
     with self.assertRaises(ValueError):
         MudAccounts.accept_password("no digits")
     with self.assertRaises(ValueError):
         MudAccounts.accept_password("223242455")
コード例 #7
0
 def test_accept_email(self):
     self.assertEqual("x@y", MudAccounts.accept_email("x@y"))
     self.assertEqual("*****@*****.**",
                      MudAccounts.accept_email("*****@*****.**"))
     with self.assertRaises(ValueError):
         MudAccounts.accept_email("@")
     with self.assertRaises(ValueError):
         MudAccounts.accept_email("test@")
     with self.assertRaises(ValueError):
         MudAccounts.accept_email("@test.com")
     with self.assertRaises(ValueError):
         MudAccounts.accept_email(" x@y")
     with self.assertRaises(ValueError):
         MudAccounts.accept_email("x@y ")
コード例 #8
0
 def test_accept_name(self):
     self.assertEqual("irm", MudAccounts.accept_name("irm"))
     self.assertEqual("irmendejongyeahz",
                      MudAccounts.accept_name("irmendejongyeahz"))
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("irmendejongyeahxy")  # too long
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("aa")  # too short
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("Irmen")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("irmen de jong")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("irmen_de_jong")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("irmen444")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name(" irmen")
     with self.assertRaises(ValueError):
         MudAccounts.accept_name("irmen ")