Exemple #1
0
 def test_list_images(self):
     """Test the 'mock' database interface."""
     
     image_list = list_images(3)
     
     self.assertEqual(3, len(image_list))        
     self.assertEqual(('cycling.jpg', '2014-01-14', '*****@*****.**', ['cool photo', 'thx']), image_list[0])
    def testImagesPresent(self):
        """As a visitor to the site, when I load the home page I 
        see three images displayed, each
        labelled with a date, a user name and a title. """

        driver = self.driver
        driver.get(self.base_url)
        
        images = driver.find_elements_by_tag_name('img')
        
        # expect to find three images
        self.assertEqual(3, len(images), "Wrong number of images found")
        
        flowtows = driver.find_elements_by_class_name('flowtow')
        
        image_list = mock.list_images(3)
        
        self.assertEqual(3, len(flowtows))
        
        # each contains the image, date, author and comments
        for index in range(3):
            div = flowtows[index]
            (path, date, user, comments) = image_list[index]
            
            self.assertIn(date, div.text)
            self.assertIn(user, div.text)
            for c in comments:
                self.assertIn(c, div.text)
                
            # look for just one image
            img = div.find_elements_by_tag_name('img')
            self.assertEqual(1, len(img))
            
            # can we actually get the image 
            # find the URL
            url = img[0].get_attribute('src')
            # try requesting it and test the content-type header returned
            h = urlopen(url)
            self.assertEqual('image/jpeg', h.getheader('content-type'))
            h.close()