 
 create or replace function test_users_function_deleteuser_removes_data()
 returns setof text as $test$
-	begin 
-		perform users.add_user('web-session-1', 'test-user',
-			'password', 'tester@test.com');
-		perform users.delete_user('web-session-1', 'test-user');
+	declare 
+		activeusercur		cursor for select users.test_user.name
+							from users.test_user
+							left outer join users.user on 
+								(lower(users.test_user.name) = 
+								users.user.name)
+							where users.user.active = true;
+		activeuser		text;
+	begin 
+		open activeusercur;
+		fetch from activeusercur into activeuser;
+		perform users.delete_user('web-session-1', activeuser);
 		return next is_empty(
 			$$select * from users.user 
-				where name = 'test-user'$$,
+				where name = '$$ || activeuser || $$'$$,
 			'Delete user should remove the user.');
 	end;
 $test$ language plpgsql;
 
 create or replace function test_users_function_deleteuser_not_case_sensitive()
 returns setof text as $test$
-	begin 
-		perform users.add_user('web-session-1', 'test-user',
-			'password', 'tester@test.com');
-		perform users.delete_user('web-session-1', 'TEST-USER');
+	declare 
+		activeusercur		cursor for select users.test_user.name
+							from users.test_user
+							left outer join users.user on 
+								(lower(users.test_user.name) = 
+								users.user.name)
+							where users.user.active = true;
+		activeuser		text;
+	begin 
+		open activeusercur;
+		fetch from activeusercur into activeuser;
+		perform users.delete_user('web-session-1', upper(activeuser));
 		return next is_empty(
 			$$select * from users.user 
-				where name = 'test-user'$$,
+				where name = '$$ || activeuser || $$'$$,
 			'Delete user should remove the user.');
 	end;
 $test$ language plpgsql;

			'Login needs to throw an error on failure.');
	end;
$test$ language plpgsql;

create or replace function test_users_function_login_username_only_active()
returns setof text as $test$

create or replace function test_users_function_add_user_inserts_data()
returns setof text as $test$
	declare
		newusercur		cursor for select users.test_user.name
							from users.test_user
							left outer join users.user on 
								(lower(users.test_user.name) = 
								users.user.name)
							where users.user.active is null;
		user1			text;
		holder			text;
	begin
		open newusercur;
		fetch from newusercur into user1;
		select add_user into holder from
			users.add_user('web-session-1', user1, 'password',
				user1);
		return next results_eq(
			$$select active, name, email from users.user 
				where name = '$$ || user1 || $$'$$,
			$$values (false, '$$ || user1 || $$', 
				'$$ || user1 || $$')$$,
			'add_user needs to add the user to users.user.');
		return next results_ne(
			$$select password from users.user
				where name = '$$ || user1 || $$'$$,
			$$values ('password')$$,
			'User''s password needs to be encrypted.');
		return next results_eq(
			$$select cast(users.validate.link as text)
				from users.validate, users.user
				where users.user.id = users.validate.user_id
					and users.user.name = '$$ || user1 || $$'$$,
			array[holder],
			'User add must output the validation link');
	end;
