class ApiUserKeyTestCase(object):  #unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(api_key=page.settings.add_api_key())
        page.log_out()
        page.close()

    def test_project_title(self):
        project = self.client.add_project(title='Before')

        project.title = 'After'

        self.assertEqual(
            project.title,
            'After',
        )

    def test_subproject_title(self):
        project = self.client.add_project(title='Parent Project')
        subproject = self.client.add_project(title='Before',
                                             parent_id=project.id)

        subproject.title = 'After'

        self.assertEqual(
            subproject.title,
            'After',
        )

    def test_component_title(self):
        project = self.client.add_project(title='Parent Project')
        component = self.client.add_component(title='Before',
                                              parent_id=project.id)

        component.title = 'After'

        self.assertEqual(
            component.title,
            'After',
        )

    def test_nested_component_title(self):
        project = self.client.add_project(title='Parent Project')
        subproject = self.client.add_project(title='Subproject',
                                             parent_id=project.id)
        component = self.client.add_component(title='Before',
                                              parent_id=subproject.id)

        component.title = 'After'

        self.assertEqual(
            component.title,
            'After',
        )
class ApiUserKeyNonContributorTestCase(object):#unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.log_out()

        page = page.user_login.log_in(helpers.create_user())
        self.non_contrib_client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.close()

    def test_project_title_non_contrib(self):
        project = self.client.add_project('Test Project')

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.project(project.id).title

    def test_subproject_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject', parent_id=project.id)

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.project(subproject.id).title

    def test_component_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        component = self.client.add_component(
            'Test Component',
            parent_id=project.id
        )

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.component(
                project_id=project.id,
                component_id=component.id
            ).title

    def test_nested_component_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject', parent_id=project.id)
        component = self.client.add_component(
            'Test Component',
            parent_id=subproject.id
        )

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.component(
                project_id=subproject.id,
                component_id=component.id
            ).title
class NodeAccessTests(object):#unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.close()

    def test_project_api_summary(self):
        project = self.client.add_project('Project')

        self.assertEqual(
            project.title,
            'Project',
        )

        self.assertEqual(
            '{}/project/{}/'.format(osf_home, project.id),
            project.url,
        )

    def test_subproject_api_summary(self):
        project = self.client.add_project('Project')
        subproject = self.client.add_project('Subproject', project.id)

        self.assertEqual(
            subproject.title,
            'Subproject',
        )

    def test_component_api_summary(self):
        project = self.client.add_project('Project')
        component = self.client.add_component('Component', project.id)

        self.assertEqual(
            component.title,
            'Component',
        )

    def test_nested_component_api_summary(self):
        project = self.client.add_project('Project')
        subproject = self.client.add_project('Subproject', project.id)
        component = self.client.add_component('Component', subproject.id)

        self.assertEqual(
            component.title,
            'Component',
        )
示例#4
0
class NodeAccessTests(object):  #unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(api_key=page.settings.add_api_key())
        page.close()

    def test_project_api_summary(self):
        project = self.client.add_project('Project')

        self.assertEqual(
            project.title,
            'Project',
        )

        self.assertEqual(
            '{}/project/{}/'.format(osf_home, project.id),
            project.url,
        )

    def test_subproject_api_summary(self):
        project = self.client.add_project('Project')
        subproject = self.client.add_project('Subproject', project.id)

        self.assertEqual(
            subproject.title,
            'Subproject',
        )

    def test_component_api_summary(self):
        project = self.client.add_project('Project')
        component = self.client.add_component('Component', project.id)

        self.assertEqual(
            component.title,
            'Component',
        )

    def test_nested_component_api_summary(self):
        project = self.client.add_project('Project')
        subproject = self.client.add_project('Subproject', project.id)
        component = self.client.add_component('Component', subproject.id)

        self.assertEqual(
            component.title,
            'Component',
        )
class ApiUserKeyNonContributorTestCase(object):  #unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(api_key=page.settings.add_api_key())
        page.log_out()

        page = page.user_login.log_in(helpers.create_user())
        self.non_contrib_client = OsfClient(
            api_key=page.settings.add_api_key())
        page.close()

    def test_project_title_non_contrib(self):
        project = self.client.add_project('Test Project')

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.project(project.id).title

    def test_subproject_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject',
                                             parent_id=project.id)

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.project(subproject.id).title

    def test_component_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        component = self.client.add_component('Test Component',
                                              parent_id=project.id)

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.component(
                project_id=project.id, component_id=component.id).title

    def test_nested_component_title_non_contrib(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject',
                                             parent_id=project.id)
        component = self.client.add_component('Test Component',
                                              parent_id=subproject.id)

        with self.assertRaises(OsfClientException):
            p = self.non_contrib_client.component(
                project_id=subproject.id, component_id=component.id).title
