def create_user(request): """ Create a user in the database. """ #FIXME - the UUID for a user should be the e-mail address. Can we make this explicit? newname = server.create_user(request.POST['type'], request.POST['handle'], request.POST['name'], request.matchdict['name']) return newname
def setUp(self): """Launch pserve using webtest with test settings""" self.appconf = get_app(test_ini) self.app = TestApp(self.appconf) #For speed, allow cookie setting. # self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[])) # This sets global var "engine" - in the case of SQLite this is a fresh RAM # DB each time. If we only did this on class instantiation the database would # be dirty and one test could influence another. # TODO - add a test that tests this. server.choose_engine("SQLite") # Punch in new administrator account with direct server call # This will implicitly generate the tables. user_id = server.create_user("administrators", "administrator", "administrator", "administrator") #server.touch_to_add_user_group("administrator", "administrators") server.touch_to_add_password(user_id, "adminpass") self.app.authorization = ('Basic', ('administrator', 'adminpass')) # This sorts out the auth token cookie. self.app.get('/users') self.app.authorization = None
def create_user(request): """ Create a user in the database. """ # FIXME - the UUID for a user should be the e-mail address. Can we make this explicit? newname = server.create_user( request.POST["type"], request.POST["handle"], request.POST["name"], request.matchdict["name"] ) return newname
def test_subtract(self): """ Behaviour: Calling the API to add credit should result credit being subtracted from the database. """ user = create_user('user', 'testuser3', 'testuser3', 'testuser3') touch_to_add_credit(user,-500) credit = check_credit(user) self.assertEqual(credit, -500)
def test_add(self): """ Behaviour: Calling the API to add credit should result credit being added to the database. """ user = create_user('user','testuser2','testuser2','testuser2') touch_to_add_credit(user,1000) credit = check_credit(user) self.assertEqual(credit, 1000)
def setUp(self): """Launch pserve using webtest with test settings""" self.appconf = get_app(test_ini) self.app = TestApp(self.appconf) # Punch in new administrator account with direct server call server.choose_engine("SQLite") # Sets global var "engine" - in the # case of SQLite this is a fresh RAM # DB each time. # Create new user. This will implicitly generate the tables. id1 = server.create_user(None, "testuser", "testuser", "testuser") server.touch_to_add_user_group("testuser", "users") server.touch_to_add_password(id1, "testpass") id2 = server.create_user(None, "administrator", "administrator", "administrator") server.touch_to_add_user_group("administrator", "administrators") server.touch_to_add_password(id2, "adminpass")
def test_ownership(self): artifact_id = self.my_create_appliance("owned") artifact2_id = self.my_create_appliance("unowned") owner_id = s.create_user("users", "*****@*****.**", "foo foo", "foo") s.touch_to_add_ownership(artifact_id, owner_id) # Test that the user really owns the server. self.assertTrue(s.check_ownership(artifact_id, owner_id)) # Test that the user does not own the second server. self.assertFalse(s.check_ownership(artifact2_id, owner_id))
def test_servers_badpass(self): """Likewise if I give a valid user name but no password """ user_id = server.create_user("administrators", "administrator", "administrator", "administrator") #server.touch_to_add_user_group("administrator", "administrators") server.touch_to_add_password(user_id, "adminpass") app = self.testapp app.authorization = ('Basic', ('administrator', 'badpassword')) response = app.get('/servers', status=401) self.assertEqual(response.headers.get('WWW-Authenticate', 'empty'), 'Basic realm="eos_db"')
def setUp(self): """Launch pserve using webtest with test settings""" #Nope, do this for each test... #self.appconf = get_app(test_ini) #self.app = TestApp(self.appconf) server.choose_engine("SQLite") # Sets global var "engine" - in the # case of SQLite this is a fresh RAM # DB each time. # Create new user. For not much reason. user_id = server.create_user("users", "testuser", "testuser", "testuser") server.touch_to_add_credit(user_id, 200)
def test_ownership_2(self): """I had a version of the portal that passed the above test but when you added a VM to any user all the users started to see it. Not good! """ owners = [] artifacts = [] for idx in (0,1,2): owners.append(s.create_user("users", "*****@*****.**" % idx , "foo %s" % idx, "foo%s" % idx)) artifacts.append(self.my_create_appliance("box%s" % idx)) s.touch_to_add_ownership(artifacts[idx], owners[0]) s.touch_to_add_ownership(artifacts[idx], owners[idx]) #All VMs owned by last owner set self.assertTrue( s.check_ownership(artifacts[0], owners[0]) and s.check_ownership(artifacts[1], owners[1]) and s.check_ownership(artifacts[2], owners[2]) ) #All VMs also owned by 0 self.assertTrue( s.check_ownership(artifacts[1], owners[0]) and s.check_ownership(artifacts[2], owners[0]) ) #VMs not owned by other owners self.assertFalse(s.check_ownership(artifacts[0], owners[1]) or s.check_ownership(artifacts[2], owners[1]) or s.check_ownership(artifacts[0], owners[2]) or s.check_ownership(artifacts[1], owners[2]) ) #This is reflected in list_artifacts_for_user? self.assertEqual(len(s.list_artifacts_for_user(owners[0])), 3) self.assertEqual(len(s.list_artifacts_for_user(owners[1])), 1) self.assertEqual(len(s.list_artifacts_for_user(owners[2])), 1) #Likewise requesting an artifact I don't own should give an error, #but that has to be tested via webtest. # Finally, adding a new box2 should Nix the old box2 self.my_create_appliance("box2") self.assertEqual(len(s.list_artifacts_for_user(owners[0])), 2) self.assertEqual(len(s.list_artifacts_for_user(owners[1])), 1) self.assertEqual(len(s.list_artifacts_for_user(owners[2])), 0)
def create_user(name): #Since we are not logged in as the administrator, do this directly return server.create_user("users", name + "@example.com", name + " " + name, name)
def create_user(self, name): #Since we are not logged in as the administrator, do this directly return server.create_user("users", name + "@example.com", name + " " + name, name)
def test_create_user(self): """ Add a user. """ user = create_user('user','testuser','testuser','testuser') self.assertEqual(check_actor_id(user), user)