def test_check_user(self): d = StubDataDriver() d.set_file_exists(True) d.set_text("a;a\nb;b\nc;c\n") p = Passwd(name="test.txt", driver=d) self.assertTrue(p.check_user("a", "a")) self.assertFalse(p.check_user("a", "b"))
def test_remove_existing_user_wrong_passwd(self): d = StubDataDriver() d.set_file_exists(True) d.set_text("a;a\nb;b\nc;c\n") p = Passwd(name="test.txt", driver=d) try: p.remove_user("b", "d") except RuntimeError: self.assertEqual(True, True) return self.assertEqual(True, False)
def test_wrong_data_structure(self): d = StubDataDriver() d.set_file_exists(True) d.set_text("xxx") try: Passwd(name="test.txt", driver=d) except RuntimeError: self.assertTrue(True) return self.assertTrue(False)
def test_remove_existing_user(self): d = StubDataDriver() d.set_file_exists(True) d.set_text("a;a\nb;b\nc;c\n") p = Passwd(name="test.txt", driver=d) p.remove_user("b", "b") p.commit() self.assertEqual(d.get_text(), "a;a\nc;c\n")
def test_add_new_user(self): d = StubDataDriver() d.set_file_exists(False) p = Passwd(name="test.txt", driver=d) p.add_user("admin", "admin") p.commit() self.assertEqual(d.get_text(), "admin;admin\n")
class ServerHandler(ServerRepository): def __init__(self, config): self.socket = {} self.rs = RawServer(Event(), 100, 1000) self.nh = NetworkHandler(self) self.shutdown = Event() self.config = config self.post_commit = [] for pattern, action in self.config.items('post-commit'): try: self.post_commit.append((re.compile(pattern, re.I), action)) except re.error, msg: raise ServerError, 'Bad post-commit pattern \"%s\": %s' % \ (pattern, msg) pw_file = path.join(config.get('control', 'datadir'), 'passwd') self.passwd = Passwd(pw_file)