def test_generate_preference(self, mock_get_image, mock_list_images, mock_fit): """ Test that a prefered placeholder image is chosen and generated correctly. """ mock_list_images.return_value = ['source/02.jpg', ] mock_fit.return_value = MagicMock() form = PlaceholderForm({'height': '400', 'width': '400'}) form.is_valid() form.generate(preference='02') # Called with the right "random" image? mock_get_image.assert_called_with('source/02.jpg') # Called with the right dimensions to fit? self.assertTrue((400, 400) in mock_fit.call_args[0])
def test_generate_random(self, mock_get_image, mock_list_images, mock_fit, mock_choice): """ Test that a random choice placeholder image is chosen and generated correctly. """ mock_list_images.return_value = ['source/01.jpg', ] mock_choice.return_value = 'source/01.jpg' mock_fit.return_value = MagicMock() form = PlaceholderForm({'height': '300', 'width': '200'}) form.is_valid() form.generate() # Called with the right "random" image? mock_get_image.assert_called_with('source/01.jpg') # Called with the right dimensions to fit? self.assertTrue((300, 200) in mock_fit.call_args[0])
def test_init_oob_dimensions(self): """ Test that out-of-bounds dimensions are handled correctly. """ form = PlaceholderForm({'height': '2001', 'width': '2001'}) self.assertFalse(form.is_valid())
def test_init_valid_fimensions(self): """ Test that decimal width and height are valid """ form = PlaceholderForm({'height': '300', 'width': '200'}) self.assertTrue(form.is_valid())
def test_init_invalid_dimensions(self): """ Test that invalid dimensions are handled correctly """ form = PlaceholderForm({'height': 'def', 'width': 'abc'}) self.assertFalse(form.is_valid())