File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,11 @@ def post_photos():
4747 resp = responses .new201 (data )
4848 return resp
4949
50+ @mod_photos .route ('/photos/<int:id>' ,methods = ['GET' ])
51+ def get_photos_one (id ):
52+ photo = Photo .query .get_or_404 (id )
53+ return jsonify (photo .serialize_all ())
54+
5055@mod_photos .route ('/photos' ,methods = ['GET' ])
5156def get_photos ():
5257 app .logger .debug ("Applying get photos..." )
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ def get_id(self):
2121
2222 def serialize (self ):
2323 return {'uuid' :self .uuid }
24+ def serialize_all (self ):
25+ return {'uuid' :self .uuid , 'filepath' : self .filepath }
2426 def __repr__ (self ):
2527 return '<photo uuid=%r filepath=%r>' % (self .uuid ,self .filepath )
2628
Original file line number Diff line number Diff line change @@ -62,31 +62,31 @@ def test_post_photo_not_allowed_file(self):
6262
6363 def test_get_photo_correct (self ):
6464 #fake information
65- data = {"uuid" :"1" ,"filepath" :"test1.jpg" }
66- Photo .create (** data )
65+ create_photo (1 )
6766
6867 #fake data to test get resource
6968 with self .app .open_resource ("test_resources/photo.jpg" ) as fp :
7069 with self .client :
7170 response = self .client .get ("/photos/v1.0/photos" )
7271 app .logger .debug (response .json )
73- app . logger . debug (response .json ['data' ][0 ]['uuid' ])
72+ self . assertTrue (response .json ['data' ][0 ]['uuid' ]== '1' )
7473
7574
76- def test_get_photo_correct (self ):
75+ def test_get_one_photo_correct (self ):
7776 #fake information
7877 create_photo (1 )
7978 #fake data to test get resource
8079 with self .client :
81- response = self .client .get ("/photos/v1.0/photos" )
80+ response = self .client .get ("/photos/v1.0/photos/1 " )
8281 app .logger .debug (response .json )
83- app .logger .debug (response .json ['data' ][0 ]['uuid' ])
82+ self .assertTrue (response .json ['uuid' ]== '1' )
83+
8484
85- def test_get_photos_pagination (self ):
85+ def test_get_photos_pagination_correct (self ):
8686 create_photo (102 )
8787 with self .client :
8888 response = self .client .get ("/photos/v1.0/photos" )
8989 app .logger .debug (response .json )
90- app . logger . debug (response .json ['data' ][0 ]['uuid' ])
90+ self . assertTrue (response .json ['data' ][0 ]['uuid' ]== '1' )
9191
9292
You can’t perform that action at this time.
0 commit comments