github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api4/brand_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package api4 5 6 import ( 7 "net/http" 8 "testing" 9 ) 10 11 func TestGetBrandImage(t *testing.T) { 12 th := Setup().InitBasic().InitSystemAdmin() 13 defer th.TearDown() 14 Client := th.Client 15 16 _, resp := Client.GetBrandImage() 17 CheckNotFoundStatus(t, resp) 18 19 Client.Logout() 20 _, resp = Client.GetBrandImage() 21 CheckNotFoundStatus(t, resp) 22 23 _, resp = th.SystemAdminClient.GetBrandImage() 24 CheckNotFoundStatus(t, resp) 25 } 26 27 func TestUploadBrandImage(t *testing.T) { 28 th := Setup().InitBasic().InitSystemAdmin() 29 defer th.TearDown() 30 Client := th.Client 31 32 data, err := readTestFile("test.png") 33 if err != nil { 34 t.Fatal(err) 35 } 36 37 ok, resp := Client.UploadBrandImage(data) 38 CheckForbiddenStatus(t, resp) 39 if ok { 40 t.Fatal("Should return false, set brand image not allowed") 41 } 42 43 // status code returns either forbidden or unauthorized 44 // note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server 45 Client.Logout() 46 _, resp = Client.UploadBrandImage(data) 47 if resp.StatusCode == http.StatusForbidden { 48 CheckForbiddenStatus(t, resp) 49 } else if resp.StatusCode == http.StatusUnauthorized { 50 CheckUnauthorizedStatus(t, resp) 51 } else { 52 t.Fatal("Should have failed either forbidden or unauthorized") 53 } 54 55 _, resp = th.SystemAdminClient.UploadBrandImage(data) 56 CheckNotImplementedStatus(t, resp) 57 }