Beispiel #1
0
 def test_compressed_text_from_url(self, mock_url_call, mock_gzip_read):
     mock_gzip_read.return_value = "Hello World"
     mock_url_call.return_value = mock.MagicMock(
         status_code=200, headers={'content-type': "application/x-gzip"})
     resource = Resource("http://simple.com")
     data = resource.read()
     self.assertEqual("Hello World", data)
Beispiel #2
0
 def test_open_json_from_file(self):
     file_resource = os.path.join(self.test_data_path, 'simple.json')
     resource = Resource(file_resource)
     data = resource.read()
     self.assertEqual(
         json.loads(
             "{ \"name\":\"John\", \"age\":31, \"city\":\"New York\" }"),
         data)
Beispiel #3
0
    def test_text_from_url(self, mock_url_call):
        mock_url_call.return_value = mock.MagicMock(
            status_code=200,
            headers={'content-type': "text/plain"},
            content="Hello World")

        resource = Resource("http://simple.com")
        data = resource.read()
        self.assertEqual("Hello World", data)
Beispiel #4
0
 def test_compressed_json_from_url(self, mock_url_call, mock_gzip_read):
     mock_gzip_read.return_value = "{ \"name\":\"John\", \"age\":31, \"city\":\"New York\" }"
     mock_url_call.return_value = mock.MagicMock(
         status_code=200, headers={'content-type': "application/x-gzip"})
     resource = Resource("http://simple.com")
     data = resource.read()
     self.assertEqual(
         json.loads(
             "{ \"name\":\"John\", \"age\":31, \"city\":\"New York\" }"),
         data)
Beispiel #5
0
    def test_open_from_directory(self):
        test_data = [
            'files.csv', 'platforms/linux/local/one_cve.py',
            'platforms/linux/remote/invalid_cve.py',
            'platforms/linux/remote/no_cve.php',
            'platforms/linux/remote/two_different_cves.txt',
            'platforms/linux/remote/two_different_one_same_cve.txt',
            'platforms/linux/remote/two_same_cves.c'
        ]
        resource = Resource(os.path.join(self.test_data_path,
                                         'exploit-source'))

        data = resource.read()
        common_prefix = os.path.commonprefix(data)
        self.assertTrue(isinstance(data, list))
        for filename in data:
            self.assertIn(filename.replace(common_prefix, ''), test_data)
 def test_delete(self):
     test_cache_file = Resource(self.location)
     self.assertTrue(test_cache_file.exists)
     test_cache_file.delete()
     self.assertFalse(test_cache_file.exists)
 def test_exists(self):
     test_cache_file = Resource(self.location)
     self.assertTrue(test_cache_file.exists)
 def test_init_two(self):
     test_cache_file = Resource(self.location)
     self.assertEqual(self.location, test_cache_file.location)
     self.assertEqual(self.cache_file, test_cache_file.filename)
     self.assertEqual(self.cache_path, test_cache_file.filepath)
Beispiel #9
0
 def test_open_text_from_file(self):
     file_resource = os.path.join(self.test_data_path, 'simple.txt')
     resource = Resource(file_resource)
     data = resource.read()
     self.assertEqual("This is a simple test.\n", data)