Beispiel #1
0
 def test_raises_error_on_bad_URL(self):
     httpretty.register_uri(httpretty.GET,
                            "http://example.com/cats.png",
                            body="not found",
                            status=404)
     with self.assertRaises(IOError):
         f = cache.WebImage('http://example.com/cats.png')
Beispiel #2
0
 def test_removes_oldest_file_when_full(self):
     image_size = cache.WebImage('http://example.com/a.png').get_size()
     print image_size
     c = cache.ImageCache(image_size + 1)
     a_url = 'http://example.com/a.png'
     b_url = 'http://example.com/b.png'
     a = c.get_image(a_url)
     b = c.get_image(b_url)
     self.assertFalse(a_url in c.images)
     self.assertTrue(b_url in c.images)
Beispiel #3
0
 def test_is_fresh_if_no_last_modified_or_etag(self):
     httpretty.register_uri(httpretty.GET,
                            "http://example.com/cats.png",
                            body=self.image_content,
                            max_age=300)
     httpretty.register_uri(httpretty.HEAD,
                            "http://example.com/cats.png",
                            max_age=300)
     f = cache.WebImage('http://example.com/cats.png')
     time.time.tm = 1400
     self.assertFalse(f.is_fresh())
Beispiel #4
0
 def test_removes_more_than_one_file_if_needed(self):
     image_size = cache.WebImage('http://example.com/a.png').get_size()
     c = cache.ImageCache(image_size + 1)
     tiny_url_a = 'http://example.com/tiny/a.png'
     tiny_url_b = 'http://example.com/tiny/b.png'
     url_d = 'http://example.com/a.png'
     a = c.get_image(tiny_url_a)
     b = c.get_image(tiny_url_b)
     d = c.get_image(url_d)
     self.assertEqual(len(c.images), 1)
     self.assertFalse(tiny_url_a in c.images)
     self.assertFalse(tiny_url_b in c.images)
     self.assertTrue(url_d in c.images)
Beispiel #5
0
 def test_is_fresh_on_recheck_with_last_modified_changed(self):
     httpretty.register_uri(httpretty.GET,
                            "http://example.com/cats.png",
                            body=self.image_content,
                            max_age=300,
                            last_modified=formatdate(200.0))
     httpretty.register_uri(httpretty.HEAD,
                            "http://example.com/cats.png",
                            max_age=300,
                            last_modified=formatdate(300.0))
     f = cache.WebImage('http://example.com/cats.png')
     time.time.tm = 1400
     self.assertFalse(f.is_fresh())
Beispiel #6
0
 def test_is_fresh_while_within_maxage(self):
     httpretty.register_uri(httpretty.GET,
                            "http://example.com/cats.png",
                            body=self.image_content,
                            max_age=300,
                            last_modified=formatdate(200.0))
     httpretty.register_uri(httpretty.HEAD,
                            "http://example.com/cats.png",
                            max_age=300,
                            last_modified=formatdate(300.0))
     f = cache.WebImage('http://example.com/cats.png')
     time.time.tm = 1200
     self.assertTrue(f.is_fresh())
Beispiel #7
0
 def test_basic_load(self):
     httpretty.register_uri(httpretty.GET,
                            "http://example.com/cats.png",
                            body=self.image_content)
     f = cache.WebImage('http://example.com/cats.png')
Beispiel #8
0
 def test_removes_a_file_when_full(self):
     image_size = cache.WebImage('http://example.com/a.png').get_size()
     c = cache.ImageCache(image_size + 1)
     a = c.get_image('http://example.com/a.png')
     b = c.get_image('http://example.com/b.png')
     self.assertEqual(len(c.images), 1)