from django.test import TestCase
import openpyxl as xl,os, time
from pathlib import Path


# Create your tests here.
from .models import employee
BASE_DIR = Path(__file__).resolve().parent
str_testdata = os.path.join(BASE_DIR, 'data','testData.xlsx')
wb = xl.load_workbook( str_testdata )


# local functions
def lf_get_modeldata(str_modelname):
    dic_datalist = {}
    
    dic_datalist[str_modelname] =  []
    Sht = wb['add_' +str_modelname ]
    for rownum in range(2,Sht.max_row + 1):
        i = 1;dic_data = {}
        if Sht.cell(row=rownum, column=1).value == None: break
        while None != Sht.cell(row=1, column=i).value :
            name1 = Sht.cell(row=1, column=i).value
            dic_data[name1] = Sht.cell(row=rownum, column=i).value
            i = i + 1
        dic_datalist[str_modelname].append(dic_data)
    #print(dic_datalist)
    return dic_datalist

class Country_Tests(TestCase):
    def setUp(self):  
        self.dic_data = {}
        self.dic_data.update(lf_get_modeldata('employee'))
    def test_employee(self):        employee.objects.create(**self.dic_data['employee'][0])
    def test_employee1(self):       employee.objects.create(**self.dic_data['employee'][1])
    def test_employee2(self):       employee.objects.create(**self.dic_data['employee'][2])
    def test_employee3(self):       employee.objects.create(**self.dic_data['employee'][3])

# dic_data = {}
# dic_data.update(lf_get_modeldata('employee'))    