 			create schema users;
 			return next 'Created users schema';
 		end if;
+		
+		if failed_test('test_users_table_testusers_exists') then 
+			create table users.test_user();
+			return next 'Created the test users table.';
+		end if;
+		if failed_test('test_users_table_testusers_column_name_exists') then
+			alter table users.test_user
+				add column name text;
+			return next 'Added the user name column to test users.';
+		end if;
+		if failed_test('test_users_table_testuser_column_name_is_text') then
+			alter table users.test_user
+				alter column name type text;
+			return next 'Altered test user name to text.';
+		end if;  
+		if failed_test('test_users_table_testuser_column_name_is_pk') then
+			alter table users.test_user
+				add primary key (name);
+			return next 'Added the primary key to test users.';
+		end if;  
+		
+		if failed_test('test_users_table_testgroup_exists') then 
+			create table users.test_group();
+			return next 'Created the test group table.';
+		end if;
+		if failed_test('test_users_table_testgroup_column_name_exists') then
+			alter table users.test_group
+				add column name text;
+			return next 'Added the user name column to test group.';
+		end if;
+		if failed_test('test_users_table_testgroup_column_name_is_text') then
+			alter table users.test_group
+				alter column name type text;
+			return next 'Altered test group name to text.';
+		end if;  
+		if failed_test('test_users_table_testgroup_column_name_is_pk') then
+			alter table users.test_group
+				add primary key (name);
+			return next 'Added the primary key to test group.';
+		end if;  
 		
 		if failed_test('test_users_user_exists') then
 			create table users.user();

create or replace function test_users_function_validate_activates_user()
returns setof text as $test$
	declare
		holder		uuid;
	begin
		select add_user into holder from
			users.add_user('web-session-1', 'test-user', 'password',
				'tester@test.com');
		perform users.validate_user('web-session-1', holder);
		return next results_eq(
			$$select active from users.user 
				where name = 'test-user'$$,
			array[true],
			'Validate user should make the user active.');
		return next is_empty(
			$$select * from users.validate, users.user
				where users.user.id = users.validate.user_id
				and users.user.name = 'test-user'$$,
			'Validate needs to delete the validation link.');
	end;
$test$ language plpgsql;


create or replace function test_users_function_addgroup_inserts_data()
returns setof text as $test$
	declare 
		newgrpcur		cursor for select users.test_group.name
							from users.test_group
							left outer join users.group on 
								(lower(users.test_group.name) = 
								users.group.name)
							where users.group.id is null;
		newgroup		text;
	begin 
		open newgrpcur;
		fetch from newgrpcur into newgroup;
		perform users.add_group('web-session-1', newgroup);
		return next results_eq( 
			$$select name from users.group
				where name = '$$ || newgroup || $$'$$,
			$$values ('$$ || newgroup || $$')$$,
			'Users add group needs to add data.');
	end;
$test$ language plpgsql;
