add fixture to tests

This commit is contained in:
2019-08-03 17:14:24 +02:00
parent 7c3028eca2
commit e31282e24e
16 changed files with 199 additions and 143 deletions

View File

@@ -4,14 +4,15 @@ import java.util.*
class Article(
id: UUID?,
var versionId: UUID?,
var versionNumber: Int?,
id: UUID = UUID.randomUUID(),
var versionId: UUID = UUID.randomUUID(),
var versionNumber: Int? = null,
var title: String?,
var annonymous: Boolean?,
var annonymous: Boolean? = true,
var content: String?,
var description: String?,
var tags: List<String>
var tags: List<String> = emptyList(),
override var createdBy: Citizen?
):
UuidEntity(id),
EntityCreatedAt by EntityCreatedAtImp(),

View File

@@ -0,0 +1,10 @@
package fr.dcproject.utils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
internal class LoggerDelegate<in R: Any>: ReadOnlyProperty<R, Logger> {
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
}

View File

@@ -2,14 +2,16 @@ do
$$
declare
_password text := crypt('azerty', gen_salt('bf', 8));
multiple int = coalesce(current_setting('fixture.quantity.multiple', true), '50')::int;
begin
delete from "user";
insert into "user" (username, password, blocked_at)
insert into "user" (id, username, password, blocked_at)
select
'username' || s,
uuid_in(md5('user'||rn::text)::cstring),
'username' || rn,
_password,
case when s % 10 = 0 then now() else null end
from generate_series(1, 1000) s;
case when rn % 10 = 0 then now() else null end
from generate_series(1, multiple) rn;
raise notice 'user fixtures done';
end;

View File

@@ -2,8 +2,9 @@ do
$$
begin
delete from citizen;
insert into citizen (name, birthday, user_id, vote_annonymous, follow_annonymous)
insert into citizen (id, name, birthday, user_id, vote_annonymous, follow_annonymous)
select
uuid_in(md5('citizen'||row_number() over ()::text)::cstring),
jsonb_build_object(
'first_name', 'first name' || row_number() over (),
'last_name', 'LAST NAME' || row_number() over (),

View File

@@ -1,11 +1,14 @@
do
$$
declare
citizen_count int = (select count(*) from citizen);
begin
delete from citizen_in_workgroup;
delete from workgroup;
insert into workgroup (created_by_id, name, description, annonymous, owner_id)
insert into workgroup (id, created_by_id, name, description, annonymous, owner_id)
select
uuid_in(md5('workgroup'||rn::text)::cstring),
z.id,
'name' || rn,
'description' || rn,
@@ -17,7 +20,7 @@ begin
select
z.id,
w.id
from (select *, row_number() over ()+5 % 1000 rn from citizen) z
from (select *, row_number() over ()+5 % citizen_count rn from citizen) z
join (select *, row_number() over () rn from workgroup) w using (rn);
raise notice 'workgroup fixtures done';

View File

@@ -12,9 +12,10 @@ begin
delete from article_relations;
delete from article;
insert into article (version_id, created_by_id, title, annonymous, content, description, tags)
insert into article (id, version_id, created_by_id, title, annonymous, content, description, tags)
select
uuid_generate_v4(),
uuid_in(md5('article'||row_number() over ())::cstring),
uuid_in(md5('article_v'||row_number() over ())::cstring),
z.id,
'title' || row_number() over (),
row_number() over () % 3 = 0,

View File

@@ -1,5 +1,7 @@
do
$$
declare
article_count int = (select count(*) from article);
begin
delete from article_in_title;
delete from title;
@@ -29,7 +31,7 @@ begin
ti.id,
a.id,
ti.constitution_id
from (select *, (row_number() over () % 1005) rn from title, lateral generate_series(1, 3) g) ti
from (select *, (row_number() over () % (article_count+7)) rn from title, lateral generate_series(1, 3) g) ti
join (select *, row_number() over () rn from article) a using (rn);
raise notice 'constitution fixtures done';

View File

@@ -1,27 +1,32 @@
do
$$
declare
article_count int = (select count(*) from article);
begin
delete from follow;
insert into follow_article (citizen_id, target_id)
insert into follow_article (id, citizen_id, target_id)
select
uuid_in(md5('follow_article'||row_number() over ())::cstring),
z.id,
a.id
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5)) z
join (select *, row_number() over () rn from article) a using (rn);
insert into follow_constitution (citizen_id, target_id)
insert into follow_constitution (id, citizen_id, target_id)
select
uuid_in(md5('follow_constitution'||row_number() over ())::cstring),
z.id,
a.id
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5)) z
join (select *, row_number() over () rn from constitution) a using (rn);
insert into follow_citizen (citizen_id, target_id)
insert into follow_citizen (id, citizen_id, target_id)
select
uuid_in(md5('follow_citizen'||row_number() over ())::cstring),
z.id,
a.id
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5)) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5)) z
join (select *, row_number() over () rn from citizen) a using (rn);
raise notice 'follow fixtures done';

