@@ -53,6 +53,9 @@ def setUp(self):
5353 self .db .tx_Source = 'web'
5454
5555 self .db .issue .addprop (tx_Source = hyperdb .String ())
56+ self .db .issue .addprop (anint = hyperdb .Integer ())
57+ self .db .issue .addprop (afloat = hyperdb .Number ())
58+ self .db .issue .addprop (abool = hyperdb .Boolean ())
5659 self .db .msg .addprop (tx_Source = hyperdb .String ())
5760
5861 self .db .post_init ()
@@ -697,14 +700,74 @@ def testEtagProcessing(self):
697700 else :
698701 self .assertEqual (self .dummy_client .response_code , 412 )
699702
703+ def testDispatchPost (self ):
704+ """
705+ run POST through rest dispatch(). This also tests
706+ sending json payload through code as dispatch is the
707+ code that changes json payload into something we can
708+ process.
709+ """
710+
711+ # TEST #0
712+ # POST: issue make joe assignee and admin and demo as
713+ # nosy
714+ # simulate: /rest/data/issue
715+ body = b'{ "title": "Joe Doe has problems", \
716+ "nosy": [ "1", "3" ], \
717+ "assignedto": "2", \
718+ "abool": true, \
719+ "afloat": 2.3, \
720+ "anint": 567890 \
721+ }'
722+ env = { "CONTENT_TYPE" : "application/json" ,
723+ "CONTENT_LENGTH" : len (body ),
724+ "REQUEST_METHOD" : "POST"
725+ }
726+ headers = {"accept" : "application/json; version=1" ,
727+ "content-type" : env ['CONTENT_TYPE' ],
728+ "content-length" : env ['CONTENT_LENGTH' ],
729+ }
730+ self .headers = headers
731+ # we need to generate a FieldStorage the looks like
732+ # FieldStorage(None, None, 'string') rather than
733+ # FieldStorage(None, None, [])
734+ body_file = BytesIO (body ) # FieldStorage needs a file
735+ form = client .BinaryFieldStorage (body_file ,
736+ headers = headers ,
737+ environ = env )
738+ self .server .client .request .headers .get = self .get_header
739+ results = self .server .dispatch (env ["REQUEST_METHOD" ],
740+ "/rest/data/issue" ,
741+ form )
742+
743+ print (results )
744+ self .assertEqual (self .server .client .response_code , 201 )
745+ json_dict = json .loads (b2s (results ))
746+ self .assertEqual (json_dict ['data' ]['link' ],
747+ "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1" )
748+ self .assertEqual (json_dict ['data' ]['id' ], "1" )
749+ results = self .server .dispatch ('GET' ,
750+ "/rest/data/issue/1" , self .empty_form )
751+ print (results )
752+ json_dict = json .loads (b2s (results ))
753+ self .assertEqual (json_dict ['data' ]['link' ],
754+ "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1" )
755+ self .assertEqual (json_dict ['data' ]['attributes' ]['abool' ], True )
756+ self .assertEqual (json_dict ['data' ]['attributes' ]['afloat' ], 2.3 )
757+ self .assertEqual (json_dict ['data' ]['attributes' ]['anint' ], 567890 )
758+ self .assertEqual (len (json_dict ['data' ]['attributes' ]['nosy' ]), 3 )
759+ self .assertEqual (json_dict ['data' ]['attributes' ]\
760+ ['assignedto' ]['link' ],
761+ "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2" )
762+
763+
700764 def testDispatch (self ):
701765 """
702766 run changes through rest dispatch(). This also tests
703767 sending json payload through code as dispatch is the
704768 code that changes json payload into something we can
705769 process.
706770 """
707-
708771 # TEST #1
709772 # PUT: joe's 'realname' using json data.
710773 # simulate: /rest/data/user/<id>/realname
0 commit comments