# Path: django_test_tools/excel.py
# class ExcelAdapter(object):
# 
#     @classmethod
#     def convert_to_list(cls, filename, sheet_name=None, has_header=True):
#         """
#         Reads an Excel file and converts every row into a dictionary. All values are converted to strings.
#         Assumes first row contains the name of the attributes.
# 
#         :param filename: <str> Excel filename
#         :param sheet_name: <str> Name of the sheet
#         :return: <list> A list of dictionaries.
#         """
#         data = list()
#         wb = load_workbook(filename=filename, data_only=True)
#         if sheet_name is None:
#             sheet = wb.active
#         else:
#             sheet = wb[sheet_name]
#         row_num = 1
#         for row in sheet.rows:
#             row_data = list()
#             if row_num == 1 and has_header:
#                 row_num += 1
#                 continue
#             for column in range(0, len(row)):
#                 row_data.append(row[column].value)
#             data.append(row_data)
#             row_num += 1
#         return data
# 
#     @classmethod
#     def convert_to_dict(cls, filename, sheet_name=None):
#         """
#         Reads an Excel file and converts every row into a dictionary. All values are converted to strings.
#         Assumes first row contains the name of the attributes.
# 
#         :param filename: <str> Excel filename
#         :param sheet_name: <str> Name of the sheet
#         :return: <list> A list of dictionaries.
#         """
#         data = list()
#         wb = load_workbook(filename=filename, data_only=True)
#         if sheet_name is None:
#             sheet = wb.active
#         else:
#             sheet = wb[sheet_name]
#         row_num = 1
#         attributes = list()
#         for row in sheet.rows:
#             row_data = dict()
#             if row_num == 1:
#                 row_num += 1
#                 for column in range(0, len(row)):
#                     attributes.append(row[column].value)
#                 continue
#             for column in range(0, len(row)):
#                 row_data[attributes[column]] = str(row[column].value)
#             data.append(row_data)
#             row_num += 1
#         return data
# 
# Path: django_test_tools/exceptions.py
# class DjangoTestToolsException(Exception):
#     pass


import csv
import json
import os
from io import StringIO
from django.conf import settings
from django.urls import reverse
from rest_framework.test import APIClient
from .excel import ExcelAdapter
from .exceptions import DjangoTestToolsException
    def get_results(self, content=None):
        if content is None:
            content = self.content
        content.seek(0)
        lines = content.readlines()
        results = list()
        for line in lines:
            results.append(line.strip('\n'))
        return results

    def get_errors(self):
        return self.get_results(self.error_content)


class TestOutputMixin(object):
    clean_output = True

    def clean_output_folder(self, dated_filename):
        if self.clean_output:
            os.remove(dated_filename)
            # noinspection PyUnresolvedReferences
            self.assertFalse(os.path.exists(dated_filename))

    def get_excel_content(self, filename, sheet_name=None):
        """
        Reads the content of an excel file and returns the content a as list of row lists.
        :param filename: string full path to the filename
        :param sheet_name: string. Name of the sheet to read if None will read the active sheet
        :return: a list containing a list of values for every row.
        """

# Path: django_test_tools/excel.py
# class ExcelAdapter(object):
# 
#     @classmethod
#     def convert_to_list(cls, filename, sheet_name=None, has_header=True):
#         """
#         Reads an Excel file and converts every row into a dictionary. All values are converted to strings.
#         Assumes first row contains the name of the attributes.
# 
#         :param filename: <str> Excel filename
#         :param sheet_name: <str> Name of the sheet
#         :return: <list> A list of dictionaries.
#         """
#         data = list()
#         wb = load_workbook(filename=filename, data_only=True)
#         if sheet_name is None:
#             sheet = wb.active
#         else:
#             sheet = wb[sheet_name]
#         row_num = 1
#         for row in sheet.rows:
#             row_data = list()
#             if row_num == 1 and has_header:
#                 row_num += 1
#                 continue
#             for column in range(0, len(row)):
#                 row_data.append(row[column].value)
#             data.append(row_data)
#             row_num += 1
#         return data
# 
#     @classmethod
#     def convert_to_dict(cls, filename, sheet_name=None):
#         """
#         Reads an Excel file and converts every row into a dictionary. All values are converted to strings.
#         Assumes first row contains the name of the attributes.
# 
#         :param filename: <str> Excel filename
#         :param sheet_name: <str> Name of the sheet
#         :return: <list> A list of dictionaries.
#         """
#         data = list()
#         wb = load_workbook(filename=filename, data_only=True)
#         if sheet_name is None:
#             sheet = wb.active
#         else:
#             sheet = wb[sheet_name]
#         row_num = 1
#         attributes = list()
#         for row in sheet.rows:
#             row_data = dict()
#             if row_num == 1:
#                 row_num += 1
#                 for column in range(0, len(row)):
#                     attributes.append(row[column].value)
#                 continue
#             for column in range(0, len(row)):
#                 row_data[attributes[column]] = str(row[column].value)
#             data.append(row_data)
#             row_num += 1
#         return data
# 
# Path: django_test_tools/exceptions.py
# class DjangoTestToolsException(Exception):
#     pass


# Path: django_test_tools/mixins.py
import csv
import json
import os
from io import StringIO
from django.conf import settings
from django.urls import reverse
from rest_framework.test import APIClient
from .excel import ExcelAdapter
from .exceptions import DjangoTestToolsException

    def get_results(self, content=None):
        if content is None:
            content = self.content
        content.seek(0)
        lines = content.readlines()
        results = list()
        for line in lines:
            results.append(line.strip('\n'))
        return results

    def get_errors(self):
        return self.get_results(self.error_content)


class TestOutputMixin(object):
    clean_output = True

    def clean_output_folder(self, dated_filename):
        if self.clean_output:
            os.remove(dated_filename)
            # noinspection PyUnresolvedReferences
            self.assertFalse(os.path.exists(dated_filename))

    def get_excel_content(self, filename, sheet_name=None):
        """
        Reads the content of an excel file and returns the content a as list of row lists.
        :param filename: string full path to the filename
        :param sheet_name: string. Name of the sheet to read if None will read the active sheet
        :return: a list containing a list of values for every row.
        """

        adapter = ExcelAdapter()