コード例 #1
0
 def test_getCustomerDataFromFile(self):
     readCSVFile = ReadCSVFile()
     fileData = readCSVFile.getFileData(ENTITIES_FOLDER,
                                        "customer" + ".csv")
     self.assertEqual(
         fileData[1],
         ['*****@*****.**', 'Derek', 'Somerville', '1234'])
コード例 #2
0
 def getCustomerDataFromFile(self):
     customerFileReader = ReadCSVFile()
     customerData = customerFileReader.getFileData(ENTITIES_FOLDER, self.customerTableName + ".csv")
     header = customerData.pop(0)
     if not self.validateDataFromFileHeader(header):
         self.errorLogging.writeToLog("CustomerDatabaseMapping.getCustomerDataFromFile",
                                      "An error occurred:" + sqlExp.args[0])
     return customerData
コード例 #3
0
 def test_getLastLinesFromFileFake(self):
     readCSVFile = ReadCSVFile()
     fileLines = readCSVFile.getLastLines(ENTITIES_FOLDER,
                                          "customer" + ".csv", 1,
                                          CSVFileObjectFake)
     self.assertEqual(
         fileLines,
         ['*****@*****.**', 'Andrew', 'Blair', '5678'])
コード例 #4
0
 def get_customer_data_from_file(self):
     customer_file_reader = ReadCSVFile()
     customer_data = customer_file_reader.get_file_data(
         ENTITIES_FOLDER, self.customer_table_name + ".csv")
     header = customer_data.pop(0)
     if not self.validate_data_from_file_header(header):
         print("CustomerDatabaseMapping.get_customer_data_from_file",
               "Not validate_data_from_file_header")
     return customer_data
コード例 #5
0
    def test_getLastLinesFromFileMock(self):
        readCSVFile = ReadCSVFile()
        readCSVFile.getLastLines = MagicMock(return_value=[
            '*****@*****.**', 'Andrew', 'Blair', '5678'
        ])

        fileLines = readCSVFile.getLastLines(ENTITIES_FOLDER,
                                             "customer" + ".csv", 1)
        self.assertEqual(
            fileLines,
            ['*****@*****.**', 'Andrew', 'Blair', '5678'])
コード例 #6
0
class TestReadCSVFile(unittest.TestCase):

    readCSVFile = ReadCSVFile()

    def test_getCustomerDataFromFile(self):
        fileData = self.readCSVFile.getFileData(ENTITIES_FOLDER,
                                                "customer" + ".csv")
        self.assertEqual(
            fileData[1],
            ['*****@*****.**', 'Derek', 'Somerville', '1234'])

    def test_getLastLinesFromFile(self):
        fileLines = self.readCSVFile.getLastLines(ENTITIES_FOLDER,
                                                  "customer" + ".csv", 1)
        self.assertEqual(
            fileLines, ['*****@*****.**', 'Matt', 'Barr', '4321'])

    def test_getCustomerDataFromStub(self):
        fileData = ReadFromStub.getFileData(self)
        self.assertEqual(fileData[1],
                         ["[email protected],Robynn,McCrossan,4567"])

    def test_getCustomerDataFake(self):
        fileData = []
        fileData.append(["emailAddress,firstName,lastName,password"])
        fileData.append(["[email protected],Robynn,McCrossan,4567"])
        fileData.append(["[email protected],John,Smith,1234"])
        fileData.append(["[email protected],Karen,Jones,2345"])

        self.assertEqual(["emailAddress,firstName,lastName,password"],
                         fileData[0])
コード例 #7
0
 def test_get_customer_data_from_file(self):
     read_csv_file = ReadCSVFile()
     customer_database_mapping = CustomerDatabaseMapping()
     customer_data = customer_database_mapping.get_customer_data_from_file()
     self.assertEqual(
         customer_data[0],
         ['*****@*****.**', 'Derek', 'Somerville', '1234'])
コード例 #8
0
class TestReadCSVFile(unittest.TestCase):

#Stubs

    readCSVFile = ReadCSVFile()

    def test_getCustomerDataFromFile(self):
        fileData = self.readCSVFile.getConfig(ENTITIES_FOLDER,"customer" + ".csv")
        self.assertEqual( fileData[0] ,['*****@*****.**', 'Derek', 'Somerville', '1234'])

    def test_getLastLinesFromFile(self):
        fileLines = self.readCSVFile.getLastLines( ENTITIES_FOLDER, "customer" + ".csv",1)
        self.assertEqual( fileLines ,['*****@*****.**', 'Matt', 'Barr', 'password'])

