Exemplo n.º 1
0
    def __init__(self, analysis_type, table_to_analyse, start_date, end_date, table_to_store=None):
        """ Initialise an Analyser.

        :param str analysis_type: name of analysis_result to carry out
        :param finances_automation.entities.table.Table table_to_analyse: table to analyse
        :param finances_automation.entities.table.Table table_to_store: table to store analysis_result in
        :param str start_date: date to start analysis_result at
        :param str end_date: date to end analysis_result at
        """
        self.available_analyses = analyses.get_available_analyses()
        self.chosen_analysis = analyses.get_analysis(analysis_type)

        self.analysis_result = None
        self.categories = conf.categories

        self.table_to_analyse = table_to_analyse
        self.table_to_store = table_to_store

        self.repositories = {'table_to_analyse': BaseRepository(self.table_to_analyse)}

        if self.table_to_store:
            self.repositories['table_to_store'] = BaseRepository(self.table_to_store)

        self.start_date, self.end_date = (
            dt.datetime.strptime(date, self.table_to_analyse.date_format).date()
            for date in (start_date, end_date)
        )
    def test_create_table(self):
        """ Test that tables can be created.

        :raise AssertionError:
        :return None:
        """
        repository = BaseRepository(self.table, autocommit=False)
        repository.create_table()
        assert repository.exists()
Exemplo n.º 3
0
def initialise_database():
    """ Create and initialise the database with all tables in the configuration file.

    :return None:
    """
    for table_name in conf.table_names:
        BaseRepository(Table.get_from_config(table_name)).create_table()
        logger.info('Created table %r', table_name)
Exemplo n.º 4
0
    def __init__(self, table, file):
        """ Initialise a BaseParser.

        :param finances_automation.entities.table.Table table: table to store data in
        :param str file: path to file to read in
        """
        self.table = table
        self.file = file

        self.table_repository = BaseRepository(self.table)
        self.data = None
    def test_load(self):
        """ Ensure data can be loaded from a table.

        :raise AssertionError:
        :return None:
        """
        repository = BaseRepository(self.table, autocommit=False)
        repository.create_table()

        repository.insert(self.example_data)
        repository.load_by_date('2019/1/1', '2020/1/2')

        assert all(self.table.data[['date', 'a', 'b']] == self.example_data[
            ['date', 'a', 'b']])
    def test_insert(self):
        """ Test insertion of data into a table.

        :raise AssertionError:
        :return None:
        """
        repository = BaseRepository(self.table, autocommit=False)
        repository.create_table()

        repository.insert(self.example_data)
    def test_instantiation_and_connection(self):
        """ Ensure the repository can be instantiated and connected to the database.

        :return None:
        """
        BaseRepository(self.table, autocommit=False)