当前位置: 首页>>代码示例>>Python>>正文


Python UserFactory.watch方法代码示例

本文整理汇总了Python中tests.factories.UserFactory.watch方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.watch方法的具体用法?Python UserFactory.watch怎么用?Python UserFactory.watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.factories.UserFactory的用法示例。


在下文中一共展示了UserFactory.watch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAUser

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import watch [as 别名]
class TestAUser(OsfTestCase):

    def setUp(self):
        super(TestAUser, self).setUp()
        self.user = UserFactory()
        self.user.set_password('science')
        # Add an API key for quicker authentication
        api_key = ApiKeyFactory()
        self.user.api_keys.append(api_key)
        self.user.save()
        self.auth = ('test', api_key._primary_key)

    def _login(self, username, password):
        '''Log in a user via at the login page.'''
        res = self.app.get('/account/').maybe_follow()
        # Fills out login info
        form = res.forms['signinForm']  # Get the form from its ID
        form['username'] = username
        form['password'] = password
        # submits
        res = form.submit().maybe_follow()
        return res

    def test_can_see_profile_url(self):
        res = self.app.get(self.user.url).maybe_follow()
        assert_in(self.user.url, res)

    def test_can_see_homepage(self):
        # Goes to homepage
        res = self.app.get('/').maybe_follow()  # Redirects
        assert_equal(res.status_code, 200)

    def test_can_log_in(self):
        # Log in and out
        self._login(self.user.username, 'science')
        self.app.get('/logout/')
        # Goes to home page
        res = self.app.get('/').maybe_follow()
        # Clicks sign in button
        res = res.click('Create an Account or Sign-In').maybe_follow()
        # Fills out login info
        form = res.forms['signinForm']  # Get the form from its ID
        form['username'] = self.user.username
        form['password'] = 'science'
        # submits
        res = form.submit().maybe_follow()
        # Sees dashboard with projects and watched projects
        assert_in('Projects', res)
        assert_in('Watchlist', res)

    def test_sees_flash_message_on_bad_login(self):
        # Goes to log in page
        res = self.app.get('/account/').maybe_follow()
        # Fills the form with incorrect password
        form  = res.forms['signinForm']
        form['username'] = self.user.username
        form['password'] = 'thisiswrong'
        # Submits
        res = form.submit()
        # Sees a flash message
        assert_in('Log-in failed', res)

    def test_is_redirected_to_dashboard_already_logged_in_at_login_page(self):
        res = self._login(self.user.username, 'science')
        res = self.app.get('/login/').follow()
        assert_equal(res.request.path, '/dashboard/')

    def test_sees_projects_in_her_dashboard(self):
        # the user already has a project
        project = ProjectFactory(creator=self.user)
        project.add_contributor(self.user)
        project.save()
        # Goes to homepage, already logged in
        res = self._login(self.user.username, 'science')
        res = self.app.get('/').maybe_follow()
        # Clicks Dashboard link in navbar
        res = res.click('Dashboard', index=0)
        assert_in('Projects', res)  # Projects heading
        # The project title is listed
        # TODO: (bgeiger) figure out how to make this assertion work with hgrid view
        #assert_in(project.title, res)

    def test_does_not_see_osffiles_in_user_addon_settings(self):
        res = self._login(self.user.username, 'science')
        res = self.app.get('/settings/addons/', auth=self.auth, auto_follow=True)
        assert_not_in('OSF Storage', res)

    def test_sees_osffiles_in_project_addon_settings(self):
        project = ProjectFactory(creator=self.user)
        project.add_contributor(
            self.user,
            permissions=['read', 'write', 'admin'],
            save=True)
        res = self.app.get('/{0}/settings/'.format(project._primary_key), auth=self.auth, auto_follow=True)
        assert_in('OSF Storage', res)

    @unittest.skip("Can't test this, since logs are dynamically loaded")
    def test_sees_log_events_on_watched_projects(self):
        # Another user has a public project
        u2 = UserFactory(username='[email protected]', fullname='Bono')
#.........这里部分代码省略.........
开发者ID:lbanner,项目名称:osf.io,代码行数:103,代码来源:webtest_tests.py

