1. Julian Moritz
  2. django-photos

Commits

Julian Moritz  committed 23e705d

made tests running

  • Participants
  • Parent commits 658d28e
  • Branches default

Comments (0)

Files changed (7)

File MANIFEST.in

View file
 include README.rst
 include NEWS.txt
+include src/photos/tests/static/*

File src/photos/admin.py

View file
 from django.contrib import admin
-from photos.models import Photo, Gallery
+from photos.models import Photo, Album
+from django.utils.translation import ugettext as _
 
 class BaseAdmin():
     def queryset(self, request):
     date_hierarchy = 'timestamp_created'
     description = _('Manage your uploaded photos.')
 
-admin.site.register(PhotoAdmin, Photo)
+admin.site.register(Photo, PhotoAdmin)
 
-class GalleryAdmin(admin.ModelAdmin, BaseAdmin):
+class AlbumAdmin(admin.ModelAdmin, BaseAdmin):
     list_filter = ('display', 'timestamp_created', )
     date_hierarchy = 'timestamp_created'
     description = _('Manage your galleries.')
     
-admin.site.register(GalleryAdmin, Gallery)
+admin.site.register(Album, AlbumAdmin)

File src/photos/models.py

View file
     timestamp_created = models.DateTimeField(_('Timestamp created'), auto_now_add=True, editable=False)
     timestamp_edited = models.DateTimeField(_('Timestamp edited'), auto_now=True, editable=False)
     
+    def __unicode__(self):
+        return self.photo.name
+    
     class Meta(object):
         verbose_name = _('Photo')
         verbose_name_plural = _('Photos')

File src/photos/templates/photos/photo_detail.html

View file
 {% extends "photos/base.html" %}
 {% block title %}{{block.super}} - Photo{% endblock %}
+{% block content %}
+Picture!
+{% endblock %}

File src/photos/tests/tests.py

View file
     def setUp(self):
         user, created = User.objects.get_or_create(username='anna')
         album = Album()
+        album.user = user
         album.save()
         photo1 = Photo(photo='a.jpg', description='a')
+        photo1.user = user
         photo1.save()
+        
+        photo2 = Photo(photo='b.jpg', description='b')
+        photo2.user = user
+        photo2.save()
+        
+        album.photos.add(photo1)
+        album.photos.add(photo2)
+        album.save()        
     
     def check_url(self, url, status_code=200):
         client = Client()
         response = client.get(url)
-        self.assertEqual(response.status_code, status_code)
+        msg = '%s != %s in %s' % (response.status_code, status_code, url)
+        self.assertEqual(response.status_code, status_code, msg)
     
     def test_album_list(self):
         url = reverse('albums')
         self.check_url(url, 200)
         
     def test_album_list_userid(self):
-        user = User.objects.get(username='anna')
+        user = User.objects.latest('id')
         url = reverse('albums-userid', args=(user.id, ))
         self.check_url(url, 200)
         
     def test_album_list_username(self):
-        url = reverse('albums-username', args=(), kwargs={'username': 'anna'})
+        user = User.objects.latest('id')
+        url = reverse('albums-username', args=(), kwargs={'username': user.username})
         self.check_url(url, 200)
         
     def test_album_detail(self):
         self.check_url(url, 200)
         
     def test_photo_list_userid(self):
-        user = User.objects.get(username='anna')
+        user = User.objects.latest('id')
         url = reverse('photos-userid', args=(user.id, ))
         self.check_url(url, 200)
         
     def test_photo_list_username(self):
-        url = reverse('photos-username', args=(), kwargs={'username': 'anna'})
+        user = User.objects.latest('id')
+        url = reverse('photos-username', args=(), kwargs={'username': user.username})
         self.check_url(url, 200)
         
     def test_photo_detail(self):
-        album = Photo.objects.latest('id')
-        url = reverse('photo-detail', args=(album.id, ))
+        photo = Photo.objects.latest('id')
+        url = reverse('photo-detail', args=(photo.id, ))
+        print Photo.objects.filter(display=True)
         self.check_url(url, 200)
     

File src/photos/tests/urls.py

View file
 from django.views.generic.list_detail import object_detail
 from django.conf.urls.defaults import *
 from django.conf import settings
+from django.contrib import admin
+admin.autodiscover()
 
 urlpatterns = patterns('',
     url(r'^photos/', include('photos.urls')),
-    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT})
+    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
+    (r'^admin/', include(admin.site.urls))
 )
+
+

File src/photos/urls.py

View file
 ALBUM_DETAIL_DICT = {'queryset': Album.objects.filter(display=True)}
 PHOTO_DETAIL_DICT = {'queryset': Photo.objects.filter(display=True)}
 
-
 urlpatterns = patterns('',
     url(r'^albums/$', album_list, name='albums'),
     url(r'^albums/(?P<user_id>\d+)/$', album_list, name='albums-userid'),
     url(r'^photos/$', photo_list, name='photos'),
     url(r'^photos/(?P<user_id>\d+)/$', photo_list, name='photos-userid'),
     url(r'^photos/(?P<username>.+)/', photo_list, name='photos-username'),
-    url(r'^photos/(?P<album_id>\d+)/(?P<object_id>\d+)/$', photo_detail, name='photo-album-detail'),
-    url(r'^photos/(?P<object_id>\d)/$', object_detail, PHOTO_DETAIL_DICT, name='photo-detail')
+    url(r'^photo/(?P<object_id>\d+)/$', object_detail, PHOTO_DETAIL_DICT, name='photo-detail'),
+    url(r'^photos/(?P<album_id>\d+)/(?P<object_id>\d+)/$', photo_detail, name='photo-album-detail')
 )