#Mocks

    def test_readFileData(self):

        self.readCSVFile.getConfig = MagicMock(return_value=[['*****@*****.**', 'Derek', 'Somerville', '1234'],['*****@*****.**', 'Matt', 'Barr', '4321']])
        self.assertEqual(self.readCSVFile.getLastLines(ENTITIES_FOLDER,"customer" + ".csv", 1) ,['*****@*****.**', 'Matt', 'Barr', '4321'])

    def test_readFileDataDerek(self):

        self.readCSVFile.getConfig = MagicMock(return_value=[['*****@*****.**', 'Derek', 'Somerville', '1234']])
        self.assertEqual(self.readCSVFile.getLastLines(ENTITIES_FOLDER,"customer" + ".csv", 1) ,['*****@*****.**', 'Derek', 'Somerville', '1234'])

    def test_readFileDataReal(self):

        readCSVFile = ReadCSVFile()
        self.assertEqual(readCSVFile.getLastLines(ENTITIES_FOLDER,"customer" + ".csv", 1) ,['*****@*****.**', 'Matt', 'Barr', 'password'])
コード例 #9
0
class TestFakingCSVFactory(unittest.TestCase):
    readCSVFile = ReadCSVFile()
    fakeFilePath = '../resource/Entities/FakerGeneratedData.csv'

    def removeExistingFakerFile(self):
        if os.path.exists(self.fakeFilePath):
            os.remove(self.fakeFilePath)

    def test_checkFakerFileIsCreated(self):
        self.removeExistingFakerFile()

        fakeCSVFile(100, ["emailAddress", "firstName", "lastName", "password"])

        self.assertEqual(os.path.exists(self.fakeFilePath), True)

    def test_ExpectedRowCountCreated(self):
        self.removeExistingFakerFile()

        actualRows = 100
        columns = ["emailAddress", "firstName", "lastName", "password"]

        fakeCSVFile(actualRows, columns)
        fileRows = self.readCSVFile.getFileData(ENTITIES_FOLDER,
                                                "FakerGeneratedData" + ".csv")

        expectedRows = len(fileRows) - 1

        self.assertEqual(expectedRows, actualRows)
コード例 #10
0
class TestOutputConsole(unittest.TestCase):
    outputConsole = OutputConsole()
    readCSCFile = ReadCSVFile()

    def testPrint(self):
        self.outputConsole.print("A test of outputConsole.print")
        outputLine = self.readCSCFile.getLastLines(USERACTION_FOLDER, OUTPUT_LOG, 1)
        self.assertEqual(["A test of outputConsole.print"], outputLine)
コード例 #11
0
class TestOutputConsole(unittest.TestCase):

    outputConsole = OutputConsole()
    readCSCFile = ReadCSVFile()

    def testPrint(self):
        self.outputConsole.print("A test of outputConsole.print")
        outputLine = self.readCSCFile.getLastLines(userActionFolder, outputLog,
                                                   1)
        self.assertEqual(["A test of outputConsole.print"], outputLine)
コード例 #12
0
class CustomerDatabaseMapping:

    errorLogging = ErrorLogging()
    customerTableName = Customer.dataSourceName

    emailAddressPosition = 0
    firstNamePosition = 1
    lastNamePosition = 2
    passwordPosition = 3

    dataSourceFields = ["emailAddress","firstName","lastName","password"]

    customerFileReader = ReadCSVFile()

    def setCustomerFileReader(self, readCSVFile):
        self.customerFileReader = readCSVFile


    def createCustomer(self, customerDetails):
        customer = Customer(
            customerDetails[self.emailAddressPosition],
            customerDetails[self.firstNamePosition],
            customerDetails[self.lastNamePosition],
            customerDetails[self.passwordPosition]
        )
        return customer

    def validateDataFromFileHeader(self, header):
        return header == self.dataSourceFields

    def getCustomerDataFromFile(self):
        customerData = self.customerFileReader.getConfig(entitiesFolder,self.customerTableName + ".csv")
        #if not self.validateDataFromFileHeader(header):
        #   self.errorLogging.writeToLog("CustomerDatabaseMapping.getCustomerDataFromFile","An error occurred:" + sqlExp.args[0])
        return customerData

    #def customerCreateTable(self):
     #   try:
      #      self.dbSetup.dropTable(self.customerTableName)
       #     self.dbSetup.createTable(self.customerTableName,self.dataSourceFields)
        #except:
         #   self.errorLogging.writeToLog("CustomerDatabaseMapping.customerCreateTable","An error occurred:" + sys.exc_info()[0])



    def getCustomerData(self):
        return self.dataSource.getData(self.customerTableName,self.dataSourceFields)

    def createAllCustomers(self):
        allCustomers = []
        allCustomerData = self.getCustomerData()
        for customerRow in allCustomerData:
            customer = self.createCustomer(customerRow)
            allCustomers.append(customer)
        return allCustomers
コード例 #13
0
    def test_Stub(self):
        readCSVFile = ReadCSVFile()
        customerDatabaseMapping = CustomerDatabaseMapping()

        customerDatabaseMapping.setConfig(ConfigStub.ConfigStub())
        customerDatabaseMapping.dataSourceFields = []

        result = customerDatabaseMapping.getCustomerData()
        self.assertEqual(
            ('*****@*****.**', 'Derek', 'Somerville', '1234'),
            result[0])
