Skip to content

Commit 807bff1

Browse files
committed
Added first feature to list photos
1 parent 3edd760 commit 807bff1

6 files changed

Lines changed: 125 additions & 13 deletions

File tree

app/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_or_404(cls, id):
2525

2626
def update(self, commit=True, **kwargs):
2727
for attr, value in kwargs.iteritems():
28-
setattr(self, attr, value)
28+
setattr(self, attr, value)
2929
return commit and self.save() or self
3030

3131
def save(self, commit=True):

app/mod_photos/controllers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
mod_photos = Blueprint('photos',__name__,url_prefix='/photos/v1.0')
1515

16+
17+
responses = FactoryResponse()
18+
1619
def allowed_file(filename):
1720
return '.' in filename and filename.rsplit('.',1)[1] in ALLOWED_EXTENSIONS
1821

1922

2023
@mod_photos.route('/photos',methods=['POST'])
21-
def photos():
22-
responses = FactoryResponse()
24+
def photos_post():
2325
app.logger.debug("Applying post photo...")
2426

2527
data = None
@@ -45,3 +47,11 @@ def photos():
4547
resp = responses.new201(data)
4648
return resp
4749

50+
@mod_photos.route('/photos',methods=['GET'])
51+
def photos_get():
52+
app.logger.debug("Applying get photos...")
53+
photos = Photo.query.all()
54+
resp = jsonify({'data':
55+
[photo.serialize() for photo in photos]})
56+
return resp
57+

app/mod_photos/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ class Photo(Base,CRUDMixin):
1010
__tablename__='photo'
1111
uuid = db.Column(db.String(128), nullable=False)
1212
filepath = db.Column(db.String(500), nullable=False)
13-
13+
14+
1415
def __init__(self,uuid,filepath):
1516
self.uuid = uuid
1617
self.filepath = filepath
1718

1819
def get_id(self):
1920
return self.id
2021

22+
def serialize(self):
23+
return {'uuid':self.uuid}
2124
def __repr__(self):
22-
return '<photo uuid=%r filepath=%r>' % (self.name,self.uuid,self.filepath)
25+
return '<photo uuid=%r filepath=%r>' % (self.uuid,self.filepath)
2326

2427

app/mod_photos/tests.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from flask import url_for
1+
from flask import url_for, jsonify, json
22
from flask.ext.login import current_user
33

44
from app.test_base import BaseTestCase
55
from app import app
66

77
from .models import Photo
88
from factory_responses import FactoryResponse
9-
9+
from app.data import db
1010

1111

1212
class TestModelPhoto(BaseTestCase):
@@ -16,13 +16,13 @@ def test_new_photo(self):
1616
self.assertTrue(photo.filepath,'/test/photo.png')
1717
class TestFactoryResponses(BaseTestCase):
1818
responses = None
19-
2019
@classmethod
2120
def setUpClass(cls):
2221
cls.responses = FactoryResponse()
2322
@classmethod
2423
def tearDownClass(cls):
2524
cls.responses = None
25+
2626
def test_200_correct(self):
2727
#TODO add respnse
2828
resp=self.responses.new200()
@@ -40,7 +40,6 @@ def test_202_correct(self):
4040

4141
class TestPhotosViews(BaseTestCase):
4242
def test_post_photo_correct(self):
43-
4443
with self.app.open_resource("test_resources/photo.jpg") as fp:
4544
with self.client:
4645
response = self.client.post("/photos/v1.0/photos",data={'file':fp});
@@ -49,7 +48,8 @@ def test_post_photo_correct(self):
4948
self.app.logger.debug(response.json)
5049
#TODO add assert for correct response
5150
self.assertTrue(response.status_code == 201)
52-
def post_photo_not_allowed_file(self):
51+
52+
def test_post_photo_not_allowed_file(self):
5353
with self.app.open_resource("test_resources/photo.txt") as fp:
5454
with self.client:
5555
response = self.client.post("/photos/v1.0/photos",data={'file':fp});
@@ -58,3 +58,14 @@ def post_photo_not_allowed_file(self):
5858
#TODO add assert for correct response
5959
self.assertTrue(response.status_code == 202)
6060

61+
def test_get_photo_correct(self):
62+
#fake information
63+
data={"uuid":"1","filepath":"test1.jpg"}
64+
Photo.create(**data)
65+
66+
#fake data to test get resource
67+
with self.app.open_resource("test_resources/photo.jpg") as fp:
68+
with self.client:
69+
response = self.client.get("/photos/v1.0/photos")
70+
app.logger.debug(response.json['data'][0]['uuid'])
71+

app/test_base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
from app.data import db
44

