Skip to content

Unit tests for models/action #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions models/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var accessModes = []AccessMode{
func TestAccessLevel(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user1 := &User{ID: 2}; LoadTestFixture(t, user1)
user2 := &User{ID: 4}; LoadTestFixture(t, user2)
repo1 := &Repository{OwnerID: 2, IsPrivate: false}; LoadTestFixture(t, repo1)
repo2 := &Repository{OwnerID: 3, IsPrivate: true}; LoadTestFixture(t, repo2)
user1 := &User{ID: 2}; AssertExistsAndLoadBean(t, user1)
user2 := &User{ID: 4}; AssertExistsAndLoadBean(t, user2)
repo1 := &Repository{OwnerID: 2, IsPrivate: false}; AssertExistsAndLoadBean(t, repo1)
repo2 := &Repository{OwnerID: 3, IsPrivate: true}; AssertExistsAndLoadBean(t, repo2)

level, err := AccessLevel(user1, repo1)
assert.NoError(t, err)
Expand All @@ -44,10 +44,10 @@ func TestAccessLevel(t *testing.T) {
func TestHasAccess(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user1 := &User{ID: 2}; LoadTestFixture(t, user1)
user2 := &User{ID: 4}; LoadTestFixture(t, user2)
repo1 := &Repository{OwnerID: 2, IsPrivate: false}; LoadTestFixture(t, repo1)
repo2 := &Repository{OwnerID: 3, IsPrivate: true}; LoadTestFixture(t, repo2)
user1 := &User{ID: 2}; AssertExistsAndLoadBean(t, user1)
user2 := &User{ID: 4}; AssertExistsAndLoadBean(t, user2)
repo1 := &Repository{OwnerID: 2, IsPrivate: false}; AssertExistsAndLoadBean(t, repo1)
repo2 := &Repository{OwnerID: 3, IsPrivate: true}; AssertExistsAndLoadBean(t, repo2)

for _, accessMode := range accessModes {
has, err := HasAccess(user1, repo1, accessMode)
Expand All @@ -71,8 +71,8 @@ func TestHasAccess(t *testing.T) {
func TestUser_GetRepositoryAccesses(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user1 := &User{ID: 1}; LoadTestFixture(t, user1)
user2 := &User{ID: 2}; LoadTestFixture(t, user2)
user1 := &User{ID: 1}; AssertExistsAndLoadBean(t, user1)
user2 := &User{ID: 2}; AssertExistsAndLoadBean(t, user2)

accesses, err := user1.GetRepositoryAccesses()
assert.NoError(t, err)
Expand All @@ -82,8 +82,8 @@ func TestUser_GetRepositoryAccesses(t *testing.T) {
func TestUser_GetAccessibleRepositories(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user1 := &User{ID: 1}; LoadTestFixture(t, user1)
user2 := &User{ID: 2}; LoadTestFixture(t, user2)
user1 := &User{ID: 1}; AssertExistsAndLoadBean(t, user1)
user2 := &User{ID: 2}; AssertExistsAndLoadBean(t, user2)

repos, err := user1.GetAccessibleRepositories(0)
assert.NoError(t, err)
Expand All @@ -98,7 +98,7 @@ func TestUser_GetAccessibleRepositories(t *testing.T) {
func TestRepository_RecalculateAccesses(t *testing.T) {
// test with organization repo
assert.NoError(t, PrepareTestDatabase())
repo1 := &Repository{ID: 3}; LoadTestFixture(t, repo1)
repo1 := &Repository{ID: 3}; AssertExistsAndLoadBean(t, repo1)
assert.NoError(t, repo1.GetOwner())

sess := x.NewSession()
Expand All @@ -119,7 +119,7 @@ func TestRepository_RecalculateAccesses(t *testing.T) {
func TestRepository_RecalculateAccesses2(t *testing.T) {
// test with non-organization repo
assert.NoError(t, PrepareTestDatabase())
repo1 := &Repository{ID: 4}; LoadTestFixture(t, repo1)
repo1 := &Repository{ID: 4}; AssertExistsAndLoadBean(t, repo1)
assert.NoError(t, repo1.GetOwner())

sess := x.NewSession()
Expand Down
Loading