Example #1
0
    def test_raise_value_error_saving_file_with_invalid_data_header(self):
        headers = ['First', 'Second']
        data = [{'First': 'f1', 'S': 's1'}, {'First': 'f2', 'S': 's2'}]
        filename = 'tests/test_file_output.csv'
        # tests to see if the data header is invalid
        with self.assertRaises(ValueError) as context:
            FileOutput(filename).export_to_CSV(data, headers)

        self.assertTrue(
            'O tipo do dado está incorreto.' in str(context.exception))
    def generate_csv(self, clean=False):
        if clean and os.path.isfile(self._filename):
            os.remove(self._filename)
        elif os.path.isfile(self._filename):
            return True

        with open('config/actors.json') as data_file:
            actors = json.load(data_file)
            actors = actors['channels']
            input_data = [{'actor': name['actor'],
                           'username': '',
                           'channel_id': ''} for name in actors]

        return FileOutput(self._filename).export_to_CSV(
                                                    input_data=input_data,
                                                    headers=self._csv_headers)
Example #3
0
    def test_save_file_with_valid_headers(self):
        headers = ['First', 'Second', 'Third']
        data = [{
            'First': 'f1',
            'Second': 's1',
            'Third': ''
        }, {
            'First': 'f2',
            'Second': 's2',
            'Third': 't1'
        }]
        filename = 'tests/test_file_output.csv'
        result = FileOutput(filename).export_to_CSV(data, headers)

        self.assertTrue(result)
        self.remove_file(filename, result)
Example #4
0
    def test_save_file_without_headers(self):
        data = [{
            'First': 'f1',
            'Second': 's1'
        }, {
            'First': 'f2',
            'Second': 's2'
        }, {
            'First': 'f3',
            'Second': 's3'
        }, {
            'First': 'f4',
            'Second': 's4'
        }]
        filename = 'tests/test_file_output.csv'
        result = FileOutput(filename).export_to_CSV(data)

        self.assertTrue(result)
        self.remove_file(filename, result)
Example #5
0
    def test_raise_value_error_with_invalid_data(self):
        with self.assertRaises(ValueError) as context:
            FileOutput('file.csv').export_to_CSV('')

        self.assertTrue(
            'O tipo do dado está incorreto.' in str(context.exception))
Example #6
0
    def test_raise_value_error_with_invalid_path(self):
        with self.assertRaises(ValueError) as context:
            FileOutput('wrong_folder/file.csv').export_to_CSV([{}])

        self.assertTrue(
            'Nome do arquivo ou caminho incorreto.' in str(context.exception))
 def get_row(self, column, value):
     return FileOutput(self._filename).get_row(column, value)
 def insert_multiple_values(self, column, search_cell, search_value):
     return FileOutput(self._filename).insert_multiple_values(column,
                                                              search_cell,
                                                              search_value)
 def insert_value(self, column, value, search_cell, search_value):
     return FileOutput(self._filename).insert_value(column, value,
                                                    search_cell,
                                                    search_value)