def test_fetching_with_ssl_verify(self, mock_urlopen, mock_ssl):
     res = resource.UrlResource(
         {'name': 'file', 'url': 'https:///dummy'})
     try:
         res.copy()
     except:
         pass
     mock_urlopen.assert_called_with('https:///dummy', context=self.ctx)
     self.assertEquals(self.ctx.check_hostname, True)
     self.assertEquals(self.ctx.verify_mode, 1)
 def test_fetching_file_exists_but_used_as_is(self, mock_urlopen):
     """
     It should not download the file, because we didn't
     specify any hash algorithm, so integrity checking is
     implicitly disabled here.
     """
     with open('file', 'w') as f:  # noqa: F841
         pass
     res = resource.UrlResource(
         {'name': 'file', 'url': 'http:///dummy'})
     res.copy()
     mock_urlopen.assert_not_called()
 def test_fetching_disable_ssl_verify(self, mock_urlopen, mock_ssl):
     tools.cfg['common'] = {}
     tools.cfg['common']['ssl_verify'] = "False"
     res = resource.UrlResource(
         {'name': 'file', 'url': 'https:///dummy'})
     try:
         res.copy()
     except:
         pass
     mock_urlopen.assert_called_with('https:///dummy', context=self.ctx)
     self.assertEquals(self.ctx.check_hostname, False)
     self.assertEquals(self.ctx.verify_mode, 0)
     tools.cfg['common']['ssl_verify'] = "True"
     tools.cfg = {}
 def test_fetching_file_exists_fetched_again(self, mock_urlopen, mock_ssl):
     """
     It should download the file again, because available
     file locally doesn't match checksum.
     """
     with open('file', 'w') as f:  # noqa: F841
         pass
     res = resource.UrlResource(
         {'name': 'file', 'url': 'http:///dummy', 'md5': '123456'})
     with self.assertRaises(ConcreateError):
         # Checksum will fail, because the "downloaded" file
         # will not have md5 equal to 123456. We need investigate
         # mocking of requests get calls to do it properly
         res.copy()
     mock_urlopen.assert_called_with('http:///dummy', context='context')
 def test_fetching_bad_status_code(self, mock_urlopen):
     res = resource.UrlResource(
         {'name': 'file', 'url': 'http:///dummy'})
     with self.assertRaises(ConcreateError):
         res.copy()