Esempio n. 1
0
class ParseUploadTest(unittest.TestCase):

    def setUp(self):
        self.comm = Comm()

    def test_successful(self):
        self.comm.upload_output = 'SUCCESS 1234'
        status = self.comm.parse_upload()
        self.assertTrue(status)
        self.assertEqual(self.comm.warnings, [])
        self.assertEqual(self.comm.tree_id, '1234')

    def test_successful_warnings(self):
        self.comm.upload_output = "Warning 1\nWarning 2\nSUCCESS 1234"
        status = self.comm.parse_upload()
        self.assertTrue(status)
        self.assertEqual(self.comm.warnings, ['Warning 1', 'Warning 2'])
        self.assertEqual(self.comm.tree_id, '1234')

    def test_fatal(self):
        self.comm.upload_output = "ERR 1234"
        status = self.comm.parse_upload()
        self.assertFalse(status)
        self.assertEqual(self.comm.warnings, ["ERR 1234"])
        self.assertEqual(self.comm.tree_id, '')
Esempio n. 2
0
 def __init__(self):
     """
     Initialize a few required variables
     See http://itol.embl.de/help.cgi#bUpOpt for available params
     """
     self.files = []
     self.params = {
         'uploadID': '',
         'projectName': '',
         'treeName': '',
         'treeDescription': '',
     }
     self.comm = Comm()
Esempio n. 3
0
 def setUp(self):
     self.tempfile = tempfile.TemporaryFile()
     self.comm = Comm.Comm()
     self.params = {'asdf': 'qwer'}
     self.files = {'zxcv': self.tempfile}
     self.all_params = self.params.copy()
     self.all_params.update(self.files)
Esempio n. 4
0
class UploadTreeTest(unittest.TestCase):

    def setUp(self):
        self.tempfile = tempfile.NamedTemporaryFile()
        self.files = [self.tempfile.name]
        self.comm = Comm()
        self.params = {'treeName': 'asdf'}

    def tearDown(self):
        self.tempfile.close()

    @patch('itolapi.comm.requests')
    @patch('itolapi.Comm.parse_upload')
    def test_upload_tree(self, mock_parse, mock_requests):
        mock_requests.post().text = 'asdf'
        mock_parse.return_value = 'qwer'
        output = self.comm.upload_tree(self.files, self.params)
        self.assertEqual(
            mock_requests.post.call_args[0][0],
            self.comm.upload_url
        )
        self.assertEqual(mock_requests.post.call_args[1]['data'], self.params)
        self.assertTrue('zipFile' in mock_requests.post.call_args[1]['files'])
        mock_parse.assert_called_once_with()
        self.assertEqual(self.comm.upload_output, 'asdf')
        self.assertEqual(output, 'qwer')
Esempio n. 5
0
 def test_tree_file_extension(self):
     zip_file = Comm.create_zip_from_files([self.tempfile.name])
     with open(zip_file.name, 'rb') as zip_file_handle:
         with zipfile.ZipFile(zip_file_handle) as zip_handle:
             files = zip_handle.namelist()
     expected_tree_name = os.path.basename(self.tempfile.name)
     self.assertIn(expected_tree_name, files)
     zip_file.close()
Esempio n. 6
0
class ExportImageTest(unittest.TestCase):
    def setUp(self):
        self.comm = Comm()
        self.params = {'tree_id': '1234'}

    @patch('itolapi.comm.requests')
    def test_export_image(self, mock_requests):
        mock_requests.post().content = 'asdf'
        output = self.comm.export_image(self.params)
        self.assertEqual(output, 'asdf')
Esempio n. 7
0
 def __init__(self):
     """
     Initialize a few required variables
     See http://itol.embl.de/help.cgi#bUpOpt for available params
     """
     self.files = []
     self.params = {
         'uploadID': '',
         'projectName': '',
         'treeName': '',
         'treeDescription': '',
     }
     self.comm = Comm()
Esempio n. 8
0
class ItolExport:
    EXPORT_FORMATS = ['png', 'svg', 'eps', 'ps', 'pdf', 'nexus', 'newick']
    """
    Instantiate the itolexport class with empty params and empty server
    """

    def __init__(self):
        """
        Instantiate class
        """
        self.params = dict({})
        self.comm = Comm()

    # Setting Export Parameters
    def add_export_param_dict(self, param_dict):
        """
        Add a dictionary of parameters to the parameters to be used when
        exporting
        @param: dictionary of parameters to be used
        """
        self.params.update(param_dict)

    def set_export_param_value(self, key, value):
        """
        Add a value to the dictionary of parameters to be used when exporting
        @param: dictionary of parameters to be used
        """
        self.params[key] = value

    def get_export_params(self):
        """
        Get the dictionary of parameters to tbe used when exporting
        @return: export the Parameters
        """
        return self.params

    # Do Exporting
    def export(self, export_location):
        """
        Call the export process
        Calling this directly assumes that the export filetype is already set
        in the export params
        @param filelocation: the location to write the export to
        @return: whether the export works
        """
        output = self.comm.export_image(self.params)
        file_handle = open(export_location, 'wb')
        file_handle.write(output)
        file_handle.close()
