Esempio n. 1
0
def test_parseDate3(mocker):
    """ 
    Test parseDate with unusual input

    Expected result: result is None

    N.B. Worker.parseDate doesn't implement robust input validation, so will
    trigger an unhandled exception when fed non-string inputs. Hence, this
    test case is currently expected to fail.

    """
    # given: setup test framework
    worker = Worker()
    input_strings = [
        "12/1220", "01/01/19999", "Monday", -1, [], {
            "hello": "world"
        }, 3.5
    ]

    # when:
    for input_string in input_strings:
        result = worker.parseDate(input_string)

        # then:
        AssertThat(result).IsNone()
Esempio n. 2
0
def test_worker_parseLineCSV_generative(input_string):
    
    # given
    worker = Worker()

    # when
    result = worker.parseLineCSV(input_string)
    
    # then
    AssertThat(result).IsNone()
Esempio n. 3
0
    def __init__(self):
        """ Constructor """
        super().__init__()
        
        # Setup database access
        dao = DAO()
        dao.create_jobs_table()
        self.dao = dao
        self.last_DB_row = None

        # Setup processing worker
        self.worker = Worker()
Esempio n. 4
0
def test_worker_parseDate2_generative(input_string):
    
    # given
    worker = Worker()

    # when
    result = worker.parseLineCSV(input_string)
    
    # then
    # returns None or a string
    # Must not throw unhandled exception
    if result is not None:
        AssertThat(result).IsInstanceOf(str)
Esempio n. 5
0
def test_parseDate3(mocker):
    """ 
    Test parseLine with bad Date format 1: dd/mmyy

    Expected result: result is None
    """    
    # given: setup test framework
    worker = Worker()
    testString = "12/1220"
    
    # when:
    result = worker.parseDate(testString)
    
    # then:
    AssertThat(result).IsNone()
Esempio n. 6
0
def test_parseDate4(mocker):
    """ 
    Test parseLine with bad Date format 2: 32Jan2019

    Expected result: result is None
    """    
    # given: setup test framework
    worker = Worker()
    testString = "32Jan2019"
    
    # when:
    result = worker.parseDate(testString)
    
    # then:
    AssertThat(result).IsNone()
Esempio n. 7
0
def test_worker_parseDate1_generative(mocker, input_date):

    # given
    input_string = input_date.strftime(format="%d%b%Y")
    worker = Worker()

    # when 
    result = worker.parseDate(input_string)
    
    print(input_string, result)
    
    # then
    AssertThat(result).IsInstanceOf(str)
    AssertThat(result).HasSize(10)
    AssertThat(result.split('-')).HasSize(3)
Esempio n. 8
0
def test_parseDate2(mocker):
    """ 
    Test parseLine with Date format 2: ddmmmYYYY

    Expected result: formatted string in dd/mm/YYYY
    """    
    # given: setup test framework
    worker = Worker()
    testString = "04Jan2019"
    expected_result = "04/01/2019"
    
    # when:
    result = worker.parseDate(testString)
    
    # then: (Using PyTruth assertions)
    AssertThat(result).IsEqualTo(expected_result)
Esempio n. 9
0
def test_parseLine2(mocker):
    """ 
    Test parseLine with bad data (some fields missing)

    Expected result: result is None
    """
    
    # given: setup test framework
    worker = Worker()
    testString = "11/11/19,Brighter Futures,12000"
    
    # when:
    result = worker.parseLine(testString)
    
    # then: (Using PyTruth assertions)
    AssertThat(result).IsNone()
Esempio n. 10
0
class Application:
    def __init__(self):
        """ Constructor """
        super().__init__()
        
        # Setup database access
        dao = DAO()
        dao.create_jobs_table()
        self.dao = dao
        self.last_DB_row = None

        # Setup processing worker
        self.worker = Worker()

    def loadData(self, data_filepath):

        parsed_data = self.worker.readData(data_filepath)

        for row in parsed_data:
            self.last_DB_row = self.dao.insert_job(row['job_title'], 
                                row['company_name'], 
                                row['salary'], 
                                row['date'])
        
        print(f'Last row in database: {self.last_DB_row}')
Esempio n. 11
0
def test_parseDate2(mocker):
    """ 
    Test parseDate with date format: ddmmmYYYY

    Expected result: formatted string in YYYY-mm-dd
    """
    # given: setup test framework
    worker = Worker()
    testString = "04Jan2019"
    expected_result = "2019-01-04"

    # when:
    result = worker.parseDate(testString)

    # then: (Using PyTruth assertions)
    AssertThat(result).IsEqualTo(expected_result)
Esempio n. 12
0
def test_parseDate4(mocker):
    """ 
    Test parseDate with unusual input

    Expected result: result is None

    N.B. Worker.parseDate contains some complicated logic, that can get tripped
    by some unusual input - in this case a real-world date format "19th June 2020".
    Hence, this test case is currently expected to fail.

    """
    # given: setup test framework
    worker = Worker()
    input_strings = ["32Jan2019", "Tuesday", "19th June 2020"]

    # when:
    for input_string in input_strings:
        result = worker.parseDate(input_string)

        # then:
        AssertThat(result).IsNone()
Esempio n. 13
0
def test_parseLine1(mocker):
    """ 
    Test parseLine with good data (all fields present)

    Expected result: dict returne with data
    """
    
    # given: setup test framework
    worker = Worker()
    testString = "11/11/19,Teacher,Brighter Futures,12000"
    expectedResult = {
                    'date': '11/11/2019',
                    'job_title': 'Teacher',
                    'company_name': 'Brighter Futures',
                    'salary': 12000
                }
    
    # when:
    result = worker.parseLine(testString)
    
    # then:
    assert result == expectedResult
Esempio n. 14
0
def test_worker_parseLine_generative(input):

    worker = Worker()

    AssertThat(worker.parseLine(input)).IsNone()