@@ -47,13 +47,6 @@ def test_invalid(self):
47
47
"metadata" ,
48
48
"error_at"
49
49
]
50
- },
51
- {
52
- "code" : "time-traveling" ,
53
- "message" : "Sounds like a bullshit" ,
54
- "path" : [
55
- "$body"
56
- ]
57
50
}
58
51
]
59
52
}
@@ -119,3 +112,72 @@ def test_valid(self):
119
112
120
113
self .assertTrue (form .is_valid ())
121
114
self .assertEqual (form .cleaned_data , expected )
115
+
116
+ def test_default_clean (self ):
117
+ data = {
118
+ "title" : "Unknown Pleasures" ,
119
+ "type" : "vinyl" ,
120
+ "artist" : {
121
+ "name" : "Joy Division" ,
122
+ "genres" : [
123
+ "rock" ,
124
+ "punk"
125
+ ],
126
+ "members" : 4
127
+ },
128
+ "year" : 1998 ,
129
+ "songs" : [
130
+ {
131
+ "title" : "Disorder" ,
132
+ "duration" : "3:29"
133
+ },
134
+ {
135
+ "title" : "Day of the Lords" ,
136
+ "duration" : "4:48" ,
137
+ "metadata" : {
138
+ "_section" : {
139
+ "type" : "ID3v2" ,
140
+ "offset" : 0 ,
141
+ "byteLength" : 2048
142
+ },
143
+ "header" : {
144
+ "majorVersion" : 3 ,
145
+ "minorRevision" : 0 ,
146
+ "flagsOctet" : 0 ,
147
+ "unsynchronisationFlag" : False ,
148
+ "extendedHeaderFlag" : False ,
149
+ "experimentalIndicatorFlag" : False ,
150
+ "size" : 2038
151
+ }
152
+ }
153
+ }
154
+ ],
155
+ "metadata" : {
156
+ "created_at" : "2019-10-21T18:57:03+0100" ,
157
+ "updated_at" : "2019-10-21T18:57:03+0100"
158
+ }
159
+ }
160
+
161
+ rf = RequestFactory ()
162
+
163
+ expected = {
164
+ "errors" : [
165
+ {
166
+ "code" : "time-traveling" ,
167
+ "message" : "Sounds like a bullshit" ,
168
+ "path" : [
169
+ "$body"
170
+ ]
171
+ }
172
+ ]
173
+ }
174
+
175
+ request = rf .post ('/foo/bar' , data = data , content_type = 'application/json' )
176
+
177
+ form = AlbumForm .create_from_request (request )
178
+
179
+ self .assertFalse (form .is_valid ())
180
+ error = {
181
+ 'errors' : [item .to_dict () for item in form ._errors ]
182
+ }
183
+ self .assertEqual (error , expected )
0 commit comments