Skip to content

Commit 92534b7

Browse files
committed
test: updates test cases for funder.json endpoint
1 parent 1744096 commit 92534b7

2 files changed

Lines changed: 78 additions & 5 deletions

File tree

registry/tests/mock_simple_salesforce/threesixty.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class MockSimpleSalesforce360Giving(MockSimpleSalesforce):
9393
},
9494
]
9595

96+
FUNDER_STATUSES = [
97+
"Funder in GrantNav",
98+
"360Giving Publisher",
99+
"Something else",
100+
None,
101+
]
102+
96103
def __init__(self, **kwargs) -> None:
97104
"""Initialise a Mock SimpleSalesforce object setup to represent the 360 Registry
98105
@@ -110,6 +117,17 @@ def __init__(self, **kwargs) -> None:
110117
"Authorised_Domain",
111118
"Self_registration_enabled",
112119
"Last_published_date",
120+
"Publisher_Prefix_Combined",
121+
"Publisher_Prefix",
122+
"Org_Case_Safe_ID",
123+
"X360Giving_Publisher",
124+
"Sectors",
125+
"Sector_Organisation_type",
126+
"Sector_Organisation_sub_type",
127+
"First_Published_Date",
128+
"Latest_Published_Date",
129+
"Update_schedule",
130+
"Update_Method",
113131
]
114132
)
115133

@@ -181,21 +199,31 @@ def _generate_accounts(self, num: int, num_with_no_prefix: int) -> None:
181199
else None
182200
)
183201
base_url = random_invalid_base_url(self.rnd)
202+
prefix = f"360G-CT{index+1}" if index > (num_with_no_prefix - 1) else None
184203
self.create_record(
185204
"Account",
186205
{
187206
"Name": f"Charitable Trust {index+1}",
188207
"Logo__c": logo,
189208
"Website": base_url + "index.html",
190-
"prefix__c": (
191-
f"360G-CT{index+1}"
192-
if index > (num_with_no_prefix - 1)
193-
else None
194-
),
209+
"prefix__c": prefix,
195210
"Org_Identifier__c": random_orgid(self.rnd),
196211
"Authorised_Domain__c": base_url,
197212
"Self_registration_enabled__c": False,
198213
"Last_published_date__c": datetime(1900, 1, 1, 0, 0, 0),
214+
"Publisher_Prefix_Combined__c": prefix,
215+
"Publisher_Prefix__c": prefix,
216+
"Org_Case_Safe_ID__c": f"case-safe-{index+1}",
217+
"X360Giving_Publisher__c": self.FUNDER_STATUSES[
218+
index % len(self.FUNDER_STATUSES)
219+
],
220+
"Sectors__c": "Health",
221+
"Sector_Organisation_type__c": "Charity",
222+
"Sector_Organisation_sub_type__c": "Grant-maker",
223+
"First_Published_Date__c": datetime(2017, 1, 1, 0, 0, 0),
224+
"Latest_Published_Date__c": datetime(1900, 1, 1, 0, 0, 0),
225+
"Update_schedule__c": "Quarterly",
226+
"Update_Method__c": "API",
199227
},
200228
)
201229

registry/tests/test_views.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_views(self):
3838
reverse_lazy("ui:index"),
3939
reverse_lazy("data"),
4040
reverse_lazy("publishers"),
41+
reverse_lazy("funders"),
4142
]
4243

4344
for url in urls:
@@ -65,3 +66,47 @@ def test_json_length(self):
6566
"distribution",
6667
]:
6768
self.assertIn(key, data[0].keys())
69+
70+
def test_funders_json(self):
71+
response = self.client.get(reverse_lazy("funders"))
72+
data = response.json()
73+
74+
cur = self.mock_sf.con.cursor()
75+
expected_ids = [
76+
row[0]
77+
for row in cur.execute(
78+
"SELECT Id FROM Account WHERE "
79+
"X360Giving_Publisher__c = 'Funder in GrantNav' "
80+
"OR X360Giving_Publisher__c = '360Giving Publisher';"
81+
).fetchall()
82+
]
83+
84+
self.assertEqual(sorted(data.keys()), sorted(expected_ids))
85+
86+
for account_id, funder in data.items():
87+
self.assertEqual(funder["id"], account_id)
88+
self.assertIn(
89+
funder["x360GivingPublisher"],
90+
["Funder in GrantNav", "360Giving Publisher"],
91+
)
92+
for key in ["name", "prefix", "orgIdentifier"]:
93+
self.assertIn(key, funder.keys())
94+
95+
def test_funders_json_excludes_non_funders(self):
96+
response = self.client.get(reverse_lazy("funders"))
97+
data = response.json()
98+
99+
cur = self.mock_sf.con.cursor()
100+
excluded_ids = [
101+
row[0]
102+
for row in cur.execute(
103+
"SELECT Id FROM Account WHERE "
104+
"X360Giving_Publisher__c IS NULL "
105+
"OR (X360Giving_Publisher__c != 'Funder in GrantNav' "
106+
"AND X360Giving_Publisher__c != '360Giving Publisher');"
107+
).fetchall()
108+
]
109+
110+
self.assertTrue(len(excluded_ids) > 0)
111+
for account_id in excluded_ids:
112+
self.assertNotIn(account_id, data.keys())

0 commit comments

Comments
 (0)