Ejemplo n.º 1
0
    def test_day_paginator_two_dates(self):
        # Start
        first_photo = Photo()
        first_photo.created_time = date(2013, 03, 01)

        db.session.add(first_photo)
        db.session.commit()

        self.assertIn(first_photo, db.session)

        # End
        second_photo = Photo()
        second_photo.created_time = date(2013, 03, 15)

        db.session.add(second_photo)
        db.session.commit()

        self.assertIn(second_photo, db.session)

        # Create day pagination
        pagination = Pagination(2013, 03, 01)

        self.assertEqual(1, pagination.page)
        self.assertEqual(15, pagination.pages)
        self.assertFalse(pagination.has_prev)
        self.assertTrue(pagination.has_next)

        # Create month pagination
        pagination = Pagination(2013, 03)

        self.assertEqual(3, pagination.page)
        self.assertEqual(1, pagination.pages)
        self.assertFalse(pagination.has_prev)
        self.assertFalse(pagination.has_next)

        # Create year pagination
        pagination = Pagination(2013)

        self.assertEqual(2013, pagination.page)
        self.assertEqual(1, pagination.pages)
        self.assertFalse(pagination.has_prev)
        self.assertFalse(pagination.has_next)

        # Widen range
        second_photo.created_time = date(2013, 03, 31)
        db.session.commit()

        pagination = Pagination(2013, 03, 01)

        self.assertEqual(1, pagination.page)
        self.assertEqual(31, pagination.pages)
        self.assertFalse(pagination.has_prev)
        self.assertTrue(pagination.has_next)
Ejemplo n.º 2
0
    def test_year_paginator(self):
        # Set up some mock objects
        first_photo = Photo()
        first_photo.created_time = date(2012, 02, 29)

        db.session.add(first_photo)
        db.session.commit()

        self.assertIn(first_photo, db.session)

        # Year two
        second_photo = Photo()
        second_photo.created_time = date(2013, 03, 01)

        db.session.add(second_photo)
        db.session.commit()

        self.assertIn(second_photo, db.session)

        # Year three
        third_photo = Photo()
        third_photo.created_time = date(2014, 03, 01)

        db.session.add(third_photo)
        db.session.commit()

        self.assertIn(third_photo, db.session)

        # Create pagination after photos
        pagination = Pagination(2012)

        self.assertEqual(3, pagination.pages)

        # Check these before and after iterating through paginator
        self.assertFalse(pagination.has_prev)
        self.assertTrue(pagination.has_next)

        # We should get 3 photos back with the expected date range
        expected_years = [
            (first_photo, date(2012, 02, 29), date(2013, 02, 28)),
            (second_photo, date(2013, 03, 01), date(2014, 02, 28)),
            (third_photo, date(2014, 03, 01), date(2015, 02, 28))
        ]
        for expected, actual in izip(expected_years, pagination.iter_pages()):
            self.assertEqual(expected, actual)
            self.assertEqual(expected[1].year, pagination.page)

        self.assertTrue(pagination.has_prev)
        self.assertFalse(pagination.has_next)
Ejemplo n.º 3
0
    def test_one_year_paginator(self):
        photo = Photo()
        photo.created_time = date(2012, 02, 29)

        db.session.add(photo)
        db.session.commit()

        self.assertIn(photo, db.session)

        # This should only run once since the db only has 1 year initially
        pagination = Pagination(2012)
        self.assertEqual(1, len(list(pagination.iter_pages())))
Ejemplo n.º 4
0
    def test_create_photo(self):
        # Start with photo
        photo = Photo()
        photo.instagram_id = '757677846642235453_1134805'
        photo.caption = '126. Who needs fireworks anyway'
        photo.created_time = datetime(2012, 02, 29)
        photo.featured_on = 'Josh Johnson; #JJ'
        photo.link = 'http://instagram.com/p/qDVDHkyxvS/'

        db.session.add(photo)
        db.session.commit()

        self.assertIn(photo, db.session)

        # Mock some images
        hi_img = Image()
        hi_img.height = 640
        hi_img.width = 640
        hi_img.url = 'http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/10522310_677385995673625_267718762_n.jpg'
        hi_img.type = 'standard_resolution'

        low_img = Image()
        low_img.height = 306
        low_img.width = 306
        low_img.url = 'http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/10522310_677385995673625_267718762_a.jpg'
        low_img.type = 'low_resolution'

        thumb_img = Image()
        thumb_img.height = 150
        thumb_img.width = 150
        thumb_img.url = 'http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/10522310_677385995673625_267718762_s.jpg'
        thumb_img.type = 'thumbnail'

        images = [hi_img, low_img, thumb_img]
        db.session.add_all(images)
        db.session.commit()

        self.assertTrue(all(i in db.session for i in images))

        # Connect images to photo
        photo.images.extend(images)
        db.session.commit()

        self.assertTrue(all(i in photo.images for i in images))
        self.assertTrue(all(photo is i.photo for i in images))

        # Mock location and tag
        loc = Location()
        loc.instagram_id = '1'
        loc.name = 'Dogpatch Labs'
        loc.latitude = 37.782
        loc.longitude = -122.387

        db.session.add(loc)
        db.session.commit()

        self.assertIn(loc, db.session)

        tag = Tag()
        tag.name = 'july4th'

        db.session.add(tag)
        db.session.commit()

        self.assertIn(tag, db.session)

        # Connect location and tag to photo
        photo.locations.append(loc)
        photo.tags.append(tag)

        db.session.commit()

        self.assertIn(loc, photo.locations)
        self.assertIn(tag, photo.tags)
        self.assertIn(photo, loc.photos)
        self.assertIn(photo, tag.photos)