コード例 #14
0
class TestReadStub(unittest.TestCase):
    readCSVFile = ReadCSVFile()

    def test_getDataFromStub(self):
        fileData = self.readCSVFile.getFileData(ENTITIES_FOLDER,
                                                "stub" + ".csv")
        self.assertEqual(
            fileData[1],
            ['*****@*****.**', 'TestFirstName', 'TestLastName', '123'])

    def test_getLastLinesFromStub(self):
        fileLines = self.readCSVFile.getLastLines(ENTITIES_FOLDER,
                                                  "stub" + ".csv", 1)
        self.assertEqual(fileLines,
                         ['*****@*****.**', 'Test2', 'Test2', '456'])
コード例 #15
0
class TestReadCSVFile(unittest.TestCase):

    read_csv_file = ReadCSVFile()

    def test_get_customer_data_from_file(self):
        file_data = self.read_csv_file.get_file_data(ENTITIES_FOLDER,
                                                     "customer" + ".csv")
        self.assertEqual(
            file_data[1],
            ['*****@*****.**', 'Derek', 'Somerville', '1234'])

    def test_get_last_lines_from_file(self):
        file_lines = self.read_csv_file.get_last_lines(ENTITIES_FOLDER,
                                                       "customer" + ".csv", 1)
        self.assertEqual(
            file_lines, ['*****@*****.**', 'Matt', 'Barr', '4321'])
コード例 #16
0
    def test_Mock(self):
        readCSVFile = ReadCSVFile()
        customerDatabaseMapping = CustomerDatabaseMapping()

        MockData = []
        MockData.append("*****@*****.**")
        MockData.append("Derek")
        MockData.append("Somerville")
        MockData.append("1234")

        customerDatabaseMapping.config.getConfig = MagicMock(
            return_value=MockData)
        customerDatabaseMapping.dataSourceFields = []

        result = customerDatabaseMapping.getCustomerData()
        self.assertEqual(
            ('*****@*****.**', 'Derek', 'Somerville', '1234'),
            result[0])
コード例 #17
0
class TestReadCSVFile(unittest.TestCase):
    readCSVFile = ReadCSVFile()

    def test_getCustomerDataFromFile(self):
        fileData = self.readCSVFile.getFileData(ENTITIES_FOLDER,
                                                "customer" + ".csv")
        self.assertEqual(
            fileData[1],
            ['*****@*****.**', 'Derek', 'Somerville', '1234'])

    def test_getLastLinesFromFile(self):
        fileLines = self.readCSVFile.getLastLines(ENTITIES_FOLDER,
                                                  "customer" + ".csv", 2)
        self.assertEqual(
            fileLines, ['*****@*****.**', 'Matt', 'Barr', '4321'])

    def test_getFirstLineFromFile(self):
        fileLines = self.readCSVFile.getFirstLine(ENTITIES_FOLDER,
                                                  "customer" + ".csv", 0)
        self.assertEqual(
            fileLines,
            ['*****@*****.**', 'Jack ', 'Nobile', '6969'])
コード例 #18
0
class TestReadCSVFile(unittest.TestCase):
    outputConsole = OutputConsole()
    readCSVFile = ReadCSVFile()
    fake = Faker()

    def test_mockFakeLastLinesFromFile(self):
        fakerLastLines = [
            self.fake.email(),
            self.fake.first_name(),
            self.fake.last_name(),
            self.fake.password()
        ]

        self.readCSVFile.getLastLines = MagicMock(return_value=fakerLastLines)

        self.assertEqual(self.readCSVFile.getLastLines(), fakerLastLines)

    def test_MockPrint(self):
        mockSuccessMessage = 'Mock successfully run!'

        self.outputConsole.print = MagicMock(return_value=mockSuccessMessage)

        self.assertEqual(self.outputConsole.print(), mockSuccessMessage)
コード例 #19
0
    def test_readFileDataReal(self):

        readCSVFile = ReadCSVFile()
        self.assertEqual(readCSVFile.getLastLines(ENTITIES_FOLDER,"customer" + ".csv", 1) ,['*****@*****.**', 'Matt', 'Barr', 'password'])
コード例 #20
0
 def attributesFile(self, menuName):
     readCSVFile = ReadCSVFile()
     smoothieMenu = readCSVFile.getConfig(entitiesFolder, menuName + ".csv")
     return smoothieMenu
コード例 #21
0
 def test_getLastLinesFromFile(self):
     readCSVFile = ReadCSVFile()
     fileLines = readCSVFile.getLastLines(ENTITIES_FOLDER,
                                          "customer" + ".csv", 1)
     self.assertEqual(
         fileLines, ['*****@*****.**', 'Matt', 'Barr', '4321'])