def test_basic_actions(self): storage = CloudStorage() name = u"tmp.ąćęłńóśźż.马铃薯.zip" f = ContentFile("content", name="my_file") filename = storage.save(name, f) self.assertIsInstance(filename, basestring) self.assertTrue(filename.endswith(name)) self.assertTrue(storage.exists(filename)) self.assertEqual(storage.size(filename), len("content")) url = storage.url(filename) self.assertIsInstance(url, basestring) self.assertNotEqual(url, "") abs_url = urlparse.urlunparse(("http", os.environ["HTTP_HOST"], url, None, None, None)) response = urlfetch.fetch(abs_url) self.assertEqual(response.status_code, httplib.OK) self.assertEqual(response.content, "content") f = storage.open(filename) self.assertIsInstance(f, File) self.assertEqual(f.read(), "content") # Delete it storage.delete(filename) self.assertFalse(storage.exists(filename))
def test_basic_actions(self): storage = CloudStorage() f = ContentFile('content', name='my_file') filename = storage.save('tmp', f) self.assertIsInstance(filename, basestring) self.assertTrue(filename.endswith('tmp')) self.assertTrue(storage.exists(filename)) self.assertEqual(storage.size(filename), len('content')) url = storage.url(filename) self.assertIsInstance(url, basestring) self.assertNotEqual(url, '') abs_url = urlparse.urlunparse( ('http', os.environ['HTTP_HOST'], url, None, None, None) ) response = urlfetch.fetch(abs_url) self.assertEqual(response.status_code, httplib.OK) self.assertEqual(response.content, 'content') f = storage.open(filename) self.assertIsInstance(f, File) self.assertEqual(f.read(), 'content') # Delete it storage.delete(filename) self.assertFalse(storage.exists(filename))
def test_basic_actions(self): storage = CloudStorage() name = u'tmp.ąćęłńóśźż.马铃薯.zip' f = ContentFile('content', name='my_file') filename = storage.save(name, f) self.assertIsInstance(filename, six.string_types) self.assertTrue(filename.endswith(name)) self.assertTrue(storage.exists(filename)) self.assertEqual(storage.size(filename), len('content')) url = storage.url(filename) self.assertIsInstance(url, six.string_types) self.assertNotEqual(url, '') abs_url = six.moves.urllib.parse.urlunparse( ('http', os.environ['HTTP_HOST'], url, None, None, None) ) response = urlfetch.fetch(abs_url) self.assertEqual(response.status_code, six.moves.http_client.OK) self.assertEqual(response.content, 'content') f = storage.open(filename) self.assertIsInstance(f, File) self.assertEqual(f.read(), 'content') # Delete it storage.delete(filename) self.assertFalse(storage.exists(filename))
def test_basic_actions(self): storage = CloudStorage() name = u'tmp.ąćęłńóśźż.马铃薯.zip' f = ContentFile('content', name='my_file') filename = storage.save(name, f) self.assertIsInstance(filename, basestring) self.assertTrue(filename.endswith(name)) self.assertTrue(storage.exists(filename)) self.assertEqual(storage.size(filename), len('content')) url = storage.url(filename) self.assertIsInstance(url, basestring) self.assertNotEqual(url, '') abs_url = urlparse.urlunparse( ('http', os.environ['HTTP_HOST'], url, None, None, None)) response = urlfetch.fetch(abs_url) self.assertEqual(response.status_code, httplib.OK) self.assertEqual(response.content, 'content') f = storage.open(filename) self.assertIsInstance(f, File) self.assertEqual(f.read(), 'content') # Delete it storage.delete(filename) self.assertFalse(storage.exists(filename))
def test_basic_actions(self): content = b'content' storage = CloudStorage() name = u'tmp.ąćęłńóśźż.马铃薯.zip' f = ContentFile(content, name='my_file') filename = storage.save(name, f) self.assertIsInstance(filename, six.string_types) self.assertTrue(filename.endswith(name)) self.assertTrue(storage.exists(filename)) self.assertEqual(storage.size(filename), len(content)) url = storage.url(filename) self.assertIsInstance(url, six.string_types) self.assertNotEqual(url, '') response = requests.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, content) f = storage.open(filename) self.assertIsInstance(f, File) self.assertEqual(f.read(), content) # Delete it storage.delete(filename) self.assertFalse(storage.exists(filename))