Source

django-photos / src / photos / tests / __init__.py

Diff from to

src/photos/tests/__init__.py

+from django.test import TestCase
+from django.test.client import Client
+from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
+from photos.models import Photo, Album
+
+class TemplateTagTest(TestCase):
+    pass
+
+class ViewTest(TestCase):
+    def setUp(self):
+        user, created = User.objects.get_or_create(username='anna')
+        album = Album()
+        album.user = user
+        album.save()
+        photo1 = Photo(photo='a.jpg')
+        photo1.user = user
+        photo1.save()
+        
+        photo2 = Photo(photo='b.jpg')
+        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)
+        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.latest('id')
+        url = reverse('albums-userid', args=(user.id, ))
+        self.check_url(url, 200)
+        
+    def test_album_list_username(self):
+        user = User.objects.latest('id')
+        url = reverse('albums-username', args=(), kwargs={'username': user.username})
+        self.check_url(url, 200)
+        
+    def test_album_detail(self):
+        album = Album.objects.latest('id')
+        url = reverse('album-detail', args=(album.id, ))
+        self.check_url(url, 200)
+        
+    def test_photo_list(self):
+        url = reverse('photos')
+        self.check_url(url, 200)
+        
+    def test_photo_list_userid(self):
+        user = User.objects.latest('id')
+        url = reverse('photos-userid', args=(user.id, ))
+        self.check_url(url, 200)
+        
+    def test_photo_list_username(self):
+        user = User.objects.latest('id')
+        url = reverse('photos-username', args=(), kwargs={'username': user.username})
+        self.check_url(url, 200)
+        
+    def test_photo_detail(self):
+        photo = Photo.objects.latest('id')
+        url = reverse('photo-detail', args=(photo.id, ))
+        self.check_url(url, 200)
+        
+    def test_photo_name(self):
+        photo = Photo.objects.get(id=1)
+        self.assertEqual(photo.name, 'a')
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.