Exemple #1
0
 def create_photo(self,title='',caption='',image=None):
     """
     Creates a photo directly in the database.
     """
     with astral.app.test_request_context('/'):
         if image is None:
             image = choice(images)
         photo = Photo(title=title,caption=caption,image=image)
         photo.save()
         return photo
 def create_photo(self, title="", caption="", image=None):
     """
     Creates a photo directly in the database.
     """
     with astral.app.test_request_context("/"):
         if image is None:
             image = choice(images)
         photo = Photo(title=title, caption=caption, image=image)
         photo.save()
         return photo
Exemple #3
0
    def test_delete(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id

        assert Photo.find_by_id(id) is not None

        rv = self.app.delete("/api/photos/%s/" % id)
        obj = json.loads(rv.data)

        assert obj == True
        assert Photo.find_by_id(id) is None
    def test_delete(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id

        assert Photo.find_by_id(id) is not None

        rv = self.app.delete("/api/photos/%s/" % id)
        obj = json.loads(rv.data)

        assert obj == True
        assert Photo.find_by_id(id) is None
Exemple #5
0
    def test_put_json(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id
        rv = self.app.put("/api/photos/%s/" % id, data=json.dumps({ 'title': 'Foobar' }), content_type='application/json')
        assert rv.status_code == 200

        photo = Photo.find_by_id(id)
        assert photo.title == 'Foobar'
    def test_put_json(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id
        rv = self.app.put("/api/photos/%s/" % id, data=json.dumps({"title": "Foobar"}), content_type="application/json")
        assert rv.status_code == 200

        photo = Photo.find_by_id(id)
        assert photo.title == "Foobar"
    def test_put_form(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id
        rv = self.app.put("/api/photos/%s/" % id, data={"title": "Foobar"})
        assert rv.status_code == 200

        photo = Photo.find_by_id(id)
        self.assertEqual(photo.title, "Foobar")
Exemple #8
0
    def test_put_form(self):
        photo = self.create_photo(title="Lorem", caption="Lorem ipsum dolor.")
        id = photo.id
        rv = self.app.put("/api/photos/%s/" % id, data={
            'title': 'Foobar',
        })
        assert rv.status_code == 200

        photo = Photo.find_by_id(id)
        self.assertEqual(photo.title, 'Foobar')