def test_merge_images_calls_expected_methods(self, ms_save_generic, ms_item_exists, ms_do_image_merge, ms_get_merge_method, ms_get_merge_type, ms_get_image_paths_and_snap_id): ms_item_exists.return_value = False the_paths_dict = {'snap_id': 'x', 'img_out_filename': 'y', 'img_out_path': 'z'} ms_get_image_paths_and_snap_id.return_value = the_paths_dict ms_get_merge_type.return_value = 'waldorf' ms_get_merge_method.return_value = int ms.merge_images('a', 'b', 'c', 'd', 'e') ms_item_exists.assert_called_once_with('b', 'picture') ms_get_image_paths_and_snap_id.assert_called_once_with('a', 'c', 'd') ms_get_merge_type.assert_called_once_with('e') ms_get_merge_method.assert_called_once_with('waldorf') ms_do_image_merge.assert_called_once_with(the_paths_dict, int) ms_save_generic.assert_called_once_with({'_id': 'd', 'type': 'picture', 'source': 'merge', 'source_image_id_1': 'a', 'source_image_id_2': 'c', 'merge_type': 'waldorf', 'group_id': 'e', 'snap_id': 'x', 'filename': 'y', 'uri': 'z', 'created': ANY}, 'picture')
def test_merge_images_calls_expected_methods( self, ms_save_generic, ms_item_exists, ms_do_image_merge, ms_get_merge_method, ms_get_merge_type, ms_get_image_paths_and_snap_id): ms_item_exists.return_value = False the_paths_dict = { 'snap_id': 'x', 'img_out_filename': 'y', 'img_out_path': 'z' } ms_get_image_paths_and_snap_id.return_value = the_paths_dict ms_get_merge_type.return_value = 'waldorf' ms_get_merge_method.return_value = int ms.merge_images('a', 'b', 'c', 'd', 'e') ms_item_exists.assert_called_once_with('b', 'picture') ms_get_image_paths_and_snap_id.assert_called_once_with('a', 'c', 'd') ms_get_merge_type.assert_called_once_with('e') ms_get_merge_method.assert_called_once_with('waldorf') ms_do_image_merge.assert_called_once_with(the_paths_dict, int) ms_save_generic.assert_called_once_with( { '_id': 'd', 'type': 'picture', 'source': 'merge', 'source_image_id_1': 'a', 'source_image_id_2': 'c', 'merge_type': 'waldorf', 'group_id': 'e', 'snap_id': 'x', 'filename': 'y', 'uri': 'z', 'created': ANY }, 'picture')
def test_merge_images_with_primary_image(self): class MockImage(object): pass group_id = uuid.uuid4() snap_id = uuid.uuid4() ms.save_picture_document = Mock() ms.find_picture = Mock( return_value={"filename": "whatever", "group_id": str(group_id), "snap_id": str(snap_id)} ) ms.get_group_document = Mock(return_value={"_id": str(group_id), "merge_type": "canine"}) ms.picture_exists = Mock(return_value=False) the_mock_image = MockImage() Image.open = Mock(return_value=the_mock_image) MockImage.convert = Mock(return_value=the_mock_image) MockImage.save = Mock() ImageChops.canine = Mock(return_value=the_mock_image) img1_primary_id_in = uuid.uuid4() img1_primary_filename_in = "whatever" img1_primary_path_in = ms.build_picture_path(picture_name=img1_primary_filename_in, snap_id=snap_id) img1_alternate_id_in = uuid.uuid4() img2_id_in = uuid.uuid4() img2_filename_in = "whatever" img2_path_in = ms.build_picture_path(picture_name=img2_filename_in, snap_id=snap_id) img_id_out = uuid.uuid4() img_filename_out = ms.build_picture_name(img_id_out) pic_path_out = ms.build_picture_path(picture_name=img_filename_out, snap_id=snap_id) test_img_dict_out = { "_id": str(img_id_out), "type": "picture", "source": "merge", "source_image_id_1": str(img1_primary_id_in), "source_image_id_2": str(img2_id_in), "merge_type": "canine", "group_id": str(group_id), "snap_id": str(snap_id), "filename": img_filename_out, "uri": ANY, "created": ANY, } ms.merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in, img_id_out, group_id) ms.get_group_document.assert_called_once_with(group_id) ms.picture_exists.assert_called_once_with(img1_alternate_id_in) find_picture_calls = [call(str(img1_primary_id_in)), call(str(img2_id_in))] ms.find_picture.assert_has_calls(find_picture_calls) image_open_calls = [call(img1_primary_path_in), call(img2_path_in)] Image.open.assert_has_calls(image_open_calls) convert_calls = [call("RGBA"), call("RGBA")] MockImage.convert.assert_has_calls(convert_calls) ImageChops.canine.assert_called_once_with(the_mock_image, the_mock_image) MockImage.save.assert_called_once_with(pic_path_out) ms.save_picture_document.assert_called_once_with(test_img_dict_out)
def test_merge_images_with_primary_image(self): class MockImage(object): pass group_id = uuid.uuid4() snap_id = uuid.uuid4() ms.save_picture_document = Mock() ms.find_picture = Mock( return_value={ 'filename': 'whatever', 'group_id': str(group_id), 'snap_id': str(snap_id) }) ms.get_group_document = Mock(return_value={ '_id': str(group_id), 'merge_type': 'canine' }) ms.picture_exists = Mock(return_value=False) the_mock_image = MockImage() Image.open = Mock(return_value=the_mock_image) MockImage.convert = Mock(return_value=the_mock_image) MockImage.save = Mock() ImageChops.canine = Mock(return_value=the_mock_image) img1_primary_id_in = uuid.uuid4() img1_primary_filename_in = 'whatever' img1_primary_path_in = ms.build_picture_path( picture_name=img1_primary_filename_in, snap_id=snap_id) img1_alternate_id_in = uuid.uuid4() img2_id_in = uuid.uuid4() img2_filename_in = 'whatever' img2_path_in = ms.build_picture_path(picture_name=img2_filename_in, snap_id=snap_id) img_id_out = uuid.uuid4() img_filename_out = ms.build_picture_name(img_id_out) pic_path_out = ms.build_picture_path(picture_name=img_filename_out, snap_id=snap_id) test_img_dict_out = { '_id': str(img_id_out), 'type': 'picture', 'source': 'merge', 'source_image_id_1': str(img1_primary_id_in), 'source_image_id_2': str(img2_id_in), 'merge_type': 'canine', 'group_id': str(group_id), 'snap_id': str(snap_id), 'filename': img_filename_out, 'uri': ANY, 'created': ANY } ms.merge_images(img1_primary_id_in, img1_alternate_id_in, img2_id_in, img_id_out, group_id) ms.get_group_document.assert_called_once_with(group_id) ms.picture_exists.assert_called_once_with(img1_alternate_id_in) find_picture_calls = [ call(str(img1_primary_id_in)), call(str(img2_id_in)) ] ms.find_picture.assert_has_calls(find_picture_calls) image_open_calls = [call(img1_primary_path_in), call(img2_path_in)] Image.open.assert_has_calls(image_open_calls) convert_calls = [call('RGBA'), call('RGBA')] MockImage.convert.assert_has_calls(convert_calls) ImageChops.canine.assert_called_once_with(the_mock_image, the_mock_image) MockImage.save.assert_called_once_with(pic_path_out) ms.save_picture_document.assert_called_once_with(test_img_dict_out)