FAQ | This is a LIVE service | Changelog

Commit 76494981 authored by Robin Goodall's avatar Robin Goodall 💬
Browse files

inst mapping tests

parent ab2f73a4
......@@ -17,3 +17,24 @@ def temp_password_file(pwd: str):
if file_name is not None:
class MockResponse():
def __init__(self, data: dict):
self.data = data
def raise_for_status(self):
def json(self) -> dict:
return self.data
class MockSession():
def __init__(self, url: str, data: dict):
self.url = url
self.data = data
def get(self, url: str) -> MockResponse:
assert url == self.url
return MockResponse(self.data)
from unittest import TestCase
import logging
from . import MockSession
from lookupsync.inst_mapping import fetch_inst_mapping, INST_MAPPING_API_ROOT
'institutions': [
"instid": "FOO",
"identifiers": [
# Duplicate of "instid" - not actually used in sync
# current scheme
# depreciated but still valid id
# ignored id but using valid scheme
# invalid scheme
}, {
"instid": "BAR",
"identifiers": [
# current scheme
}, {
"instid": "BAZ",
"identifiers": [
# current scheme
'SRID1': 'FOO',
'SRID2': 'FOO',
'SRID100': 'BAR',
'SRID200': 'BAZ',
class InstMappingTest(TestCase):
def test_fetch_inst_mapping(self):
fetch_inst_mapping gets the response from the institution mapping API and
converts the 'institutions' list returned to a dict of only Student Record
institution ids to Lookup instids
with self.assertLogs(level=logging.WARNING) as captured:
inst_map = fetch_inst_mapping(session)
# Mapping matches expectations
self.assertEqual(inst_map, INST_MAPPING_EXPECTED)
# Warning given for invalid scheme
'Invalid identifier scheme institution.v1.fake.university.identifiers.cam.ac.uk',
[r.getMessage() for r in captured.records])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment