def setUp(self): user_1 = UserFactory(nsid='1234567890@N01') user_2 = UserFactory(nsid='9876543210@N01') account_1 = AccountFactory(user=user_1) account_2 = AccountFactory(user=user_2) self.photos_1 = PhotoFactory.create_batch(2, user=user_1) self.photos_2 = PhotoFactory.create_batch(3, user=user_2) self.private_photo = PhotoFactory(user=user_1, is_private=True) # For comparing with the results: self.public_pks = [p.pk for p in self.photos_1] + \ [p.pk for p in self.photos_2]
def setUp(self): user_1 = UserFactory(nsid='1234567890@N01') user_2 = UserFactory(nsid='9876543210@N01') account_1 = AccountFactory(user=user_1) account_2 = AccountFactory(user=user_2) self.photos_1 = PhotoFactory.create_batch(2, user=user_1) self.photos_2 = PhotoFactory.create_batch(3, user=user_2) self.private_photo = PhotoFactory(user=user_1, is_private=True) # For comparing with the results: self.public_pks = [p.pk for p in self.photos_1] + \ [p.pk for p in self.photos_2]
def test_data(self): "Check format of a single data element." user = FlickrUserFactory(nsid='35034346050@N01') PhotoFactory.create_batch(3, user=user, post_time=make_datetime('2018-01-01 12:00:00')) result = FlickrGenerator(nsid='35034346050@N01').get_photos_per_year() self.assertIn('data', result) self.assertEqual(len(result['data']), 1) self.assertEqual(result['data'][0]['label'], '2018') self.assertEqual(result['data'][0]['value'], 3)
def test_home_context(self): "The Flickr home page sends the correct data to templates" accounts = AccountFactory.create_batch(3) photos_1 = PhotoFactory.create_batch(2, user=accounts[0].user) photos_2 = PhotoFactory.create_batch(2, user=accounts[1].user) response = self.client.get(reverse('flickr:home')) self.assertIn('account_list', response.context) self.assertIn('photo_list', response.context) self.assertEqual(len(response.context['photo_list']), 4) self.assertIn('order', response.context) self.assertEqual(response.context['order'], 'uploaded') # Three accounts, only two of which have Photos: self.assertEqual( [account.pk for account in response.context['account_list']], [1, 2, 3])
def test_home_context(self): "The Flickr home page sends the correct data to templates" accounts = AccountFactory.create_batch(3) photos_1 = PhotoFactory.create_batch(2, user=accounts[0].user) photos_2 = PhotoFactory.create_batch(2, user=accounts[1].user) response = self.client.get(reverse('flickr:home')) self.assertIn('account_list', response.context) self.assertIn('photo_list', response.context) self.assertEqual(len(response.context['photo_list']), 4) self.assertIn('order', response.context) self.assertEqual(response.context['order'], 'uploaded') # Three accounts, only two of which have Photos: self.assertEqual( [account.pk for account in response.context['account_list']], [1,2,3] )
def setUp(self): user_1 = UserFactory(nsid='1234567890@N01') user_2 = UserFactory(nsid='9876543210@N01') account_1 = AccountFactory(user=user_1) account_2 = AccountFactory(user=user_2) self.photos_1 = PhotoFactory.create_batch(2, user=user_1) self.photos_2 = PhotoFactory.create_batch(3, user=user_2) post_time = datetime.datetime(2015, 3, 18, 12, 0, 0).replace(tzinfo=pytz.utc) self.photos_1[0].post_time = post_time self.photos_1[0].save() self.photos_2[1].post_time = post_time + datetime.timedelta(hours=1) self.photos_2[1].save() self.private_photo = PhotoFactory(user=user_1, is_private=True, post_time=post_time)
def setUp(self): self.user_1 = UserFactory(nsid='1234567890@N01') self.user_2 = UserFactory(nsid='9876543210@N01') AccountFactory(user=self.user_1) AccountFactory(user=self.user_2) # Photos taken in 2015 and 2016 for user 1: PhotoFactory.create_batch(3, taken_time=datetime_from_str('2015-01-01 12:00:00'), user=self.user_1) PhotoFactory.create_batch(2, taken_time=datetime_from_str('2016-01-01 12:00:00'), user=self.user_1) # And one for user_2 taken in 2015: PhotoFactory(user=self.user_2, taken_time=datetime_from_str('2015-01-01 12:00:00')) # And one private photo for user_1 taken in 2015: PhotoFactory(user=self.user_1, is_private=True, taken_time=datetime_from_str('2015-01-01 12:00:00'))
def test_photo_detail_templates(self): "Uses the correct templates" account = AccountFactory() photos = PhotoFactory.create_batch(3, user=account.user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': account.user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'flickr/photo_detail.html') self.assertTemplateUsed(response, 'flickr/base.html') self.assertTemplateUsed(response, 'ditto/base.html')
def test_photo_detail_templates(self): "Uses the correct templates" account = AccountFactory() photos = PhotoFactory.create_batch(3, user=account.user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': account.user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'flickr/photo_detail.html') self.assertTemplateUsed(response, 'flickr/base.html') self.assertTemplateUsed(response, 'ditto/base.html')
def test_flickr_photos_several(self): "It should return all Photos from each day." user = UserFactory(nsid='11111111111@N01') account = FlickrAccountFactory(user=user) day_1_photos = PhotoFactory.create_batch(4, user=user, is_private=False, post_time=make_datetime('2017-05-01 12:30:00')) day_2_photos = PhotoFactory.create_batch(3, user=user, is_private=False, post_time=make_datetime('2017-06-01 12:30:00')) r = RecentObjects( (('flickr_photos', user.nsid,),) ) objects = r.get_objects() self.assertEqual(len(objects), 2) self.assertEqual(len(objects[0]['objects']), 3) self.assertEqual(len(objects[1]['objects']), 4)
def setUp(self): self.user_1 = UserFactory(nsid='1234567890@N01') self.user_2 = UserFactory(nsid='9876543210@N01') AccountFactory(user=self.user_1) AccountFactory(user=self.user_2) # Photos taken in 2015 and 2016 for user 1: PhotoFactory.create_batch( 3, taken_time=datetime_from_str('2015-01-01 12:00:00'), user=self.user_1) PhotoFactory.create_batch( 2, taken_time=datetime_from_str('2016-01-01 12:00:00'), user=self.user_1) # And one for user_2 taken in 2015: PhotoFactory(user=self.user_2, taken_time=datetime_from_str('2015-01-01 12:00:00')) # And one private photo for user_1 taken in 2015: PhotoFactory(user=self.user_1, is_private=True, taken_time=datetime_from_str('2015-01-01 12:00:00'))
def test_years(self): "Should include all intermediate years." user = FlickrUserFactory(nsid='35034346050@N01') PhotoFactory(user=user, post_time=make_datetime('2014-01-01 12:00:00')) PhotoFactory.create_batch(3, user=user, post_time=make_datetime('2016-01-01 12:00:00')) PhotoFactory(user=user, post_time=make_datetime('2018-01-01 12:00:00')) result = FlickrGenerator(nsid='35034346050@N01').get_photos_per_year() self.assertIn('data', result) self.assertEqual(result['data'], [ {'label': '2014', 'value': 1}, {'label': '2015', 'value': 0}, {'label': '2016', 'value': 3}, {'label': '2017', 'value': 0}, {'label': '2018', 'value': 1}, ])
def setUp(self): user_1 = UserFactory(nsid='1234567890@N01') user_2 = UserFactory(nsid='9876543210@N01') account_1 = AccountFactory(user=user_1) account_2 = AccountFactory(user=user_2) self.photos_1 = PhotoFactory.create_batch(2, user=user_1) self.photos_2 = PhotoFactory.create_batch(3, user=user_2) taken_time = datetime.datetime(2014, 3, 18, 12, 0, 0).replace( tzinfo=pytz.utc) post_time = datetime.datetime(2015, 3, 18, 12, 0, 0).replace( tzinfo=pytz.utc) self.photos_1[0].taken_time = taken_time self.photos_1[0].post_time = post_time self.photos_1[0].save() self.photos_2[1].taken_time = taken_time + datetime.timedelta(hours=1) self.photos_2[1].post_time = post_time + datetime.timedelta(hours=1) self.photos_2[1].save() self.private_photo = PhotoFactory(user=user_1, is_private=True, post_time = post_time)
def test_flickr_photos(self): "It only returns Public Photos from the correct User" u1 = UserFactory(nsid='11111111111@N01') u2 = UserFactory(nsid='22222222222@N01') FlickrAccountFactory(user=u1) FlickrAccountFactory(user=u2) PhotoFactory.create_batch(3, user=u1, is_private=False) # These shouldn't be returned: PhotoFactory(user=u1, is_private=True) PhotoFactory(user=u2, is_private=False) r = RecentObjects( (('flickr_photos', u1.nsid,),) ) objects = r.get_objects() self.assertEqual(len(objects), 1) for obj in objects: self.assertEqual(obj['objects'][0].user, u1) self.assertFalse(obj['objects'][0].is_private)
def test_photo_detail_context_no_account(self): "Sends correct data to templates when showing a photo with no account" user = UserFactory() photos = PhotoFactory.create_batch(3, user=user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertIn('account', response.context) self.assertIsNone(response.context['account']) self.assertIn('flickr_user', response.context) self.assertEqual(user.pk, response.context['flickr_user'].pk) self.assertIn('photo', response.context) self.assertEqual(photos[1].pk, response.context['photo'].pk)
def test_user_detail_context_no_account(self): "Sends correct data to templates for a User with no Account." user = UserFactory() users_photos = PhotoFactory.create_batch(2, user=user) other_photos = PhotoFactory.create_batch(2) response = self.client.get( reverse('flickr:user_detail', kwargs={'nsid': user.nsid})) self.assertIn('account', response.context) self.assertIsNone(response.context['account']) self.assertIn('flickr_user', response.context) self.assertEqual(user.pk, response.context['flickr_user'].pk) self.assertIn('order', response.context) self.assertEqual(response.context['order'], 'uploaded') self.assertIn('photo_list', response.context) self.assertEqual(len(response.context['photo_list']), 2) # ie, only user's photos. self.assertIn(users_photos[0], response.context['photo_list']) self.assertIn(users_photos[1], response.context['photo_list'])
def test_photo_detail_context(self): "Sends the correct data to templates" account = AccountFactory() photos = PhotoFactory.create_batch(3, user=account.user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': account.user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertIn('account', response.context) self.assertEqual(account.pk, response.context['account'].pk) self.assertIn('flickr_user', response.context) self.assertEqual(account.user.pk, response.context['flickr_user'].pk) self.assertIn('photo', response.context) self.assertEqual(photos[1].pk, response.context['photo'].pk)
def test_photo_detail_context(self): "Sends the correct data to templates" account = AccountFactory() photos = PhotoFactory.create_batch(3, user=account.user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': account.user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertIn('account', response.context) self.assertEqual(account.pk, response.context['account'].pk) self.assertIn('flickr_user', response.context) self.assertEqual(account.user.pk, response.context['flickr_user'].pk) self.assertIn('photo', response.context) self.assertEqual(photos[1].pk, response.context['photo'].pk)
def test_user_detail_context_no_account(self): "Sends correct data to templates for a User with no Account." user = UserFactory() users_photos = PhotoFactory.create_batch(2, user=user) other_photos = PhotoFactory.create_batch(2) response = self.client.get(reverse('flickr:user_detail', kwargs={'nsid': user.nsid})) self.assertIn('account', response.context) self.assertIsNone(response.context['account']) self.assertIn('flickr_user', response.context) self.assertEqual(user.pk, response.context['flickr_user'].pk) self.assertIn('order', response.context) self.assertEqual(response.context['order'], 'uploaded') self.assertIn('photo_list', response.context) self.assertEqual(len(response.context['photo_list']), 2) # ie, only user's photos. self.assertIn(users_photos[0], response.context['photo_list']) self.assertIn(users_photos[1], response.context['photo_list'])
def test_photo_detail_context_no_account(self): "Sends correct data to templates when showing a photo with no account" user = UserFactory() photos = PhotoFactory.create_batch(3, user=user) response = self.client.get(reverse('flickr:photo_detail', kwargs={'nsid': user.nsid, 'flickr_id': photos[1].flickr_id})) self.assertIn('account', response.context) self.assertIsNone(response.context['account']) self.assertIn('flickr_user', response.context) self.assertEqual(user.pk, response.context['flickr_user'].pk) self.assertIn('photo', response.context) self.assertEqual(photos[1].pk, response.context['photo'].pk)
def setUp(self): self.user_1 = UserFactory(nsid='1234567890@N01') self.account_1 = AccountFactory(user=self.user_1) # Three photos, one of which is private. self.photos_1 = PhotoFactory.create_batch(3, user=self.user_1) self.photos_1[0].is_private = True self.photos_1[0].save() self.user_2 = UserFactory(nsid='9876543210@N01') self.account_2 = AccountFactory(user=self.user_2) self.photos_2 = PhotoFactory.create_batch(3, user=self.user_2) # Has three photos, one of them private: self.photoset_1 = PhotosetFactory(user=self.user_1, flickr_id=123456) self.photoset_1.photos.add(*self.photos_1) # Should have two of user_2's three photos: self.photoset_2a = PhotosetFactory(user=self.user_2, flickr_id=98765) self.photoset_2a.photos.add(self.photos_2[0], self.photos_2[1]) # Has all three of user_2's photos: self.photoset_2b = PhotosetFactory(user=self.user_2, flickr_id=55555) self.photoset_2b.photos.add(*self.photos_2)
def setUp(self): self.user_1 = UserFactory(nsid='1234567890@N01') self.account_1 = AccountFactory(user=self.user_1) # Three photos, one of which is private. self.photos_1 = PhotoFactory.create_batch(3, user=self.user_1) self.photos_1[0].is_private = True self.photos_1[0].save() self.user_2 = UserFactory(nsid='9876543210@N01') self.account_2 = AccountFactory(user=self.user_2) self.photos_2 = PhotoFactory.create_batch(3, user=self.user_2) # Has three photos, one of them private: self.photoset_1 = PhotosetFactory(user=self.user_1, flickr_id=123456) self.photoset_1.photos.add(*self.photos_1) # Should have two of user_2's three photos: self.photoset_2a = PhotosetFactory(user=self.user_2, flickr_id=98765) self.photoset_2a.photos.add(self.photos_2[0], self.photos_2[1]) # Has all three of user_2's photos: self.photoset_2b = PhotosetFactory(user=self.user_2, flickr_id=55555) self.photoset_2b.photos.add(*self.photos_2)