-
Notifications
You must be signed in to change notification settings - Fork 2
/
entity_delete_test.go
94 lines (68 loc) · 2.43 KB
/
entity_delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gorilla/context"
"github.com/stretchr/testify/assert"
)
func TestDeleteNoId(t *testing.T) {
req := deleteRequest("/Shot/")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200, `foo`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestDeletePermissionsIssue(t *testing.T) {
req := deleteRequest("/Project/75")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200,
`{"exception":true,"message":"API delete() CRUD ERROR #4.1: Entity Project 75 can not be `+
`deleted by this user. Rule: API Admin -- PermissionRule 315: retire_entity_condition FOR `+
`entity_type => Project. RULE: {\"path\":\"name\", \"relation\":\"is_not\",\"values\":`+
`[\"Template Project\"]}","error_code":104}`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusForbidden, w.Code)
}
func TestDeleteError(t *testing.T) {
req := deleteRequest("/Project/75")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200,
`{"exception":true,"message":"Somer Error message","error_code":104}`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
}
func TestDeleteSuccess(t *testing.T) {
req := deleteRequest("/Project/75")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200, `{"results": true}`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
}
func TestDeleteMissing(t *testing.T) {
req := deleteRequest("/Shot/1000000")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200,
`{"exception":true,"message":"API delete() CRUD ERROR #3: Entity of type [Shot] with id=1000000 does not exist.","error_code":104}`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestDeleteBadJsonResponse(t *testing.T) {
req := deleteRequest("/Project/75")
w := httptest.NewRecorder()
server, client, config := mockShotgun(200, `foo`)
defer server.Close()
context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
assert.Equal(t, http.StatusBadGateway, w.Code)
}