def test_file_write_fail(self): self.fixtures = os.path.join( os.path.abspath(os.path.dirname(__file__) + '/xyz')) item = { 'item_id': 'test_file_name', 'item_version': 1, 'formatted_item': 'I was here', 'encoded_item': b'I was here', 'item_encoding': 'utf-8', 'destination': { "name": "test", "delivery_type": "File", "format": "nitf", "config": { "file_path": self.fixtures } } } with self.app.app_context(): service = FilePublishService() try: service._transmit(item, self.subscribers) except PublishFileError as ex: self.assertEqual(ex.message, 'File publish error') self.assertEqual(ex.code, 13000)
def test_format_default_file_extension(self): item = { 'item_id': 'test_file_name', 'item_version': 1, 'published_seq_num': 1, 'formatted_item': 'I was here', 'encoded_item': b'I was here', 'item_encoding': 'utf-8', 'destination': { "name": "test", "delivery_type": "File", "format": "nitf", "config": { "file_path": self.fixtures } } } service = FilePublishService() try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, 'test_file_name-1-1.ntf') if os.path.isfile(path): os.remove(path) item['destination']['config']['file_extension'] = '' try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, 'test_file_name-1-1.ntf') if os.path.isfile(path): os.remove(path)
def test_format_default_file_extension(self): item = { "item_id": "test_file_name", "item_version": 1, "published_seq_num": 1, "formatted_item": "I was here", "encoded_item": b"I was here", "item_encoding": "utf-8", "destination": { "name": "test", "delivery_type": "File", "format": "nitf", "config": { "file_path": self.fixtures }, }, } service = FilePublishService() try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, "test_file_name-1-1.ntf") if os.path.isfile(path): os.remove(path) item["destination"]["config"]["file_extension"] = "" try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, "test_file_name-1-1.ntf") if os.path.isfile(path): os.remove(path)
def test_file_write_fail(self): self.fixtures = os.path.join( os.path.abspath(os.path.dirname(__file__) + "/xyz")) item = { "item_id": "test_file_name", "item_version": 1, "formatted_item": "I was here", "encoded_item": b"I was here", "item_encoding": "utf-8", "destination": { "name": "test", "delivery_type": "File", "format": "nitf", "config": { "file_path": self.fixtures }, }, } with self.app.app_context(): service = FilePublishService() try: service._transmit(item, self.subscribers) except PublishFileError as ex: self.assertEqual( str(ex), "PublishFileError Error 13000 - File publish error") self.assertEqual(ex.code, 13000)
def test_format_default_file_extension(self): item = {'item_id': 'test_file_name', 'item_version': 1, 'published_seq_num': 1, 'formatted_item': 'I was here', 'encoded_item': b'I was here', 'item_encoding': 'utf-8', 'destination': {"name": "test", "delivery_type": "File", "format": "nitf", "config": {"file_path": self.fixtures}} } service = FilePublishService() try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, 'test_file_name-1-1.ntf') if os.path.isfile(path): os.remove(path) item['destination']['config']['file_extension'] = '' try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, 'test_file_name-1-1.ntf') if os.path.isfile(path): os.remove(path)
def test_file_write_fail(self): self.fixtures = os.path.join(os.path.abspath(os.path.dirname(__file__) + '/xyz')) item = {'item_id': 'test_file_name', 'item_version': 1, 'formatted_item': 'I was here', 'destination': {"name": "test", "delivery_type": "File", "format": "nitf", "config": {"file_path": self.fixtures}} } with self.app.app_context(): service = FilePublishService() try: service._transmit(item, self.subscribers) except PublishFileError as ex: self.assertEqual(ex.message, 'File publish error') self.assertEqual(ex.code, 13000)
def test_file_write_string(self): item = {'item_id': 'test_file_name', 'item_version': 1, 'published_seq_num': 1, 'formatted_item': 'I was here', 'destination': {"name": "test", "delivery_type": "File", "format": "nitf", "config": {"file_path": self.fixtures}} } service = FilePublishService() try: service._transmit(item, self.subscribers) self.assertTrue(True) finally: path = os.path.join(self.fixtures, 'test_file_name-1-1.txt') if os.path.isfile(path): os.remove(path)