class ApiNodeKeyTestCase(object):#unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.close()

    def test_project_add_api_key(self):
        project = self.client.add_project('Test Project')
        key = project.add_api_key()

        self.assertIsInstance(key, ApiKey)

    def test_project_edit_title(self):
        project = self.client.add_project('Test Project')
        key = project.add_api_key()

        node_id = project.id
        del project

        osf = OsfClient(api_key=key)
        project = osf.project(project_id=node_id)
        project.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            project.title,
        )

    def test_subproject_edit_title(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project(
            'Subproject',
            parent_id=project.id
        )
        key = subproject.add_api_key()

        node_id = subproject.id

        osf = OsfClient(api_key=key)
        node = osf.project(project_id=node_id)
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )

    def test_component_edit_title(self):
        project = self.client.add_project('Test Project')
        component = self.client.add_component(
            'Component',
            parent_id=project.id
        )
        key = component.add_api_key()

        node_id = component.id

        osf = OsfClient(api_key=key)
        node = osf.component(project_id=project.id, component_id=node_id)
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )

    def test_nested_component_edit_title(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project(
            'Subproject',
            parent_id=project.id
        )
        component = self.client.add_component(
            'Component',
            parent_id=subproject.id,
        )
        key = component.add_api_key()

        node_id = component.id

        osf = OsfClient(api_key=key)
        node = osf.component(
            component_id=node_id,
            project_id=subproject.id,
        )
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )
class ApiUserKeyTestCase(object):#unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.log_out()
        page.close()

    def test_project_title(self):
        project = self.client.add_project(title='Before')

        project.title = 'After'

        self.assertEqual(
            project.title,
            'After',
        )

    def test_subproject_title(self):
        project = self.client.add_project(title='Parent Project')
        subproject = self.client.add_project(
            title='Before',
            parent_id=project.id
        )

        subproject.title = 'After'

        self.assertEqual(
            subproject.title,
            'After',
        )

    def test_component_title(self):
        project = self.client.add_project(title='Parent Project')
        component = self.client.add_component(
            title='Before',
            parent_id=project.id
        )

        component.title = 'After'

        self.assertEqual(
            component.title,
            'After',
        )

    def test_nested_component_title(self):
        project = self.client.add_project(title='Parent Project')
        subproject = self.client.add_project(
            title='Subproject',
            parent_id=project.id
        )
        component = self.client.add_component(
            title='Before',
            parent_id=subproject.id
        )

        component.title = 'After'

        self.assertEqual(
            component.title,
            'After',
        )
class ApiUserProfilesTestCase(object):#unittest.TestCase):
    def setUp(self):
        self.user = helpers.create_user()
        page = LoginPage().log_in(self.user)
        key = page.settings.add_api_key()
        page.close()

        self.client = OsfClient(api_key=key)

    def test_own_profile(self):
        profile = self.client.user()

        self.assertEqual(
            self.user.full_name,
            profile.full_name,
        )

    def test_others_profile(self):
        own_profile = self.client.user()

        # Create another user, get their API key
        other_user = helpers.create_user()
        page = LoginPage().log_in(other_user)
        key = page.settings.add_api_key()
        page.close()

        other_client = OsfClient(api_key=key)
        other_profile = self.client.user(user_id=other_client.user().id)

        self.assertNotEqual(
            own_profile.id,
            other_profile.id,
        )

    def test_api_keys(self):
        self.assertEqual(1, len(self.client.user().api_keys))

    def test_create_api_key(self):
        profile = self.client.user()
        self.assertEqual(1, len(profile.api_keys))

        new_key = profile.add_api_key('Fizzpop')

        self.assertIsInstance(new_key, ApiKey)
        self.assertEqual(2, len(profile.api_keys))

        self.assertIn(
            'Fizzpop',
            [x.label for x in profile.api_keys]
        )

    def test_revoke_api_key(self):
        new_key = self.client.user().add_api_key('FizzPop')

        new_client = OsfClient(api_key=new_key)

        self.client.user().revoke_api_key(new_key)

        self.assertNotIn(
            new_key,
            self.client.user().api_keys
        )

        with self.assertRaises(OsfClientException):
            user = new_client.user()

    def test_api_key_history(self):
        user = self.client.user()

        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Test Subproject',
                                             parent_id=project.id)
        component = self.client.add_component('Test Component',
                                              parent_id=subproject.id)

        project.title = 'Foo'
        subproject.title = 'Bar'
        component.title = 'Baz'
        project.public = True


        print user.api_key_history(
            key=user.api_keys[0]
        )

    def test_date_registered(self):
        self.assertEqual(
            dt.date.today(),
            self.client.user().date_registered,
        )

    def test_activity_points_increment(self):
        self.assertEqual(0, self.client.user().activity_points)

        self.client.add_project('Test Project')

        self.assertEqual(1, self.client.user().activity_points)

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_project_counts_private_project(self):
        self.assertEqual(0, self.client.user().total_project_count)

        project = self.client.add_project("Test Project")

        info = self.client.user()

        self.assertEqual(0, info.public_project_count)
        self.assertEqual(1, info.private_project_count)
        self.assertEqual(1, info.total_project_count)

        project.public = True

        info = self.client.user()

        self.assertEqual(1, info.public_project_count)
        self.assertEqual(0, info.private_project_count)
        self.assertEqual(1, info.total_project_count)

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_public_projects(self):
        self.assertEqual(0, len(self.client.user().public_projects))

        project = self.client.add_project('Test Project')
        project.public = True

        self.assertEqual(1, len(self.client.user().public_projects))

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_public_components(self):
        self.assertEqual(0, len(self.client.user().public_components))

        project = self.client.add_project('Test Project')
        component = self.client.add_component(
            title='Test Component',
            parent_id=project.id,
            category='Hypothesis',
        )

        component.public = True

        self.assertEqual(1, len(self.client.user().public_components))
