|
@@ -1,6 +1,7 @@
|
|
|
package api
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"encoding/json"
|
|
|
"net/http"
|
|
|
"net/http/httptest"
|
|
@@ -80,7 +81,7 @@ func (t *testSuite) BeforeAll() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (t *testSuite) TestTeachersJSON() {
|
|
|
+func (t *testSuite) TestGetTeachersJSON() {
|
|
|
var teachers []*orm.Teacher
|
|
|
|
|
|
req, err := http.NewRequest("GET", "/teachers?format=json", nil)
|
|
@@ -108,3 +109,37 @@ func (t *testSuite) TestTeachersJSON() {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func (t *testSuite) TestPostTeacherJSON() {
|
|
|
+ teacher := new(orm.Teacher)
|
|
|
+ teacher.Name = "Mario"
|
|
|
+ teacher.Surname = "ROSSI"
|
|
|
+
|
|
|
+ data, err := json.Marshal(teacher)
|
|
|
+ t.Nil(err)
|
|
|
+
|
|
|
+ req, err := http.NewRequest("POST", "/teachers/add?format=json", bytes.NewBuffer(data))
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ pattern := PathPattern{
|
|
|
+ "/api/%s/add",
|
|
|
+ "/%s?format=json&tpl_layout=base&tpl_content=%s",
|
|
|
+ []string{"POST"},
|
|
|
+ }
|
|
|
+
|
|
|
+ rr := httptest.NewRecorder()
|
|
|
+ modelHandler("teachers", pattern).ServeHTTP(rr, req)
|
|
|
+
|
|
|
+ t.Equal(http.StatusOK, rr.Code)
|
|
|
+
|
|
|
+ // if !t.Failed() {
|
|
|
+ // err := json.Unmarshal(rr.Body.Bytes(), &teachers)
|
|
|
+ // t.Nil(err)
|
|
|
+ // if !t.Failed() {
|
|
|
+ // t.Equal("AGOSTINO", teachers[0].Surname)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|