be more forgiving of bad affiliation date ranges
Scan all affiliations and take the latest one that has a start date that makes it valid for the date in question. This works around the fact that there is a bug in the web UI for the foundation site making it difficult for users to modify their existing affiliations. Change-Id: I369d777e0ef2064fc728f9042d9b0e3eca84d350 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
79acba8388
commit
eefd29b96b
@ -104,9 +104,14 @@ class Member:
|
||||
return affiliation
|
||||
|
||||
def find_affiliation(self, when):
|
||||
for affiliation in self.affiliations:
|
||||
if affiliation.active(when):
|
||||
return affiliation
|
||||
candidates = [
|
||||
affiliation
|
||||
for affiliation in self.affiliations
|
||||
if affiliation.active(when)
|
||||
]
|
||||
if candidates:
|
||||
return candidates[-1]
|
||||
return None
|
||||
|
||||
|
||||
def lookup_member(email):
|
||||
|
@ -95,6 +95,32 @@ class TestFoundationMember(base.TestCase):
|
||||
a.organization,
|
||||
)
|
||||
|
||||
def test_find_affiliation_two_open_date_ranges(self):
|
||||
# Insert another affiliation at the end of the list without
|
||||
# including an end_date so that two records match the date.
|
||||
self.m._data['affiliations'].append({
|
||||
"created": 1525022430,
|
||||
"start_date": 1458518400,
|
||||
"owner_id": 359,
|
||||
"last_edited": 1525022430,
|
||||
"id": 156410,
|
||||
"is_current": True,
|
||||
"job_title": "Super Hacker",
|
||||
"organization": {
|
||||
"id": 7297,
|
||||
"created": 1422355350,
|
||||
"name": "Hackers 'R Us",
|
||||
"last_edited": 1422355350
|
||||
},
|
||||
"end_date": None,
|
||||
})
|
||||
|
||||
a = self.m.find_affiliation(datetime.datetime(2016, 4, 17))
|
||||
self.assertEqual(
|
||||
"Hackers 'R Us",
|
||||
a.organization,
|
||||
)
|
||||
|
||||
|
||||
class TestFetchMember(base.TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user