示例#9
0
class ApiUserKeyCreateNodeTestCase(object):  #unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(api_key=page.settings.add_api_key())
        page.close()

    def test_create_project(self):
        # A project should be returned
        self.assertIsInstance(
            self.client.add_project('New Project'),
            OsfProject,
        )

    def test_create_subproject(self):
        parent = self.client.add_project('New Project')

        subproject = self.client.add_project('Subproject', parent_id=parent.id)

        # a project should be returned ...
        self.assertIsInstance(
            subproject,
            OsfProject,
        )

        # ... and its parent should be set
        self.assertEqual(
            subproject.parent_id,
            parent.id,
        )

    def test_create_component(self):
        parent = self.client.add_project('Parent Project')
        component = self.client.add_component('Test Component',
                                              parent.id,
                                              category='Hypothesis')

        # a component should be returned ...
        self.assertIsInstance(
            component,
            OsfComponent,
        )

        # ... and its parent should be set
        self.assertEqual(component.parent_id, parent.id)

    def test_create_nested_component(self):
        parent_project = self.client.add_project('New Project')

        subproject = self.client.add_project('Subproject', parent_project.id)

        component = self.client.add_component('Test Component',
                                              subproject.id,
                                              category='Hypothesis')

        # a component should be returned ...
        self.assertIsInstance(
            component,
            OsfComponent,
        )

        # ... and its parent should be set
        self.assertEqual(
            component.parent_id,
            subproject.id,
        )
class ApiUserKeyCreateNodeTestCase(object):#unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(
            api_key=page.settings.add_api_key()
        )
        page.close()

    def test_create_project(self):
        # A project should be returned
        self.assertIsInstance(
            self.client.add_project('New Project'),
            OsfProject,
        )

    def test_create_subproject(self):
        parent = self.client.add_project('New Project')

        subproject = self.client.add_project(
            'Subproject',
            parent_id=parent.id
        )

        # a project should be returned ...
        self.assertIsInstance(
            subproject,
            OsfProject,
        )

        # ... and its parent should be set
        self.assertEqual(
            subproject.parent_id,
            parent.id,
        )

    def test_create_component(self):
        parent = self.client.add_project('Parent Project')
        component = self.client.add_component(
            'Test Component',
            parent.id,
            category='Hypothesis'
        )

        # a component should be returned ...
        self.assertIsInstance(
            component,
            OsfComponent,
        )

        # ... and its parent should be set
        self.assertEqual(
            component.parent_id,
            parent.id
        )

    def test_create_nested_component(self):
        parent_project = self.client.add_project('New Project')

        subproject = self.client.add_project(
            'Subproject',
            parent_project.id
        )

        component = self.client.add_component(
            'Test Component',
            subproject.id,
            category='Hypothesis'
        )

        # a component should be returned ...
        self.assertIsInstance(
            component,
            OsfComponent,
        )

        # ... and its parent should be set
        self.assertEqual(
            component.parent_id,
            subproject.id,
        )
class ApiUserProfilesTestCase(object):  #unittest.TestCase):
    def setUp(self):
        self.user = helpers.create_user()
        page = LoginPage().log_in(self.user)
        key = page.settings.add_api_key()
        page.close()

        self.client = OsfClient(api_key=key)

    def test_own_profile(self):
        profile = self.client.user()

        self.assertEqual(
            self.user.full_name,
            profile.full_name,
        )

    def test_others_profile(self):
        own_profile = self.client.user()

        # Create another user, get their API key
        other_user = helpers.create_user()
        page = LoginPage().log_in(other_user)
        key = page.settings.add_api_key()
        page.close()

        other_client = OsfClient(api_key=key)
        other_profile = self.client.user(user_id=other_client.user().id)

        self.assertNotEqual(
            own_profile.id,
            other_profile.id,
        )

    def test_api_keys(self):
        self.assertEqual(1, len(self.client.user().api_keys))

    def test_create_api_key(self):
        profile = self.client.user()
        self.assertEqual(1, len(profile.api_keys))

        new_key = profile.add_api_key('Fizzpop')

        self.assertIsInstance(new_key, ApiKey)
        self.assertEqual(2, len(profile.api_keys))

        self.assertIn('Fizzpop', [x.label for x in profile.api_keys])

    def test_revoke_api_key(self):
        new_key = self.client.user().add_api_key('FizzPop')

        new_client = OsfClient(api_key=new_key)

        self.client.user().revoke_api_key(new_key)

        self.assertNotIn(new_key, self.client.user().api_keys)

        with self.assertRaises(OsfClientException):
            user = new_client.user()

    def test_api_key_history(self):
        user = self.client.user()

        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Test Subproject',
                                             parent_id=project.id)
        component = self.client.add_component('Test Component',
                                              parent_id=subproject.id)

        project.title = 'Foo'
        subproject.title = 'Bar'
        component.title = 'Baz'
        project.public = True

        print user.api_key_history(key=user.api_keys[0])

    def test_date_registered(self):
        self.assertEqual(
            dt.date.today(),
            self.client.user().date_registered,
        )

    def test_activity_points_increment(self):
        self.assertEqual(0, self.client.user().activity_points)

        self.client.add_project('Test Project')

        self.assertEqual(1, self.client.user().activity_points)

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_project_counts_private_project(self):
        self.assertEqual(0, self.client.user().total_project_count)

        project = self.client.add_project("Test Project")

        info = self.client.user()

        self.assertEqual(0, info.public_project_count)
        self.assertEqual(1, info.private_project_count)
        self.assertEqual(1, info.total_project_count)

        project.public = True

        info = self.client.user()

        self.assertEqual(1, info.public_project_count)
        self.assertEqual(0, info.private_project_count)
        self.assertEqual(1, info.total_project_count)

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_public_projects(self):
        self.assertEqual(0, len(self.client.user().public_projects))

        project = self.client.add_project('Test Project')
        project.public = True

        self.assertEqual(1, len(self.client.user().public_projects))

    @unittest.skip('Fails - public/private routes not yet implemented')
    def test_public_components(self):
        self.assertEqual(0, len(self.client.user().public_components))

        project = self.client.add_project('Test Project')
        component = self.client.add_component(
            title='Test Component',
            parent_id=project.id,
            category='Hypothesis',
        )

        component.public = True

        self.assertEqual(1, len(self.client.user().public_components))
class ApiNodeKeyTestCase(object):  #unittest.TestCase):
    def setUp(self):
        page = LoginPage().log_in(helpers.create_user())
        self.client = OsfClient(api_key=page.settings.add_api_key())
        page.close()

    def test_project_add_api_key(self):
        project = self.client.add_project('Test Project')
        key = project.add_api_key()

        self.assertIsInstance(key, ApiKey)

    def test_project_edit_title(self):
        project = self.client.add_project('Test Project')
        key = project.add_api_key()

        node_id = project.id
        del project

        osf = OsfClient(api_key=key)
        project = osf.project(project_id=node_id)
        project.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            project.title,
        )

    def test_subproject_edit_title(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject',
                                             parent_id=project.id)
        key = subproject.add_api_key()

        node_id = subproject.id

        osf = OsfClient(api_key=key)
        node = osf.project(project_id=node_id)
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )

    def test_component_edit_title(self):
        project = self.client.add_project('Test Project')
        component = self.client.add_component('Component',
                                              parent_id=project.id)
        key = component.add_api_key()

        node_id = component.id

        osf = OsfClient(api_key=key)
        node = osf.component(project_id=project.id, component_id=node_id)
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )

    def test_nested_component_edit_title(self):
        project = self.client.add_project('Test Project')
        subproject = self.client.add_project('Subproject',
                                             parent_id=project.id)
        component = self.client.add_component(
            'Component',
            parent_id=subproject.id,
        )
        key = component.add_api_key()

        node_id = component.id

        osf = OsfClient(api_key=key)
        node = osf.component(
            component_id=node_id,
            project_id=subproject.id,
        )
        node.title = 'Title Changed'

        self.assertEqual(
            'Title Changed',
            node.title,
        )