def test_download(self, m_check, m_need):
        """Test actual download."""
        m_check.return_value = False
        m_need.return_value = True
        downloader = Downloader()
        source = 'file:///b.txt'
        destination = '/a.txt'

        tmpfile = tempfile.SpooledTemporaryFile(max_size=1024000, mode='wb')
        tmpfile.write(b'source content')
        tmpfile.seek(0)

        with mock.patch('cities_light.downloader.urlopen',
                        return_value=tmpfile):
            module_name = '{}.b.open'.format(__name__)
            mock_open = mock.mock_open()
            # The downoader.needs_downloading will return true and last three
            # lines of downloader.download will copy the source to sestination
            with mock.patch(module_name, mock_open):
                self.assertTrue(downloader.download(
                    source,
                    destination,
                    False))
                handle = mock_open()
                handle.write.assert_called_once_with(b'source content')
Ejemplo n.º 2
0
    def test_not_download(self):
        """Tests actual not download."""
        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = True
            downloader = Downloader()
            source = 'file:///b.txt'
            destination = '/a.txt'
            with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                downloader.download(source, destination)
                uo_mock.assert_not_called()

        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = False
            with mock.patch.object(Downloader, 'needs_downloading') as n:
                n.return_value = False
                downloader = Downloader()
                source = 'file:///b.txt'
                destination = '/a.txt'
                with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                    downloader.download(source, destination)
                    uo_mock.assert_not_called()
Ejemplo n.º 3
0
 def test_download_calls_source_matches_destination(self, m_check):
     """Test if download() checks for source and destination match."""
     m_check.return_value = True
     downloader = Downloader()
     source = 'file:///a.txt'
     destination = '/a.txt'
     # The downloader.download will return false
     # as source and destination are same
     # The downloader.source_matches_destination will return
     # true and downloader.download will return false
     self.assertFalse(downloader.download(source, destination, False))
     m_check.assert_called_with(source, destination)
Ejemplo n.º 4
0
 def test_download_calls_needs_downloading(self, m_check, m_need):
     """Test if download() checks if source should be downloaded."""
     m_check.return_value = False
     m_need.return_value = False
     downloader = Downloader()
     source = 'file:///a.txt'
     destination = '/a.txt'
     # Here dowaloder.needs_downloading() will return false
     # as the time of modifiaction of dest>= time of source
     # and the size od source and destination are same
     # and downloader.download will return false
     self.assertFalse(downloader.download(source, destination, False))
     m_check.assert_called_with(source, destination)
     m_need.assert_called_with(source, destination, False)
    def test_not_download(self):
        """Tests actual not download."""
        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = True
            downloader = Downloader()
            source = 'file:///b.txt'
            destination = '/a.txt'
            with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                downloader.download(source, destination)
                uo_mock.assert_not_called()

        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = False
            with mock.patch.object(Downloader, 'needs_downloading') as n:
                n.return_value = False
                downloader = Downloader()
                source = 'file:///b.txt'
                destination = '/a.txt'
                # Here copy of b has been made in above function,the
                # downloder.needs_downloading() will return false
                # and no download will happen
                with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                    downloader.download(source, destination)
                    uo_mock.assert_not_called()
Ejemplo n.º 6
0
    def test_not_download(self):
        """Tests actual not download."""
        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = True
            downloader = Downloader()
            source = 'file:///b.txt'
            destination = '/a.txt'
            with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                downloader.download(source, destination)
                uo_mock.assert_not_called()

        with mock.patch.object(Downloader, 'source_matches_destination') as m:
            m.return_value = False
            with mock.patch.object(Downloader, 'needs_downloading') as n:
                n.return_value = False
                downloader = Downloader()
                source = 'file:///b.txt'
                destination = '/a.txt'
                # Here copy of b has been made in above function,the
                # downloder.needs_downloading() will return false
                # and no download will happen
                with mock.patch('cities_light.downloader.urlopen') as uo_mock:
                    downloader.download(source, destination)
                    uo_mock.assert_not_called()
Ejemplo n.º 7
0
 def test_download_calls_needs_downloading(self, m_check, m_need):
     """Test if download() checks if source should be downloaded."""
     m_check.return_value = False
     m_need.return_value = False
     downloader = Downloader()
     source = 'file:///a.txt'
     destination = '/a.txt'
     self.assertFalse(
         downloader.download(
             source,
             destination,
             False
         )
     )
     m_check.assert_called_with(source, destination)
     m_need.assert_called_with(source, destination, False)
 def test_download_calls_source_matches_destination(self, m_check):
     """Test if download() checks for source and destination match."""
     m_check.return_value = True
     downloader = Downloader()
     source = 'file:///a.txt'
     destination = '/a.txt'
     # The downloader.download will return false
     # as source and destination are same
     # The downloader.source_matches_destination will return
     # true and downloader.download will return false
     self.assertFalse(
         downloader.download(
             source,
             destination,
             False
         )
     )
     m_check.assert_called_with(source, destination)
 def test_download_calls_needs_downloading(self, m_check, m_need):
     """Test if download() checks if source should be downloaded."""
     m_check.return_value = False
     m_need.return_value = False
     downloader = Downloader()
     source = 'file:///a.txt'
     destination = '/a.txt'
     # Here dowaloder.needs_downloading() will return false
     # as the time of modifiaction of dest>= time of source
     # and the size od source and destination are same
     # and downloader.download will return false
     self.assertFalse(
         downloader.download(
             source,
             destination,
             False
         )
     )
     m_check.assert_called_with(source, destination)
     m_need.assert_called_with(source, destination, False)
Ejemplo n.º 10
0
    def test_download(self, m_check, m_need):
        """Test actual download."""
        m_check.return_value = False
        m_need.return_value = True
        downloader = Downloader()
        source = 'file:///b.txt'
        destination = '/a.txt'

        tmpfile = tempfile.SpooledTemporaryFile(max_size=1024000, mode='wb')
        tmpfile.write(b'source content')
        tmpfile.seek(0)

        with mock.patch('cities_light.downloader.urlopen',
                        return_value=tmpfile):
            module_name = '{}.b.open'.format(__name__)
            mock_open = mock.mock_open()
            with mock.patch(module_name, mock_open):
                self.assertTrue(downloader.download(
                    source,
                    destination,
                    False))
                handle = mock_open()
                handle.write.assert_called_once_with(b'source content')