def test_create_job_fails(self, mock_get_job_links, mock_create_job_listing):

        response = example_response
        mock_job_links = [mock.Mock(), mock.Mock(), mock.Mock()]
        mock_get_job_links.return_value = mock_job_links
        mock_jobs = [mock.Mock(), None, mock.Mock()]
        class Test:
            def __init__(self):
                self.calls = 0
            def __call__(self, response):
                if self.calls != 1:
                    self.calls += 1
                    return mock_jobs[self.calls - 1]
                else:
                    self.calls += 1
                    raise scraping.JobCreationFailed()
        mock_create_job_listing.side_effect = Test()
        
        scraping.populate_db(response)

        mock_get_job_links.assert_called_once_with(response)
        mock_create_job_listing.assert_has_calls([mock.call(i) for i in mock_job_links])
        for job in mock_jobs:
            if job != None:
                job.save.assert_called_once_with()
    def test_main(self, mock_get_job_links, mock_create_job_listing):

        response = example_response # defined earlier
        mock_job_links = [mock.Mock(), mock.Mock()]
        mock_get_job_links.return_value = mock_job_links
        mock_jobs = [mock.Mock(), mock.Mock()]
        mock_create_job_listing.side_effect = mock_jobs
        
        scraping.populate_db(response)

        mock_get_job_links.assert_called_once_with(response)
        mock_create_job_listing.assert_has_calls([mock.call(i) for i in mock_job_links])
        for job in mock_jobs:
            job.save.assert_called_once_with()