def test_rm_on_an_existing_file(self, mock_os, mock_path):
        mock_path.isfile.return_value = True

        service = RemovalService()
        service.rm("existing filename")

        mock_os.remove.assert_called_with("existing filename")
    def test_rm_on_a_nonexistent_file(self, mock_os, mock_path):
        service = RemovalService()

        mock_path.isfile.return_value = False

        service.rm("any_path")

        self.assertFalse(
            mock_os.remove.called,
            "The remove call should not go through on a non-existent file")
Example #3
0
 def test_upload_complete(self, mock_rm):
     # build our dependencies
     removal_service = RemovalService()
     reference = UploadService(removal_service)
     # call upload_complete, which should, in turn, call `rm`:
     reference.upload_complete("my uploaded file")
     # check that it called the rm method of any RemovalService
     mock_rm.assert_called_with("my uploaded file")
     # check that it called the rm method of _our_ removal_service
     removal_service.rm.assert_called_with("my uploaded file")
Example #4
0
    def test_rm(self, mock_os, mock_path):
        # instantiate our service
        reference = RemovalService()

        # set up the mock
        mock_path.isfile.return_value = False

        reference.rm("any path")

        # test that the remove call was NOT called.
        self.assertFalse(mock_os.remove.called,
                         "Failed to not remove the file if not present.")

        # make the file 'exist'
        mock_path.isfile.return_value = True

        reference.rm("any path")

        mock_os.remove.assert_called_with("any path")
Example #5
0
 def test_rm(self, mock_os, mock_path):
     # instantiate our service
     reference = RemovalService()
     # set up the mock
     mock_path.isfile.return_value = False
     reference.rm("any path")
     # test that the remove call was NOT called.
     self.assertFalse(mock_os.remove.called, "Failed to not remove the file if not present.")
     # make the file 'exist'
     mock_path.isfile.return_value = True
     reference.rm("any path")
     mock_os.remove.assert_called_with("any path")