示例2: TestWatching

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import watch [as 别名]
class TestWatching(OsfTestCase):

    def setUp(self):
        super(TestWatching, self).setUp()
        self.user = UserFactory()
        self.project = ProjectFactory(creator=self.user)
        # add some log objects
        api_key = ApiKeyFactory()
        self.user.api_keys.append(api_key)
        self.user.save()
        self.consolidate_auth = Auth(user=self.user, api_key=api_key)
        # Clear project logs
        self.project.logs = []
        self.project.save()
        # A log added 100 days ago
        self.project.add_log(
            'project_created',
            params={'project': self.project._primary_key},
            auth=self.consolidate_auth,
            log_date=dt.datetime.utcnow() - dt.timedelta(days=100),
            save=True,
        )
        # Set the ObjectId to correspond with the log date
        # A log added now
        self.last_log = self.project.add_log(
            'tag_added',
            params={'project': self.project._primary_key},
            auth=self.consolidate_auth, log_date=dt.datetime.utcnow(),
            save=True,
        )
        # Clear watched list
        self.user.watched = []
        self.user.save()

    def test_watch_adds_to_watched_list(self):
        n_watched_then = len(self.user.watched)
        # A user watches a WatchConfig
        config = WatchConfigFactory(node=self.project)
        self.user.watch(config)
        n_watched_now = len(self.user.watched)
        assert_equal(n_watched_now, n_watched_then + 1)
        assert_true(self.user.is_watching(self.project))

    def test_unwatch_removes_from_watched_list(self):
        # The user has already watched a project
        self._watch_project(self.project)
        config = WatchConfigFactory(node=self.project)
        n_watched_then = len(self.user.watched)
        self.user.unwatch(config)
        n_watched_now = len(self.user.watched)
        assert_equal(n_watched_now, n_watched_then - 1)
        assert_false(self.user.is_watching(self.project))

    @unittest.skip("Won't work because the old log's id doesn't encode the "
                   "correct log date")
    def test_get_recent_log_ids(self):
        self._watch_project(self.project)
        log_ids = list(self.user.get_recent_log_ids())
        assert_equal(self.last_log._id, log_ids[0])
        # This part won't work
        # TODO(sloria): Rethink.
        assert_equal(len(log_ids), 1)

    def test_get_recent_log_ids_since(self):
        self._watch_project(self.project)
        since = dt.datetime.utcnow().replace(tzinfo=utc) - dt.timedelta(days=101)
        log_ids = list(self.user.get_recent_log_ids(since=since))
        assert_equal(len(log_ids), 2)

    def test_get_daily_digest_log_ids(self):
        self._watch_project(self.project)
        day_log_ids = list(self.user.get_daily_digest_log_ids())
        assert_in(self.last_log._id, day_log_ids)

    def _watch_project(self, project):
        watch_config = WatchConfigFactory(node=project)
        self.user.watch(watch_config)
        self.user.save()

    def _unwatch_project(self, project):
        watch_config = WatchConfigFactory(node=project)
        self.user.watch(watch_config)
        self.user.save()
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:85,代码来源:test_watch.py

示例3: TestWatching

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import watch [as 别名]
class TestWatching(OsfTestCase):

    def setUp(self):
        super(TestWatching, self).setUp()
        self.user = UserFactory()
        self.project = ProjectFactory(creator=self.user)
        # add some log objects
        self.consolidate_auth = Auth(user=self.user)
        self.project.save()
        # A log added 100 days ago
        self.project.add_log(
            'tag_added',
            params={'project': self.project._primary_key},
            auth=self.consolidate_auth,
            log_date=dt.datetime.utcnow() - dt.timedelta(days=100),
            save=True,
        )
        # Set the ObjectId to correspond with the log date
        # A log added now
        self.last_log = self.project.add_log(
            'tag_added',
            params={'project': self.project._primary_key},
            auth=self.consolidate_auth, log_date=dt.datetime.utcnow(),
            save=True,
        )
        # Clear watched list
        self.user.watched = []
        self.user.save()

    def test_watch_adds_to_watched_list(self):
        n_watched_then = len(self.user.watched)
        # A user watches a WatchConfig
        config = WatchConfigFactory(node=self.project)
        self.user.watch(config)
        n_watched_now = len(self.user.watched)
        assert_equal(n_watched_now, n_watched_then + 1)
        assert_true(self.user.is_watching(self.project))

    def test_unwatch_removes_from_watched_list(self):
        # The user has already watched a project
        self._watch_project(self.project)
        config = WatchConfigFactory(node=self.project)
        n_watched_then = len(self.user.watched)
        self.user.unwatch(config)
        n_watched_now = len(self.user.watched)
        assert_equal(n_watched_now, n_watched_then - 1)
        assert_false(self.user.is_watching(self.project))

    @unittest.skip("Won't work because the old log's id doesn't encode the "
                   "correct log date")
    def test_get_recent_log_ids(self):
        self._watch_project(self.project)
        log_ids = list(self.user.get_recent_log_ids())
        assert_equal(self.last_log._id, log_ids[0])
        # This part won't work
        # TODO(sloria): Rethink.
        assert_equal(len(log_ids), 1)

    def test_get_recent_log_ids_since(self):
        self._watch_project(self.project)
        since = dt.datetime.utcnow().replace(tzinfo=utc) - dt.timedelta(days=101)
        log_ids = list(self.user.get_recent_log_ids(since=since))
        assert_equal(len(log_ids), 3)

    def test_get_daily_digest_log_ids(self):
        self._watch_project(self.project)
        day_log_ids = list(self.user.get_daily_digest_log_ids())
        assert_in(self.last_log._id, day_log_ids)

    def _watch_project(self, project):
        watch_config = WatchConfigFactory(node=project)
        self.user.watch(watch_config)
        self.user.save()

    def _unwatch_project(self, project):
        watch_config = WatchConfigFactory(node=project)
        self.user.watch(watch_config)
        self.user.save()

    def test_paginate_helper(self):
        self._watch_project(self.project)
        logs = list(self.user.get_recent_log_ids())
        size = 10
        page = 0
        total = len(logs)
        paginated_logs, pages = paginate(
            self.user.get_recent_log_ids(), total, page, size)
        page_num = math.ceil(total / float(size))
        assert_equal(len(list(paginated_logs)), total)
        assert_equal(page_num, pages)

    def test_paginate_no_negative_page_num(self):
        self._watch_project(self.project)
        logs = list(self.user.get_recent_log_ids())
        size = 10
        page = -1
        total = len(logs)
        with assert_raises(HTTPError):
            paginate(self.user.get_recent_log_ids(), total, page, size)

#.........这里部分代码省略.........
开发者ID:545zhou,项目名称:osf.io,代码行数:103,代码来源:test_watch.py


注:本文中的tests.factories.UserFactory.watch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。