-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added processing to apply project credits, determine institution name…
… for each PI, and exporting HU and BU invoices
- Loading branch information
Showing
3 changed files
with
245 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"northeastern.edu" : "Northeastern University", | ||
"bu.edu" : "Boston University", | ||
"bentley.edu" : "Bentley", | ||
"uri.edu" : "University of Rhode Island", | ||
"redhat.com" : "Red Hat", | ||
"childrens.harvard.edu" : "Boston Childrens Hospital", | ||
"mclean.harvard.edu" : "McLean Hospital", | ||
"meei.harvard.edu" : "Massachusetts Eye & Ear", | ||
"dfci.harvard.edu" : "Dana-Farber Cancer Institute", | ||
"bwh.harvard.edu" : "Brigham and Women's Hospital", | ||
"bidmc.harvard.edu" : "Beth Israel Deaconess Medical Center", | ||
"harvard.edu" : "Harvard University", | ||
"wpi.edu" : "Worcester Polytechnic Institute", | ||
"mit.edu" : "Massachusetts Institute of Technology", | ||
"umass.edu" : "University of Massachusetts Amherst", | ||
"uml.edu" : "University of Massachusetts Lowell", | ||
"codeforboston.org" : "Code For Boston", | ||
"mmsh" : "Harvard University", | ||
"gstuart" : "University of Massachusetts Amherst", | ||
"rudolph" : "Boston Childrens Hospital", | ||
"robbaron" : "Boston University", | ||
"kmdalton" : "Harvard University", | ||
"mzink" : "University of Massachusetts Amherst", | ||
"yale.edu" : "Yale University", | ||
"francesco.pontiggia" : "Harvard University" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from unittest import TestCase | ||
from unittest import skipIf | ||
import tempfile | ||
import pandas | ||
import os | ||
|
@@ -175,3 +176,65 @@ def test_export_pi(self): | |
self.assertNotIn('ProjectA', pi_df['Project - Allocation'].tolist()) | ||
self.assertNotIn('ProjectB', pi_df['Project - Allocation'].tolist()) | ||
self.assertNotIn('ProjectC', pi_df['Project - Allocation'].tolist()) | ||
|
||
|
||
class TestGetInstitute(TestCase): | ||
|
||
def setUp(self): | ||
|
||
data = { | ||
'Manager (PI)': ['[email protected]', '[email protected]', '[email protected]', 'fake', '[email protected]'], | ||
'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD', 'ProjectE'], | ||
'Answer': ["Boston University", "McLean Hospital", "Harvard University", "", "Northeastern University"] | ||
} | ||
self.data = pandas.DataFrame(data) | ||
|
||
def test_get_pi_institution(self): | ||
for i, row in self.data.iterrows(): | ||
institution_name = process_report.get_institution_from_pi(row['Manager (PI)']) | ||
self.assertEqual(institution_name, row['Answer']) | ||
|
||
@skipIf(process_report.apply_credits_0002 not in process_report.applied_credits, "Skipping test for credit 0002 because credit not enabled") | ||
class TestCredit0002(TestCase): | ||
def setUp(self): | ||
|
||
data = { | ||
'Manager (PI)': ['PI1', 'PI1', 'PI2', 'PI3', 'PI4', 'PI4'], | ||
'Project - Allocation': ['ProjectA', 'ProjectB', 'ProjectC', 'ProjectD', 'ProjectE', 'ProjectF'], | ||
'Cost': [10, 100, 10000, 5000, 800, 1000] | ||
} | ||
self.dataframe = pandas.DataFrame(data) | ||
old_pi = ['PI2', 'PI3'] | ||
old_pi_file = tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.csv') | ||
for pi in old_pi: old_pi_file.write(pi + "\n") | ||
self.old_pi_file = old_pi_file.name | ||
|
||
os.environ["C0002_OLD_PI"] = self.old_pi_file | ||
|
||
def tearDown(self): | ||
os.remove(self.old_pi_file) | ||
|
||
def test_apply_credit_0002(self): | ||
dataframe = process_report.add_credits(self.dataframe) | ||
|
||
self.assertTrue('Credit' in dataframe) | ||
self.assertTrue('Credit Code' in dataframe) | ||
self.assertTrue('Balance' in dataframe) | ||
|
||
credited_projects = dataframe[dataframe['Credit Code'] == '0002'] | ||
|
||
self.assertEqual(4, len(credited_projects.index)) | ||
self.assertTrue('PI2' not in credited_projects['Manager (PI)'].unique()) | ||
self.assertTrue('PI3' not in credited_projects['Manager (PI)'].unique()) | ||
|
||
self.assertEqual(10, credited_projects[credited_projects['Project - Allocation'] == 'ProjectA']['Credit'].iloc[0]) | ||
self.assertEqual(100, credited_projects[credited_projects['Project - Allocation'] == 'ProjectB']['Credit'].iloc[0]) | ||
self.assertEqual(800, credited_projects[credited_projects['Project - Allocation'] == 'ProjectE']['Credit'].iloc[0]) | ||
self.assertEqual(200, credited_projects[credited_projects['Project - Allocation'] == 'ProjectF']['Credit'].iloc[0]) | ||
|
||
self.assertEqual(0, credited_projects[credited_projects['Project - Allocation'] == 'ProjectA']['Balance'].iloc[0]) | ||
self.assertEqual(0, credited_projects[credited_projects['Project - Allocation'] == 'ProjectB']['Balance'].iloc[0]) | ||
self.assertEqual(0, credited_projects[credited_projects['Project - Allocation'] == 'ProjectE']['Balance'].iloc[0]) | ||
self.assertEqual(800, credited_projects[credited_projects['Project - Allocation'] == 'ProjectF']['Balance'].iloc[0]) | ||
|
||
|