# 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
        """
        Get full patch for the fixture file

        :param fixture_filename: <str> name of the fixture file
        :return: <str> full path to fixture file
        """
        self._sanity_check()
        if self.app_name is None:
            fixture_file = settings.APPS_DIR.path('tests', 'fixtures', fixture_filename).root
        else:
            fixture_file = settings.APPS_DIR.path(self.app_name, 'tests', 'fixtures', fixture_filename).root
        return fixture_file

    def get_fixture_json(self, fixture_filename):
        """
        Reads a file and returns the json content.

        :param fixture_filename: <str> filename
        :return: <dict> With the file content
        """
        fixture_file = self.get_fixture_fullpath(fixture_filename)

        with open(fixture_file, 'r') as f:
            json_data = json.load(f)
        return json_data

    def _sanity_check(self):
        if self.app_name is None and self.strict:
            raise DjangoTestToolsException('app_name not defined')
        if not hasattr(settings, 'APPS_DIR'):

# 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

        """
        Get full patch for the fixture file

        :param fixture_filename: <str> name of the fixture file
        :return: <str> full path to fixture file
        """
        self._sanity_check()
        if self.app_name is None:
            fixture_file = settings.APPS_DIR.path('tests', 'fixtures', fixture_filename).root
        else:
            fixture_file = settings.APPS_DIR.path(self.app_name, 'tests', 'fixtures', fixture_filename).root
        return fixture_file

    def get_fixture_json(self, fixture_filename):
        """
        Reads a file and returns the json content.

        :param fixture_filename: <str> filename
        :return: <dict> With the file content
        """
        fixture_file = self.get_fixture_fullpath(fixture_filename)

        with open(fixture_file, 'r') as f:
            json_data = json.load(f)
        return json_data

    def _sanity_check(self):
        if self.app_name is None and self.strict:
            raise DjangoTestToolsException('app_name not defined')
        if not hasattr(settings, 'APPS_DIR'):

            raise DjangoTestToolsException('APPS_DIR not defined')