View File

@@ -1,40 +1,46 @@
do
$$
declare
article_count int = (select count(*) from article);
begin
delete from comment;
insert into comment_on_article (citizen_id, target_id, content)
insert into comment_on_article (id, citizen_id, target_id, content)
select
uuid_in(md5('comment_on_article'||row_number() over ())::cstring),
z.id,
a.id,
'content' || (row_number() over () * g)
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from article) a using (rn);
insert into comment_on_article (citizen_id, target_id, content, parent_id)
insert into comment_on_article (id, citizen_id, target_id, content, parent_id)
select
uuid_in(md5('comment_on_article_2'||row_number() over ())::cstring),
z.id,
a.target_id,
'content' || row_number() over () * g,
a.id
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from comment_on_article) a using (rn);
insert into comment_on_article (citizen_id, target_id, content, parent_id)
insert into comment_on_article (id, citizen_id, target_id, content, parent_id)
select
uuid_in(md5('comment_on_article_3'||row_number() over ())::cstring),
z.id,
a.target_id,
'content' || row_number() over () * g,
a.id
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from comment_on_article where parent_id is not null) a using (rn);
insert into comment_on_constitution (citizen_id, target_id, content)
insert into comment_on_constitution (id, citizen_id, target_id, content)
select
uuid_in(md5('comment_on_constitution'||row_number() over ())::cstring),
z.id,
a.id,
'content' || row_number() over () * g
from (select *, row_number() over () % 995 rn from citizen, lateral generate_series(1, 5) g) z
from (select *, row_number() over () % (article_count+7) rn from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from constitution) a using (rn);
raise notice 'comment fixtures done';

View File

@@ -1,45 +1,51 @@
do
$$
declare
article_count int = (select count(*) from article);
begin
delete from vote_for_article;
delete from vote_for_constitution;
delete from vote_for_comment_on_article;
delete from vote_for_comment_on_constitution;
insert into vote_for_article (citizen_id, target_id, note, anonymous)
raise notice '%', article_count;
insert into vote_for_article (id, citizen_id, target_id, note, anonymous)
select
uuid_in(md5('vote_for_article'||row_number() over ())::cstring),
z.id,
a.id,
(row_number() over () % 3) -1,
(row_number() over () % 3 = 1)
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 10) g) z
from (select *, row_number() over ()+g % (article_count+7) rn, g from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from article) a using (rn);
insert into vote_for_constitution (citizen_id, target_id, note, anonymous)
insert into vote_for_constitution (id, citizen_id, target_id, note, anonymous)
select
uuid_in(md5('vote_for_constitution'||row_number() over ())::cstring),
z.id,
a.id,
(row_number() over () % 3) -1,
(row_number() over () % 3 = 1)
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 5) g) z
from (select *, row_number() over () % (article_count+7) rn, g from citizen, lateral generate_series(1, 5) g) z
join (select *, row_number() over () rn from constitution) a using (rn);
insert into vote_for_comment_on_article (citizen_id, target_id, note, anonymous)
insert into vote_for_comment_on_article (id, citizen_id, target_id, note, anonymous)
select
uuid_in(md5('vote_for_comment_on_article'||row_number() over ())::cstring),
z.id,
a.id,
(row_number() over () % 3) -1,
(row_number() over () % 3 = 1)
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 3) g) z
from (select *, row_number() over () % (article_count+7) rn, g from citizen, lateral generate_series(1, 3) g) z
join (select *, row_number() over () rn from comment_on_article) a using (rn);
insert into vote_for_comment_on_constitution (citizen_id, target_id, note, anonymous)
insert into vote_for_comment_on_constitution (id, citizen_id, target_id, note, anonymous)
select
uuid_in(md5('vote_for_comment_on_constitution'||row_number() over ())::cstring),
z.id,
a.id,
(row_number() over () % 3) -1,
(row_number() over () % 3 = 1)
from (select *, row_number() over () % 995 rn, g from citizen, lateral generate_series(1, 2) g) z
from (select *, row_number() over () % (article_count+7) rn, g from citizen, lateral generate_series(1, 2) g) z
join (select *, row_number() over () rn from comment_on_constitution) a using (rn);
raise notice 'vote fixtures done';

View File

@@ -39,4 +39,3 @@ drop table if exists citizen_in_workgroup;
drop table if exists workgroup;
drop table if exists citizen;
drop table if exists "user";
drop type if exists public."name";