def setUp(self):
        super(TestNodeRelationshipInstitutions, self).setUp()

        self.institution2 = InstitutionFactory()
        self.institution1 = InstitutionFactory()

        self.user = AuthUserFactory()
        self.user.affiliated_institutions.append(self.institution1)
        self.user.affiliated_institutions.append(self.institution2)
        self.user.save()

        self.read_write_contributor = AuthUserFactory()
        self.read_write_contributor_institution = InstitutionFactory()
        self.read_write_contributor.affiliated_institutions.append(
            self.read_write_contributor_institution)
        self.read_write_contributor.save()

        self.read_only_contributor = AuthUserFactory()
        self.read_only_contributor_institution = InstitutionFactory()
        self.read_only_contributor.affiliated_institutions.append(
            self.read_only_contributor_institution)
        self.read_only_contributor.save()

        self.node = NodeFactory(creator=self.user)
        self.node.add_contributor(self.read_write_contributor,
                                  permissions=[permissions.WRITE])
        self.node.add_contributor(self.read_only_contributor,
                                  permissions=[permissions.READ])
        self.node.save()

        self.node_institutions_url = '/{0}nodes/{1}/relationships/institutions/'.format(
            API_BASE, self.node._id)
 def setUp(self):
     super(TestUserInstititutionRelationship, self).setUp()
     self.user = AuthUserFactory()
     self.user2 = AuthUserFactory()
     self.url = '/{}users/{}/relationships/institutions/'.format(
         API_BASE, self.user._id)
     self.institution1 = InstitutionFactory()
     self.institution2 = InstitutionFactory()
     self.user.affiliated_institutions.append(self.institution1)
     self.user.affiliated_institutions.append(self.institution2)
     self.user.save()
Esempio n. 3
0
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)
 def setUp(self):
     super(TestNodeRelationshipInstitution, self).setUp()
     self.user = AuthUserFactory()
     self.institution = InstitutionFactory()
     self.node = NodeFactory(is_public=True)
     self.node_institution_url = '/{0}nodes/{1}/relationships/institution/'.format(
         API_BASE, self.node._id)
 def setUp(self):
     super(TestNodeInstitutionDetail, self).setUp()
     self.institution = InstitutionFactory()
     self.node = NodeFactory(is_public=True)
     self.node.primary_institution = self.institution
     self.node.save()
     self.user = AuthUserFactory()
     self.node2 = NodeFactory(creator=self.user)
 def setUp(self):
     super(TestNodeInstitutionDetail, self).setUp()
     self.institution = InstitutionFactory()
     self.node = NodeFactory(is_public=True)
     self.node.affiliated_institutions.append(self.institution)
     self.node.save()
     self.user = AuthUserFactory()
     self.node2 = NodeFactory(creator=self.user)
Esempio n. 7
0
    def setUp(self):
        super(TestInstitutionUsersList, self).setUp()
        self.institution = InstitutionFactory()
        self.user1 = UserFactory()
        self.user1.affiliated_institutions.append(self.institution)
        self.user1.save()
        self.user2 = UserFactory()
        self.user2.affiliated_institutions.append(self.institution)
        self.user2.save()

        self.institution_user_url = '/{0}institutions/{1}/users/'.format(API_BASE, self.institution._id)
