mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* MM-27149: optimize initBasic Mostly, all tests just needed the user initialization part and not the channel and group creation. So we move the user initialization inside the Setup call. This avoids unnecessary DB calls which take around 250-300ms on average. And we make the login requests concurrently to shave off a few more ms. According to my tests, the 2 login calls take 140 ms on average, which shaves off 70ms. So approximately, we shave off 350ms per test. And there are 114 occurences of these. So around 39 seconds. * make initlogin only for Setup/SetupEnterprise Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/utils/testutils"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetBrandImage(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
Client := th.Client
|
|
|
|
_, resp := Client.GetBrandImage()
|
|
CheckNotFoundStatus(t, resp)
|
|
|
|
Client.Logout()
|
|
_, resp = Client.GetBrandImage()
|
|
CheckNotFoundStatus(t, resp)
|
|
|
|
_, resp = th.SystemAdminClient.GetBrandImage()
|
|
CheckNotFoundStatus(t, resp)
|
|
}
|
|
|
|
func TestUploadBrandImage(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
Client := th.Client
|
|
|
|
data, err := testutils.ReadTestFile("test.png")
|
|
require.Nil(t, err)
|
|
|
|
_, resp := Client.UploadBrandImage(data)
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
// status code returns either forbidden or unauthorized
|
|
// note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server
|
|
Client.Logout()
|
|
_, resp = Client.UploadBrandImage(data)
|
|
if resp.StatusCode == http.StatusForbidden {
|
|
CheckForbiddenStatus(t, resp)
|
|
} else if resp.StatusCode == http.StatusUnauthorized {
|
|
CheckUnauthorizedStatus(t, resp)
|
|
} else {
|
|
require.Fail(t, "Should have failed either forbidden or unauthorized")
|
|
}
|
|
|
|
_, resp = th.SystemAdminClient.UploadBrandImage(data)
|
|
CheckCreatedStatus(t, resp)
|
|
}
|
|
|
|
func TestDeleteBrandImage(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
data, err := testutils.ReadTestFile("test.png")
|
|
require.Nil(t, err)
|
|
|
|
_, resp := th.SystemAdminClient.UploadBrandImage(data)
|
|
CheckCreatedStatus(t, resp)
|
|
|
|
resp = th.Client.DeleteBrandImage()
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
th.Client.Logout()
|
|
|
|
resp = th.Client.DeleteBrandImage()
|
|
CheckUnauthorizedStatus(t, resp)
|
|
|
|
resp = th.SystemAdminClient.DeleteBrandImage()
|
|
CheckOKStatus(t, resp)
|
|
|
|
resp = th.SystemAdminClient.DeleteBrandImage()
|
|
CheckNotFoundStatus(t, resp)
|
|
}
|