Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rosie adapter to load files acording to starting year #476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rosie/rosie/chamber_of_deputies/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def reimbursements(self):
df = pd.DataFrame()
paths = (
str(path) for path in Path(self.path).glob('*.csv')
if match(self.REIMBURSEMENTS_PATTERN, path.name)
if match(self.REIMBURSEMENTS_PATTERN, path.name) and
self.match_starting_year(path.name)
)

for path in paths:
Expand All @@ -69,6 +70,10 @@ def reimbursements(self):

return df

def match_starting_year(self, path_name):
file_year = int(path_name.split('-')[1].split('.')[0])
return file_year >= self.STARTING_YEAR

def update_datasets(self):
self.update_companies()
self.update_reimbursements()
Expand Down
9 changes: 8 additions & 1 deletion rosie/rosie/chamber_of_deputies/tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def setUp(self):
adapter.log.disabled = True
self.dataset = adapter.dataset


def test_load_all_years(self):
self.assertEqual(6, len(self.dataset))

Expand All @@ -69,6 +68,14 @@ def test_is_party_expense_category(self):
party_expenses = self.dataset[self.dataset.is_party_expense == True]
self.assertEqual(1, len(party_expenses))

@freeze_time('2019-02-10')
def test_match_starting_year(self):
adapter = Adapter(self.temp_path)
adapter.STARTING_YEAR = 2018
self.assertEqual(adapter.match_starting_year('reimbursements-2017.csv'), False)
self.assertEqual(adapter.match_starting_year('reimbursements-2018.csv'), True)
self.assertEqual(adapter.match_starting_year('reimbursements-2019.csv'), True)

@freeze_time('2010-11-12')
@patch('rosie.chamber_of_deputies.adapter.fetch')
@patch('rosie.chamber_of_deputies.adapter.Reimbursements')
Expand Down