55
class BaseTestCase(TestCase):
6+
#FIXME DEAD CODE??
67
def create_app(self):
78
app.config.from_object('config')
89
return app
910
def setUp(self):
10-
app.config['TESTING']=True
1111
app.config['WTF_CSRF_ENABLED']=False
12-
db.create_all()
12+
app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///:memory:'
13+
app.config['TESTING']=True
14+
#set up memory database
15+
db.app = app
16+
db.create_all()
1317
def tearDown(self):
1418
#db.session_remove()
1519
db.drop_all()

requirements.txt

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
APScheduler>=3.0.4
1+
APScheduler==3.1.0
2+
BeautifulSoup==3.2.1
3+
CherryPy==3.2.2
24
Flask==0.10.1
35
Flask-APScheduler==1.2.1
46
Flask-Bootstrap==3.3.5.7
@@ -7,22 +9,104 @@ Flask-SQLAlchemy==2.1
79
Flask-Testing==0.4.2
810
Flask-WTF==0.12
911
Jinja2==2.8
12+
Mako==0.9.1
13+
Markdown==2.4
1014
MarkupSafe==0.23
15+
PAM==0.4.2
16+
Pillow==2.3.0
17+
Pygments==1.6
18+
Routes==2.0
1119
SQLAlchemy==1.0.9
20+
Theano==0.8.1
21+
Twisted-Core==13.2.0
22+
Twisted-Names==13.2.0
23+
Twisted-Web==13.2.0
1224
WTForms==2.0.2
1325
Werkzeug==0.10.4
1426
amqp==1.4.7
1527
anyjson==0.3.3
28+
## FIXME: could not find svn URL in dependency_links for this package:
29+
apsw==3.8.2-r1
30+
apt-xapian-index==0.45
31+
apturl==0.4.1ubuntu4
1632
argparse==1.2.1
1733
billiard==3.3.0.21
1834
celery==3.1.19
35+
chardet==2.0.1
36+
colorama==0.2.5
37+
command-not-found==0.3
38+
configglue==1.1.2
39+
configobj==4.7.2
40+
coverage==4.0.3
41+
cssselect==0.9.1
42+
cssutils==0.9.10
43+
dbgp==1.1
44+
debtagshw==0.1
45+
defer==1.0.6
46+
dirspec==13.10
47+
dnspython==1.11.1
1948
dominate==2.1.16
49+
dryscrape==1.0
50+
duplicity==0.6.23
51+
fake-factory==0.5.7
52+
feedparser==5.1.3
53+
funcsigs==1.0.0
2054
futures==3.0.3
55+
gunicorn==19.3.0
56+
gyp==0.1
57+
html5lib==0.999
58+
httplib2==0.8
59+
ipaddress==1.0.16
2160
itsdangerous==0.24
2261
kombu==3.0.29
62+
lockfile==0.8
63+
lxml==3.3.3
64+
matplotlib==1.3.1
65+
mechanize==0.2.5
66+
mixer==5.5.7
67+
nemo-emblems==0.0.1
68+
netifaces==0.8
69+
networkx==1.8.1
70+
nose==1.3.1
71+
numpy==1.11.0
72+
oauthlib==0.6.1
73+
oneconf==0.3.7.14.04.1
74+
ordereddict==1.1
75+
paramiko==1.10.1
76+
pexpect==3.1
77+
piston-mini-client==0.7.5
78+
protobuf==2.5.0
79+
pyOpenSSL==0.13
80+
pycrypto==2.6.1
81+
pycups==1.9.66
82+
pycurl==7.19.3
83+
pygobject==3.12.0
84+
pyinotify==0.9.4
85+
pyparsing==2.0.1
86+
pyserial==2.6
87+
pysmbc==1.0.14.1
88+
python-apt==0.9.3.5ubuntu2
2389
python-dateutil==2.4.2
90+
python-debian==0.1.21-nmu2ubuntu2
2491
pytz==2015.7
92+
pyxdg==0.25
93+
redis==2.10.5
94+
reportlab==3.0
95+
repoze.lru==0.6
96+
requests==2.2.1
97+
scipy==0.17.0
98+
sessioninstaller==0.0.0
2599
six==1.10.0
100+
system-service==0.1.6
26101
tzlocal==1.2
102+
uTidylib==0.2
103+
urllib3==1.7.1
104+
vboxapi==1.0
105+
vim-debug==1.5.4
106+
virtualenv==1.11.4
27107
visitor==0.1.2
108+
webkit-server==1.0
109+
wicd==1.7.2.4
28110
wsgiref==0.1.2
111+
xvfbwrapper==0.2.8
112+
zope.interface==4.0.5

0 commit comments

Comments
 (0)