示例#1
0
    def test_converts_amount_field_into_money_object(self, mocks):
        mocks.reader.return_value = [[
            'accountName', 'goalName', 'total', 'startDate'
        ], ['biz', 'baz', '5000,50', '06.06.2017']]
        gc = GoalConnector()
        gc_entry = list(gc.all())[0]

        assert gc_entry['total'] == Money('5000.50', 'RUR')
示例#2
0
    def test_converts_date_field_into_datetime_object(self, mocks):
        mocks.reader.return_value = [[
            'accountName', 'goalName', 'total', 'startDate'
        ], ['foo', 'bar', '1000', '04.05.2016']]
        gc = GoalConnector()
        gc_entry = list(gc.all())[0]

        assert gc_entry['start_date'] == datetime(2016, 5, 4)
示例#3
0
    def test_converts_field_names_from_csv_to_field_names_of_model(
            self, mocks):
        mocks.reader.return_value = [[
            'accountName', 'goalName', 'total', 'startDate'
        ], ['foo', 'bar', '1000', '01.01.2016']]
        gc = GoalConnector()

        actual_dict_keys = sorted(list(gc.all())[0].keys())
        assert actual_dict_keys == sorted(
            ['account', 'name', 'start_date', 'total'])
示例#4
0
    def test_getting_source_prop_1st_time_reads_source_csv_and_stores_content(
            self, mocks):
        gc = GoalConnector()
        _ = gc._source

        mocks.open.assert_called_once_with('path_to_csv_file', 'rb')
        assert gc._data == ['csv\n', 'file\n', 'content\n']
示例#5
0
    def test_all_returns_iterable_of_dicts_formed_from_read_csv_data(
            self, mocks):
        mocks.reader.return_value = [[
            'ship_name', 'ship_class', 'tiryampampation_type'
        ], ['Blackbird 9000', 'striker', 'null-t'],
                                     ['Lux Aeterna', 'wanderer', 'warp']]
        gc = GoalConnector()
        result = list(gc.all())

        assert result == [{
            'ship_name': 'Blackbird 9000',
            'ship_class': 'striker',
            'tiryampampation_type': 'null-t'
        }, {
            'ship_name': 'Lux Aeterna',
            'ship_class': 'wanderer',
            'tiryampampation_type': 'warp'
        }]
示例#6
0
    def test_getting_source_prop_2nd_time_returns_data_prop(self):
        gc = GoalConnector()
        _ = gc._source

        assert gc._source == gc._data
示例#7
0
    def test_getting_source_prop_1st_time_calls_utility_method(self, mocks):
        gc = GoalConnector()
        _ = gc._source

        mocks.get_path.assert_called_once_with('pathToGoalsCsv')
示例#8
0
 def test_goal_connector_is_a_csv_connector(self):
     assert isinstance(GoalConnector(), CsvConnector)