Esempio n. 9
0
class ItolExport:
    EXPORT_FORMATS = ['png', 'svg', 'eps', 'ps', 'pdf', 'nexus', 'newick']
    """
    Instantiate the itolexport class with empty params and empty server
    """

    def __init__(self):
        """
        Instantiate class
        """
        self.params = dict({})
        self.comm = Comm()

    # Setting Export Parameters
    def add_export_param_dict(self, param_dict):
        """
        Add a dictionary of parameters to the parameters to be used when
        exporting
        @param: dictionary of parameters to be used
        """
        self.params.update(param_dict)

    def set_export_param_value(self, key, value):
        """
        Add a value to the dictionary of parameters to be used when exporting
        @param: dictionary of parameters to be used
        """
        self.params[key] = value

    def get_export_params(self):
        """
        Get the dictionary of parameters to tbe used when exporting
        @return: export the Parameters
        """
        return self.params

    # Do Exporting
    def export(self, export_location):
        """
        Call the export process
        Calling this directly assumes that the export filetype is already set
        in the export params
        @param filelocation: the location to write the export to
        @return: whether the export works
        """
        output = self.comm.export_image(self.params)
        file_handle = open(export_location, 'wb')
        file_handle.write(output)
        file_handle.close()
Esempio n. 10
0
 def __init__(self):
     """
     Initialize a few required variables
     """
     self.variables = dict()
     self.comm = Comm.Comm()
Esempio n. 11
0
class Itol:
    """
    This class handles the main itol functionality
    """
    def __init__(self):
        """
        Initialize a few required variables
        See http://itol.embl.de/help.cgi#bUpOpt for available params
        """
        self.files = []
        self.params = {
            'uploadID': '',
            'projectName': '',
            'treeName': '',
            'treeDescription': '',
        }
        self.comm = Comm()

    def add_file(self, file_path):
        """
        Add a file to be uploaded, tree or dataset
        """
        if not os.path.isfile(file_path):
            raise IOError('%s is not a file' % file_path)
        self.files.append(file_path)

    def upload(self):
        """
        Upload the data to the iTOL server and return an ItolExport object
        """
        good_upload = self.comm.upload_tree(self.files, self.params)
        if good_upload:
            return self.comm.tree_id
        else:
            self.comm.tree_id = 0
            return False

    def get_webpage(self):
        """
        Get the web page where you can download the Itol tree
        """
        webpage = "http://itol.embl.de/external.cgi?tree=" +\
            str(self.comm.tree_id) + "&restore_saved=1"
        return webpage

    def get_itol_export(self):
        """
        Returns an instance of ItolExport in preparation of exporting from the
        generated tree
        @return: instance of ItolExport
        """
        itol_exporter = ItolExport()
        itol_exporter.set_export_param_value('tree', self.comm.tree_id)
        return itol_exporter

    def print_variables(self):
        """
        Print the files and params that have been set so far
        """
        print('Files:')
        pprint.pprint(self.files)
        print('Parameters:')
        pprint.pprint(self.params)
Esempio n. 12
0
 def setUp(self):
     self.comm = Comm()
     self.params = {'tree_id': '1234'}
Esempio n. 13
0
 def setUp(self):
     self.comm = Comm()
Esempio n. 14
0
 def __init__(self):
     """
     Instantiate class
     """
     self.params = dict({})
     self.comm = Comm.Comm()
Esempio n. 15
0
class Itol:
    """
    This class handles the main itol functionality
    """

    def __init__(self):
        """
        Initialize a few required variables
        See http://itol.embl.de/help.cgi#bUpOpt for available params
        """
        self.files = []
        self.params = {
            'uploadID': '',
            'projectName': '',
            'treeName': '',
            'treeDescription': '',
        }
        self.comm = Comm()

    def add_file(self, file_path):
        """
        Add a file to be uploaded, tree or dataset
        """
        if not os.path.isfile(file_path):
            raise IOError('%s is not a file' % file_path)
        self.files.append(file_path)

    def upload(self):
        """
        Upload the data to the iTOL server and return an ItolExport object
        """
        good_upload = self.comm.upload_tree(self.files, self.params)
        if good_upload:
            return self.comm.tree_id
        else:
            self.comm.tree_id = 0
            return False

    def get_webpage(self):
        """
        Get the web page where you can download the Itol tree
        """
        webpage = "http://itol.embl.de/external.cgi?tree=" +\
            str(self.comm.tree_id) + "&restore_saved=1"
        return webpage

    def get_itol_export(self):
        """
        Returns an instance of ItolExport in preparation of exporting from the
        generated tree
        @return: instance of ItolExport
        """
        itol_exporter = ItolExport()
        itol_exporter.set_export_param_value('tree', self.comm.tree_id)
        return itol_exporter

    def print_variables(self):
        """
        Print the files and params that have been set so far
        """
        print('Files:')
        pprint.pprint(self.files)
        print('Parameters:')
        pprint.pprint(self.params)
Esempio n. 16
0
 def __init__(self):
     """
     Instantiate class
     """
     self.params = dict({})
     self.comm = Comm()
Esempio n. 17
0
 def setUp(self):
     self.tempfile = tempfile.NamedTemporaryFile()
     self.files = [self.tempfile.name]
     self.comm = Comm()
     self.params = {'treeName': 'asdf'}