]> khamidou — GitHub mirrors - kite.git/commitdiff
user management functions
authorkarim hamidou <khamidou@gmail.com>
Fri, 8 Nov 2013 07:41:53 +0000 (08:41 +0100)
committerkarim hamidou <khamidou@gmail.com>
Fri, 8 Nov 2013 07:41:53 +0000 (08:41 +0100)
src/back/kite/users.py [new file with mode: 0644]
src/back/tests/test_users.py [new file with mode: 0644]

diff --git a/src/back/kite/users.py b/src/back/kite/users.py
new file mode 100644 (file)
index 0000000..f87acbb
--- /dev/null
@@ -0,0 +1,15 @@
+# users.py - user management functions + commandline tool
+import os
+
+class UserError(Exception):
+    pass
+
+
+def create_user(name, _base_folder=os.path.expanduser("~")):
+    """Create the basic structure for an user. Note: _base_folder is only used for testing"""
+    try:
+        os.mkdir(os.path.join(_base_folder, name))
+    except OSError:
+        raise UserError("Folder %s already exists" % name)
+    
+    
diff --git a/src/back/tests/test_users.py b/src/back/tests/test_users.py
new file mode 100644 (file)
index 0000000..0ac188e
--- /dev/null
@@ -0,0 +1,18 @@
+import os
+import unittest
+import tempfile
+import fcntl
+import kite.users
+
+class TestLockfile(unittest.TestCase):
+    def test_creation(self):
+        tmpdir = tempfile.mkdtemp()
+        kite.users.create_user("charles", _base_folder=tmpdir)
+        self.assertTrue(os.path.exists(os.path.join(tmpdir, "charles")))
+
+        try:
+            # Creating the file twice raises an error
+            kite.users.create_user("charles", _base_folder=tmpdir)
+            assert False, "Exception should have been raised"
+        except kite.users.UserError:
+            pass