Refactor User and DB handling (#123)
fix copyright date Add more user tests More user tests More user tests Start refactoring user tests Docs Fix lint Fix db fixtures init in tests Fix models test Fix loading fixtures Fix ineffasign Fix lint Fix integration tests Fix init of test engine creation Fix user related tests Better handling of creating test enging Moved all fixtures to db package Moved all fixtures to db package Moved user related stuff to seperate package Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/123
This commit is contained in:
28
pkg/db/db.go
28
pkg/db/db.go
@ -23,7 +23,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -85,33 +84,6 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// CreateTestEngine creates an instance of the db engine which lives in memory
|
||||
func CreateTestEngine() (engine *xorm.Engine, err error) {
|
||||
|
||||
if x != nil {
|
||||
return x, nil
|
||||
}
|
||||
|
||||
if os.Getenv("VIKUNJA_TESTS_USE_CONFIG") == "1" {
|
||||
config.InitConfig()
|
||||
engine, err = CreateDBEngine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
engine, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
engine.SetMapper(core.GonicMapper{})
|
||||
engine.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1")
|
||||
engine.SetLogger(xorm.NewSimpleLogger(log.GetLogWriter("database")))
|
||||
x = engine
|
||||
return
|
||||
}
|
||||
|
||||
// RegisterTableStructsForCache registers tables in gob encoding for redis cache
|
||||
func RegisterTableStructsForCache(val interface{}) {
|
||||
gob.Register(val)
|
||||
|
5
pkg/db/fixtures/files.yml
Normal file
5
pkg/db/fixtures/files.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- id: 1
|
||||
name: test
|
||||
size: 100
|
||||
created_unix: 1570998791
|
||||
created_by_id: 1
|
8
pkg/db/fixtures/label_task.yml
Normal file
8
pkg/db/fixtures/label_task.yml
Normal file
@ -0,0 +1,8 @@
|
||||
- id: 1
|
||||
task_id: 1
|
||||
label_id: 4
|
||||
created: 0
|
||||
- id: 2
|
||||
task_id: 2
|
||||
label_id: 4
|
||||
created: 0
|
20
pkg/db/fixtures/labels.yml
Normal file
20
pkg/db/fixtures/labels.yml
Normal file
@ -0,0 +1,20 @@
|
||||
- id: 1
|
||||
title: 'Label #1'
|
||||
created_by_id: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 2
|
||||
title: 'Label #2'
|
||||
created_by_id: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 3
|
||||
title: 'Label #3 - other user'
|
||||
created_by_id: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 4
|
||||
title: 'Label #4 - visible via other task'
|
||||
created_by_id: 2
|
||||
updated: 0
|
||||
created: 0
|
24
pkg/db/fixtures/link_sharing.yml
Normal file
24
pkg/db/fixtures/link_sharing.yml
Normal file
@ -0,0 +1,24 @@
|
||||
- id: 1
|
||||
hash: test
|
||||
list_id: 1
|
||||
right: 0
|
||||
sharing_type: 1
|
||||
shared_by_id: 1
|
||||
created: 0
|
||||
updated: 0
|
||||
- id: 2
|
||||
hash: test2
|
||||
list_id: 2
|
||||
right: 1
|
||||
sharing_type: 1
|
||||
shared_by_id: 1
|
||||
created: 0
|
||||
updated: 0
|
||||
- id: 3
|
||||
hash: test3
|
||||
list_id: 3
|
||||
right: 2
|
||||
sharing_type: 1
|
||||
shared_by_id: 1
|
||||
created: 0
|
||||
updated: 0
|
182
pkg/db/fixtures/list.yml
Normal file
182
pkg/db/fixtures/list.yml
Normal file
@ -0,0 +1,182 @@
|
||||
-
|
||||
id: 1
|
||||
title: Test1
|
||||
description: Lorem Ipsum
|
||||
identifier: test1
|
||||
owner_id: 1
|
||||
namespace_id: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 2
|
||||
title: Test2
|
||||
description: Lorem Ipsum
|
||||
identifier: test2
|
||||
owner_id: 3
|
||||
namespace_id: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 3
|
||||
title: Test3
|
||||
description: Lorem Ipsum
|
||||
identifier: test3
|
||||
owner_id: 3
|
||||
namespace_id: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 4
|
||||
title: Test4
|
||||
description: Lorem Ipsum
|
||||
identifier: test4
|
||||
owner_id: 3
|
||||
namespace_id: 3
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 5
|
||||
title: Test5
|
||||
description: Lorem Ipsum
|
||||
identifier: test5
|
||||
owner_id: 5
|
||||
namespace_id: 5
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 6
|
||||
title: Test6
|
||||
description: Lorem Ipsum
|
||||
identifier: test6
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 7
|
||||
title: Test7
|
||||
description: Lorem Ipsum
|
||||
identifier: test7
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 8
|
||||
title: Test8
|
||||
description: Lorem Ipsum
|
||||
identifier: test8
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 9
|
||||
title: Test9
|
||||
description: Lorem Ipsum
|
||||
identifier: test9
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 10
|
||||
title: Test10
|
||||
description: Lorem Ipsum
|
||||
identifier: test10
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 11
|
||||
title: Test11
|
||||
description: Lorem Ipsum
|
||||
identifier: test11
|
||||
owner_id: 6
|
||||
namespace_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 12
|
||||
title: Test12
|
||||
description: Lorem Ipsum
|
||||
identifier: test12
|
||||
owner_id: 6
|
||||
namespace_id: 7
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 13
|
||||
title: Test13
|
||||
description: Lorem Ipsum
|
||||
identifier: test13
|
||||
owner_id: 6
|
||||
namespace_id: 8
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 14
|
||||
title: Test14
|
||||
description: Lorem Ipsum
|
||||
identifier: test14
|
||||
owner_id: 6
|
||||
namespace_id: 9
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 15
|
||||
title: Test15
|
||||
description: Lorem Ipsum
|
||||
identifier: test15
|
||||
owner_id: 6
|
||||
namespace_id: 10
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 16
|
||||
title: Test16
|
||||
description: Lorem Ipsum
|
||||
identifier: test16
|
||||
owner_id: 6
|
||||
namespace_id: 11
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 17
|
||||
title: Test17
|
||||
description: Lorem Ipsum
|
||||
identifier: test17
|
||||
owner_id: 6
|
||||
namespace_id: 12
|
||||
updated: 0
|
||||
created: 0
|
||||
# This list is owned by user 7, and several other users have access to it via different methods.
|
||||
# It is used to test the listUsers method.
|
||||
-
|
||||
id: 18
|
||||
title: Test18
|
||||
description: Lorem Ipsum
|
||||
identifier: test18
|
||||
owner_id: 7
|
||||
namespace_id: 13
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 19
|
||||
title: Test19
|
||||
description: Lorem Ipsum
|
||||
identifier: test19
|
||||
owner_id: 7
|
||||
namespace_id: 14
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 20
|
||||
title: Test20
|
||||
description: Lorem Ipsum
|
||||
identifier: test20
|
||||
owner_id: 13
|
||||
namespace_id: 15
|
||||
updated: 0
|
||||
created: 0
|
78
pkg/db/fixtures/namespaces.yml
Normal file
78
pkg/db/fixtures/namespaces.yml
Normal file
@ -0,0 +1,78 @@
|
||||
- id: 1
|
||||
name: testnamespace
|
||||
description: Lorem Ipsum
|
||||
owner_id: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 2
|
||||
name: testnamespace2
|
||||
description: Lorem Ipsum
|
||||
owner_id: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 3
|
||||
name: testnamespace3
|
||||
description: Lorem Ipsum
|
||||
owner_id: 3
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 6
|
||||
name: testnamespace6
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 7
|
||||
name: testnamespace7
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 8
|
||||
name: testnamespace8
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 9
|
||||
name: testnamespace9
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 10
|
||||
name: testnamespace10
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 11
|
||||
name: testnamespace11
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 12
|
||||
name: testnamespace12
|
||||
description: Lorem Ipsum
|
||||
owner_id: 6
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 13
|
||||
name: testnamespace13
|
||||
description: Lorem Ipsum
|
||||
owner_id: 7
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 14
|
||||
name: testnamespace14
|
||||
description: Lorem Ipsum
|
||||
owner_id: 7
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 15
|
||||
name: testnamespace15
|
||||
description: Lorem Ipsum
|
||||
owner_id: 13
|
||||
updated: 0
|
||||
created: 0
|
8
pkg/db/fixtures/task_assignees.yml
Normal file
8
pkg/db/fixtures/task_assignees.yml
Normal file
@ -0,0 +1,8 @@
|
||||
- id: 1
|
||||
task_id: 30
|
||||
user_id: 1
|
||||
created: 0
|
||||
- id: 2
|
||||
task_id: 30
|
||||
user_id: 2
|
||||
created: 0
|
11
pkg/db/fixtures/task_attachments.yml
Normal file
11
pkg/db/fixtures/task_attachments.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- id: 1
|
||||
task_id: 1
|
||||
file_id: 1
|
||||
created_by_id: 1
|
||||
created: 0
|
||||
# The file for this attachment does not exist
|
||||
- id: 2
|
||||
task_id: 1
|
||||
file_id: 9999
|
||||
created_by_id: 1
|
||||
created: 0
|
12
pkg/db/fixtures/task_relations.yml
Normal file
12
pkg/db/fixtures/task_relations.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- id: 1
|
||||
task_id: 1
|
||||
other_task_id: 29
|
||||
relation_kind: 'subtask'
|
||||
created_by_id: 1
|
||||
created: 0
|
||||
- id: 2
|
||||
task_id: 29
|
||||
other_task_id: 1
|
||||
relation_kind: 'parenttask'
|
||||
created_by_id: 1
|
||||
created: 0
|
8
pkg/db/fixtures/task_reminders.yml
Normal file
8
pkg/db/fixtures/task_reminders.yml
Normal file
@ -0,0 +1,8 @@
|
||||
- id: 1
|
||||
task_id: 27
|
||||
reminder_unix: 1543626724
|
||||
created: 1543626724
|
||||
- id: 2
|
||||
task_id: 27
|
||||
reminder_unix: 1543626824
|
||||
created: 1543626724
|
246
pkg/db/fixtures/tasks.yml
Normal file
246
pkg/db/fixtures/tasks.yml
Normal file
@ -0,0 +1,246 @@
|
||||
- id: 1
|
||||
text: 'task #1'
|
||||
description: 'Lorem Ipsum'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 2
|
||||
text: 'task #2 done'
|
||||
done: true
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 2
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 3
|
||||
text: 'task #3 high prio'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 3
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
priority: 100
|
||||
- id: 4
|
||||
text: 'task #4 low prio'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 4
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
priority: 1
|
||||
- id: 5
|
||||
text: 'task #5 higher due date'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 5
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
due_date_unix: 1543636724
|
||||
- id: 6
|
||||
text: 'task #6 lower due date'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 6
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
due_date_unix: 1543616724
|
||||
- id: 7
|
||||
text: 'task #7 with start date'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 7
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
start_date_unix: 1544600000
|
||||
- id: 8
|
||||
text: 'task #8 with end date'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 8
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
end_date_unix: 1544700000
|
||||
- id: 9
|
||||
text: 'task #9 with start and end date'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 9
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
start_date_unix: 1544600000
|
||||
end_date_unix: 1544700000
|
||||
- id: 10
|
||||
text: 'task #10 basic'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 10
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 11
|
||||
text: 'task #11 basic'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 11
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 12
|
||||
text: 'task #12 basic'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 12
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 13
|
||||
text: 'task #13 basic other list'
|
||||
created_by_id: 1
|
||||
list_id: 2
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 14
|
||||
text: 'task #14 basic other list'
|
||||
created_by_id: 5
|
||||
list_id: 5
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 15
|
||||
text: 'task #15'
|
||||
created_by_id: 6
|
||||
list_id: 6
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 16
|
||||
text: 'task #16'
|
||||
created_by_id: 6
|
||||
list_id: 7
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 17
|
||||
text: 'task #17'
|
||||
created_by_id: 6
|
||||
list_id: 8
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 18
|
||||
text: 'task #18'
|
||||
created_by_id: 6
|
||||
list_id: 9
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 19
|
||||
text: 'task #19'
|
||||
created_by_id: 6
|
||||
list_id: 10
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 20
|
||||
text: 'task #20'
|
||||
created_by_id: 6
|
||||
list_id: 11
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 21
|
||||
text: 'task #21'
|
||||
created_by_id: 6
|
||||
list_id: 12
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 22
|
||||
text: 'task #22'
|
||||
created_by_id: 6
|
||||
list_id: 13
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 23
|
||||
text: 'task #23'
|
||||
created_by_id: 6
|
||||
list_id: 14
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 24
|
||||
text: 'task #24'
|
||||
created_by_id: 6
|
||||
list_id: 15
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 25
|
||||
text: 'task #25'
|
||||
created_by_id: 6
|
||||
list_id: 16
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 26
|
||||
text: 'task #26'
|
||||
created_by_id: 6
|
||||
list_id: 17
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 27
|
||||
text: 'task #27 with reminders'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 12
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 28
|
||||
text: 'task #28 with repeat after'
|
||||
done: false
|
||||
created_by_id: 1
|
||||
repeat_after: 3600
|
||||
list_id: 1
|
||||
index: 13
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 29
|
||||
text: 'task #29 with parent task (1)'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 14
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 30
|
||||
text: 'task #30 with assignees'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 15
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 31
|
||||
text: 'task #31 with color'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 16
|
||||
hex_color: f0f0f0
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 32
|
||||
text: 'task #32'
|
||||
created_by_id: 1
|
||||
list_id: 3
|
||||
index: 1
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
- id: 33
|
||||
text: 'task #33 with percent done'
|
||||
created_by_id: 1
|
||||
list_id: 1
|
||||
index: 17
|
||||
percent_done: 0.5
|
||||
created: 1543626724
|
||||
updated: 1543626724
|
||||
|
48
pkg/db/fixtures/team_list.yml
Normal file
48
pkg/db/fixtures/team_list.yml
Normal file
@ -0,0 +1,48 @@
|
||||
- id: 1
|
||||
team_id: 1
|
||||
list_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
# This team has read only access on list 6
|
||||
- id: 2
|
||||
team_id: 2
|
||||
list_id: 6
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
# This team has write access on list 7
|
||||
- id: 3
|
||||
team_id: 3
|
||||
list_id: 7
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
# This team has admin access on list 8
|
||||
- id: 4
|
||||
team_id: 4
|
||||
list_id: 8
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
# Readonly acces on list 19
|
||||
- id: 5
|
||||
team_id: 8
|
||||
list_id: 19
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
# Write acces on list 19
|
||||
- id: 6
|
||||
team_id: 9
|
||||
list_id: 19
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
# Admin acces on list 19
|
||||
- id: 7
|
||||
team_id: 10
|
||||
list_id: 19
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
57
pkg/db/fixtures/team_members.yml
Normal file
57
pkg/db/fixtures/team_members.yml
Normal file
@ -0,0 +1,57 @@
|
||||
-
|
||||
team_id: 1
|
||||
user_id: 1
|
||||
admin: true
|
||||
created: 0
|
||||
-
|
||||
team_id: 1
|
||||
user_id: 2
|
||||
created: 0
|
||||
-
|
||||
team_id: 2
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 3
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 4
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 5
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 6
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 7
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 8
|
||||
user_id: 1
|
||||
created: 0
|
||||
-
|
||||
team_id: 9
|
||||
user_id: 2
|
||||
created: 0
|
||||
-
|
||||
team_id: 10
|
||||
user_id: 3
|
||||
created: 0
|
||||
-
|
||||
team_id: 11
|
||||
user_id: 8
|
||||
created: 0
|
||||
-
|
||||
team_id: 12
|
||||
user_id: 9
|
||||
created: 0
|
||||
-
|
||||
team_id: 13
|
||||
user_id: 10
|
||||
created: 0
|
52
pkg/db/fixtures/team_namespaces.yml
Normal file
52
pkg/db/fixtures/team_namespaces.yml
Normal file
@ -0,0 +1,52 @@
|
||||
- id: 1
|
||||
team_id: 1
|
||||
namespace_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 2
|
||||
team_id: 2
|
||||
namespace_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 3
|
||||
team_id: 5
|
||||
namespace_id: 7
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 4
|
||||
team_id: 6
|
||||
namespace_id: 8
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 5
|
||||
team_id: 7
|
||||
namespace_id: 9
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 6
|
||||
team_id: 11
|
||||
namespace_id: 14
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 7
|
||||
team_id: 12
|
||||
namespace_id: 14
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 8
|
||||
team_id: 13
|
||||
namespace_id: 14
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
40
pkg/db/fixtures/teams.yml
Normal file
40
pkg/db/fixtures/teams.yml
Normal file
@ -0,0 +1,40 @@
|
||||
- id: 1
|
||||
name: testteam1
|
||||
description: Lorem Ipsum
|
||||
created_by_id: 1
|
||||
- id: 2
|
||||
name: testteam2_read_only_on_list6
|
||||
created_by_id: 1
|
||||
- id: 3
|
||||
name: testteam3_write_on_list7
|
||||
created_by_id: 1
|
||||
- id: 4
|
||||
name: testteam4_admin_on_list8
|
||||
created_by_id: 1
|
||||
- id: 5
|
||||
name: testteam2_read_only_on_namespace7
|
||||
created_by_id: 1
|
||||
- id: 6
|
||||
name: testteam3_write_on_namespace8
|
||||
created_by_id: 1
|
||||
- id: 7
|
||||
name: testteam4_admin_on_namespace9
|
||||
created_by_id: 1
|
||||
- id: 8
|
||||
name: testteam8
|
||||
created_by_id: 7
|
||||
- id: 9
|
||||
name: testteam9
|
||||
created_by_id: 7
|
||||
- id: 10
|
||||
name: testteam10
|
||||
created_by_id: 7
|
||||
- id: 11
|
||||
name: testteam11
|
||||
created_by_id: 7
|
||||
- id: 12
|
||||
name: testteam12
|
||||
created_by_id: 7
|
||||
- id: 13
|
||||
name: testteam13
|
||||
created_by_id: 7
|
97
pkg/db/fixtures/users.yml
Normal file
97
pkg/db/fixtures/users.yml
Normal file
@ -0,0 +1,97 @@
|
||||
-
|
||||
id: 1
|
||||
username: 'user1'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user1@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 2
|
||||
username: 'user2'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user2@example.com'
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 3
|
||||
username: 'user3'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user3@example.com'
|
||||
password_reset_token: passwordresettesttoken
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 4
|
||||
username: 'user4'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user4@example.com'
|
||||
email_confirm_token: tiepiQueed8ahc7zeeFe1eveiy4Ein8osooxegiephauph2Ael
|
||||
updated: 0
|
||||
created: 0
|
||||
-
|
||||
id: 5
|
||||
username: 'user5'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user5@example.com'
|
||||
email_confirm_token: tiepiQueed8ahc7zeeFe1eveiy4Ein8osooxegiephauph2Ael
|
||||
is_active: false
|
||||
updated: 0
|
||||
created: 0
|
||||
# This use is used to create a whole bunch of lists which are then shared directly with a user
|
||||
- id: 6
|
||||
username: 'user6'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user6@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 7
|
||||
username: 'user7'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user7@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 8
|
||||
username: 'user8'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user8@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 9
|
||||
username: 'user9'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user9@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 10
|
||||
username: 'user10'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user10@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 11
|
||||
username: 'user11'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user11@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 12
|
||||
username: 'user12'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user12@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 13
|
||||
username: 'user13'
|
||||
password: '$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.' # 1234
|
||||
email: 'user14@example.com'
|
||||
is_active: true
|
||||
updated: 0
|
||||
created: 0
|
48
pkg/db/fixtures/users_list.yml
Normal file
48
pkg/db/fixtures/users_list.yml
Normal file
@ -0,0 +1,48 @@
|
||||
- id: 1
|
||||
user_id: 1
|
||||
list_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 2
|
||||
user_id: 2
|
||||
list_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 3
|
||||
user_id: 1
|
||||
list_id: 9
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 4
|
||||
user_id: 1
|
||||
list_id: 10
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 5
|
||||
user_id: 1
|
||||
list_id: 11
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 6
|
||||
user_id: 4
|
||||
list_id: 19
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 7
|
||||
user_id: 5
|
||||
list_id: 19
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 8
|
||||
user_id: 6
|
||||
list_id: 19
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
52
pkg/db/fixtures/users_namespace.yml
Normal file
52
pkg/db/fixtures/users_namespace.yml
Normal file
@ -0,0 +1,52 @@
|
||||
- id: 1
|
||||
user_id: 1
|
||||
namespace_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 2
|
||||
user_id: 2
|
||||
namespace_id: 3
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 3
|
||||
user_id: 1
|
||||
namespace_id: 10
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 4
|
||||
user_id: 1
|
||||
namespace_id: 11
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
|
||||
- id: 5
|
||||
user_id: 1
|
||||
namespace_id: 12
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 6
|
||||
user_id: 11
|
||||
namespace_id: 14
|
||||
right: 0
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 7
|
||||
user_id: 12
|
||||
namespace_id: 14
|
||||
right: 1
|
||||
updated: 0
|
||||
created: 0
|
||||
- id: 8
|
||||
user_id: 13
|
||||
namespace_id: 14
|
||||
right: 2
|
||||
updated: 0
|
||||
created: 0
|
69
pkg/db/test.go
Normal file
69
pkg/db/test.go
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright2018-2020 Vikunja and contriubtors. All rights reserved.
|
||||
//
|
||||
// This file is part of Vikunja.
|
||||
//
|
||||
// Vikunja is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Vikunja is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
"os"
|
||||
)
|
||||
|
||||
// CreateTestEngine creates an instance of the db engine which lives in memory
|
||||
func CreateTestEngine() (engine *xorm.Engine, err error) {
|
||||
|
||||
if x != nil {
|
||||
return x, nil
|
||||
}
|
||||
|
||||
if os.Getenv("VIKUNJA_TESTS_USE_CONFIG") == "1" {
|
||||
config.InitConfig()
|
||||
engine, err = CreateDBEngine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
engine, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
engine.SetMapper(core.GonicMapper{})
|
||||
engine.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1")
|
||||
engine.SetLogger(xorm.NewSimpleLogger(log.GetLogWriter("database")))
|
||||
x = engine
|
||||
return
|
||||
}
|
||||
|
||||
// InitTestFixtures populates the db with all fixtures from the fixtures folder
|
||||
func InitTestFixtures(tablenames ...string) (err error) {
|
||||
// Create all fixtures
|
||||
config.InitDefaultConfig()
|
||||
// We need to set the root path even if we're not using the config, otherwise fixtures are not loaded correctly
|
||||
config.ServiceRootpath.Set(os.Getenv("VIKUNJA_SERVICE_ROOTPATH"))
|
||||
|
||||
// Sync fixtures
|
||||
err = InitFixtures(tablenames...)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -18,15 +18,36 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/testfixtures.v2"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var fixtures *testfixtures.Context
|
||||
|
||||
// InitFixtures initialize test fixtures for a test database
|
||||
func InitFixtures(helper testfixtures.Helper, dir string) (err error) {
|
||||
func InitFixtures(tablenames ...string) (err error) {
|
||||
|
||||
var helper testfixtures.Helper = &testfixtures.SQLite{}
|
||||
if config.DatabaseType.GetString() == "mysql" {
|
||||
helper = &testfixtures.MySQL{}
|
||||
}
|
||||
dir := filepath.Join(config.ServiceRootpath.GetString(), "pkg", "db", "fixtures")
|
||||
|
||||
testfixtures.SkipDatabaseNameCheck(true)
|
||||
fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir)
|
||||
|
||||
// If fixture table names are specified, load them
|
||||
// Otherwise, load all fixtures
|
||||
if len(tablenames) > 0 {
|
||||
for i, name := range tablenames {
|
||||
tablenames[i] = filepath.Join(dir, name+".yml")
|
||||
}
|
||||
fixtures, err = testfixtures.NewFiles(x.DB().DB, helper, tablenames...)
|
||||
} else {
|
||||
fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -34,3 +55,9 @@ func InitFixtures(helper testfixtures.Helper, dir string) (err error) {
|
||||
func LoadFixtures() error {
|
||||
return fixtures.Load()
|
||||
}
|
||||
|
||||
// LoadAndAssertFixtures loads all fixtures defined before and asserts they are correctly loaded
|
||||
func LoadAndAssertFixtures(t *testing.T) {
|
||||
err := LoadFixtures()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user