class TestInstitution(OsfTestCase): def setUp(self): super(TestInstitution, self).setUp() self.institution = InstitutionFactory() def test_institution_save_only_changes_mapped_fields_on_node(self): node = self.institution.node old = { 'title': node.title, 'institution_logo_name': node.institution_logo_name, 'system_tags': node.system_tags, 'piwik_site_id': node.piwik_site_id } new = { 'title': ' A Completely Different name omg.', 'institution_logo_name': ' A different ', 'system_tags': ['new_tags', 'other', 'busta', 'rhymes'], 'piwik_site_id': 'is this an id' } self.institution.name = new['title'] self.institution.logo_name = new['institution_logo_name'] self.institution.system_tags = new['system_tags'] self.institution.piwik_site_id = new['piwik_site_id'] self.institution.save() node.reload() #assert changes assert_equal(node.title, new['title']) assert_equal(node.institution_logo_name, new['institution_logo_name']) #assert remained same assert_equal(node.system_tags, old['system_tags']) assert_not_equal(node.system_tags, new['system_tags']) assert_equal(node.piwik_site_id, old['piwik_site_id']) assert_not_equal(node.piwik_site_id, new['piwik_site_id']) def test_institution_mappings(self): for key, val in self.institution.attribute_map.iteritems(): assert_equal(getattr(self.institution, key), getattr(self.institution.node, val)) def test_institution_banner_path_none(self): inst = InstitutionFactory() inst.banner_name = None assert_is_none(inst.banner_path, None) def test_institution_logo_path_none(self): inst = InstitutionFactory() inst.logo_name = None assert_is_none(inst.logo_path, None)
class TestInstitution(OsfTestCase): def setUp(self): super(TestInstitution, self).setUp() self.institution = InstitutionFactory() def tearDown(self): super(TestInstitution, self).tearDown() Node.remove() def test_institution_save_only_changes_mapped_fields_on_node(self): node = self.institution.node old = { 'title': node.title, 'institution_logo_name': node.institution_logo_name, 'system_tags': node.system_tags, } new = { 'title': ' A Completely Different name omg.', 'institution_logo_name': ' A different ', 'system_tags': ['new_tags', 'other', 'busta', 'rhymes'], } self.institution.name = new['title'] self.institution.logo_name = new['institution_logo_name'] self.institution.system_tags = new['system_tags'] self.institution.save() node.reload() #assert changes assert_equal(node.title, new['title']) assert_equal(node.institution_logo_name, new['institution_logo_name']) #assert remained same assert_equal(node.system_tags, old['system_tags']) assert_not_equal(node.system_tags, new['system_tags']) def test_institution_mappings(self): for key, val in self.institution.attribute_map.iteritems(): assert_equal(getattr(self.institution, key), getattr(self.institution.node, val)) def test_institution_banner_path_none(self): inst = InstitutionFactory() inst.banner_name = None assert_is_none(inst.banner_path, None) def test_institution_logo_path_none(self): inst = InstitutionFactory() inst.logo_name = None assert_is_none(inst.logo_path, None) def test_institution_logo_path_rounded_corners(self): inst = InstitutionFactory(logo_name='osf-shield.png') expected_logo_path = '/static/img/institutions/shields-rounded-corners/osf-shield-rounded-corners.png' assert_equal(inst.logo_path_rounded_corners, expected_logo_path) def test_institution_find(self): insts = list(Institution.find()) assert_equal(len(insts), 1) assert_equal(insts[0], self.institution) def test_institution_find_doesnt_find_deleted(self): self.institution.node.is_deleted = True self.institution.node.save() insts = list(Institution.find()) assert_equal(len(insts), 0) def test_find_deleted(self): self.institution.node.is_deleted = True self.institution.node.save() insts = list(Institution.find(deleted=True)) assert_equal(len(insts), 1) assert_equal(insts[0], self.institution)
class TestInstitutionAuth(ApiTestCase): def setUp(self): super(TestInstitutionAuth, self).setUp() self.institution = InstitutionFactory() self.institution.save() self.url = '/{0}institutions/auth/'.format(API_BASE) def tearDown(self): super(TestInstitutionAuth, self).tearDown() self.institution.remove() User.remove() def build_payload(self, username): data = { 'provider': { 'id': self.institution._id, 'user': { 'middleNames': '', 'familyName': '', 'givenName': '', 'fullname': 'Fake User', 'suffix': '', 'username': username } } } return jwe.encrypt(jwt.encode({ 'sub': username, 'data': json.dumps(data) }, settings.JWT_SECRET, algorithm='HS256'), settings.JWE_SECRET) def test_creates_user(self): username = '******' assert_equal(User.find(Q('username', 'eq', username)).count(), 0) with capture_signals() as mock_signals: res = self.app.post(self.url, self.build_payload(username)) assert_equal(res.status_code, 204) assert_equal(mock_signals.signals_sent(), set([signals.user_confirmed])) user = User.find_one(Q('username', 'eq', username)) assert_true(user) assert_in(self.institution, user.affiliated_institutions) def test_adds_institution(self): username = '******' user = User(username=username, fullname='Mr Moco') user.save() with capture_signals() as mock_signals: res = self.app.post(self.url, self.build_payload(username)) assert_equal(res.status_code, 204) assert_equal(mock_signals.signals_sent(), set()) user.reload() assert_in(self.institution, user.affiliated_institutions) def test_finds_user(self): username = '******' user = User(username=username, fullname='Mr Moco') user.affiliated_institutions.append(self.institution) user.save() res = self.app.post(self.url, self.build_payload(username)) assert_equal(res.status_code, 204) user.reload() assert_equal(len(user.affiliated_institutions), 1) def test_bad_token(self): res = self.app.post(self.url, 'al;kjasdfljadf', expect_errors=True) assert_equal(res.status_code, 403)
class TestInstitution(OsfTestCase): def setUp(self): super(TestInstitution, self).setUp() self.institution = InstitutionFactory() def tearDown(self): super(TestInstitution, self).tearDown() Node.remove() def test_institution_save_only_changes_mapped_fields_on_node(self): node = self.institution.node old = { 'title': node.title, 'institution_logo_name': node.institution_logo_name, 'system_tags': node.system_tags, } new = { 'title': ' A Completely Different name omg.', 'institution_logo_name': ' A different ', 'system_tags': ['new_tags', 'other', 'busta', 'rhymes'], } self.institution.name = new['title'] self.institution.logo_name = new['institution_logo_name'] self.institution.system_tags = new['system_tags'] self.institution.save() node.reload() #assert changes assert_equal(node.title, new['title']) assert_equal(node.institution_logo_name, new['institution_logo_name']) #assert remained same assert_equal(node.system_tags, old['system_tags']) assert_not_equal(node.system_tags, new['system_tags']) def test_institution_mappings(self): for key, val in self.institution.attribute_map.iteritems(): assert_equal(getattr(self.institution, key), getattr(self.institution.node, val)) def test_institution_banner_path_none(self): inst = InstitutionFactory() inst.banner_name = None assert_is_none(inst.banner_path, None) def test_institution_logo_path_none(self): inst = InstitutionFactory() inst.logo_name = None assert_is_none(inst.logo_path, None) def test_institution_find(self): insts = list(Institution.find()) assert_equal(len(insts), 1) assert_equal(insts[0], self.institution) def test_institution_find_doesnt_find_deleted(self): self.institution.node.is_deleted = True self.institution.node.save() insts = list(Institution.find()) assert_equal(len(insts), 0) def test_find_deleted(self): self.institution.node.is_deleted = True self.institution.node.save() insts = list(Institution.find(deleted=True)) assert_equal(len(insts), 1) assert_equal(insts[0], self.institution)