Esempio n. 8
0
    def setUp(self):
        super(TestInstitutionNodeList, self).setUp()
        self.institution = InstitutionFactory()
        self.node1 = ProjectFactory(is_public=True)
        self.node1.affiliated_institutions.append(self.institution)
        self.node1.save()
        self.user1 = AuthUserFactory()
        self.node2 = ProjectFactory(creator=self.user1, is_public=False)
        self.node2.affiliated_institutions.append(self.institution)
        self.node2.save()
        self.node3 = ProjectFactory(is_public=False)
        self.node3.affiliated_institutions.append(self.institution)
        self.node3.save()

        self.institution_node_url = '/{0}institutions/{1}/nodes/'.format(
            API_BASE, self.institution._id)
 def setUp(self):
     super(TestInstitutionRelationshipNodes, self).setUp()
     self.user = AuthUserFactory()
     self.institution = InstitutionFactory()
     self.user.affiliated_institutions.append(self.institution)
     self.user.save()
     self.node1 = NodeFactory(creator=self.user)
     self.node2 = NodeFactory(is_public=True)
     self.node3 = NodeFactory()
     self.node1.affiliated_institutions.append(self.institution)
     self.node2.affiliated_institutions.append(self.institution)
     self.node3.affiliated_institutions.append(self.institution)
     self.node1.save()
     self.node2.save()
     self.node3.save()
     self.institution_nodes_url = '/{}institutions/{}/relationships/nodes/'.format(API_BASE, self.institution._id)
    def setUp(self):
        super(TestInstitutionRegistrationList, self).setUp()
        self.institution = InstitutionFactory()
        self.registration1 = RegistrationFactory(is_public=True, is_registration=True)
        self.registration1.primary_institution = self.institution
        self.registration1.save()
        self.user1 = AuthUserFactory()
        self.user2 = AuthUserFactory()
        self.registration2 = RegistrationFactory(creator=self.user1, is_public=False, is_registration=True)
        self.registration2.primary_institution = self.institution
        self.registration2.add_contributor(self.user2, auth=Auth(self.user1))
        self.registration2.save()
        self.registration3 = RegistrationFactory(creator=self.user2, is_public=False, is_registration=True)
        self.registration3.primary_institution = self.institution
        self.registration3.save()

        self.institution_node_url = '/{0}institutions/{1}/registrations/'.format(API_BASE, self.institution._id)
Esempio n. 11
0
    def setUp(self):
        super(TestInstitutionNodeList, self).setUp()
        self.institution = InstitutionFactory()
        self.node1 = NodeFactory(is_public=True)
        self.node1.primary_institution = self.institution
        self.node1.save()
        self.user1 = AuthUserFactory()
        self.user2 = AuthUserFactory()
        self.node2 = NodeFactory(creator=self.user1, is_public=False)
        self.node2.primary_institution = self.institution
        self.node2.add_contributor(self.user2, auth=Auth(self.user1))
        self.node2.save()
        self.node3 = NodeFactory(creator=self.user2, is_public=False)
        self.node3.primary_institution = self.institution
        self.node3.save()

        self.institution_node_url = '/{0}institutions/{1}/nodes/'.format(
            API_BASE, self.institution._id)
Esempio n. 12
0
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)
Esempio n. 13
0
 def setUp(self):
     super(TestInstitution, self).setUp()
     self.institution = InstitutionFactory()
Esempio n. 14
0
 def setUp(self):
     super(TestInstitutionList, self).setUp()
     self.institution = InstitutionFactory()
     self.institution2 = InstitutionFactory()
     self.institution_url = '/{}institutions/'.format(API_BASE)
Esempio n. 15
0
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)
Esempio n. 16
0
 def test_institution_banner_path_none(self):
     inst = InstitutionFactory()
     inst.banner_name = None
     assert_is_none(inst.banner_path, None)
Esempio n. 17
0
 def setUp(self):
     super(TestInstitution, self).setUp()
     self.institution = InstitutionFactory()
Esempio n. 18
0
 def test_institution_logo_path_none(self):
     inst = InstitutionFactory()
     inst.logo_name = None
     assert_is_none(inst.logo_path, None)
Esempio n. 19
0
 def test_institution_banner_path_none(self):
     inst = InstitutionFactory()
     inst.banner_name = None
     assert_is_none(inst.banner_path, None)
Esempio n. 20
0
 def setUp(self):
     super(TestInstitutionAuth, self).setUp()
     self.institution = InstitutionFactory()
     self.institution.save()
     self.url = '/{0}institutions/auth/'.format(API_BASE)
Esempio n. 21
0
 def setUp(self):
     super(TestInstitutionDetail, self).setUp()
     self.institution = InstitutionFactory()
     self.institution_url = '/' + API_BASE + 'institutions/{id}/'
Esempio n. 22
0
 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)
Esempio n. 23
0
 def test_institution_logo_path_none(self):
     inst = InstitutionFactory()
     inst.logo_name = None
     assert_is_none(inst.logo_path, None)
Esempio n. 24
0
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)