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


Python utils.now_in_utc函数代码示例

本文整理汇总了Python中micromasters.utils.now_in_utc函数的典型用法代码示例。如果您正苦于以下问题:Python now_in_utc函数的具体用法?Python now_in_utc怎么用?Python now_in_utc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_count_courses_mixed_fa

    def test_count_courses_mixed_fa(self):
        """
        Test count_courses_passed with mixed course-exam configuration
        """
        mmtrack = MMTrack(
            user=self.user,
            program=self.program_financial_aid,
            edx_user_data=self.cached_edx_user_data
        )
        # this is course with exam run and the user has CombinedFinalGrade for it
        course_with_exam_1 = CourseFactory.create(program=self.program_financial_aid)
        ExamRunFactory.create(course=course_with_exam_1, date_grades_available=now_in_utc()-timedelta(weeks=1))
        CombinedFinalGrade.objects.create(user=self.user, course=course_with_exam_1, grade=0.7)
        # create course with exam run the user did not pass
        ExamRunFactory.create(
            course__program=self.program_financial_aid,
            date_grades_available=now_in_utc() - timedelta(weeks=1)
        )
        # another course with no exam
        FinalGradeFactory.create(
            user=self.user,
            course_run=self.crun_fa,
            passed=True
        )

        assert mmtrack.count_courses_passed() == 2
开发者ID:mitodl,项目名称:micromasters,代码行数:26,代码来源:utils_test.py

示例2: setUpTestData

    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.run_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()-timedelta(days=1),
            course__program__financial_aid_availability=True,
        )
        cls.run_fa_with_cert = CourseRunFactory.create(
            freeze_grade_date=None,
            course__program=cls.run_fa.course.program,
        )

        cls.run_no_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()+timedelta(days=1),
            course__program__financial_aid_availability=False,
        )
        cls.run_no_fa_with_cert = CourseRunFactory.create(
            course__program=cls.run_no_fa.course.program,
        )

        all_course_runs = (cls.run_fa, cls.run_fa_with_cert, cls.run_no_fa, cls.run_no_fa_with_cert, )

        for run in all_course_runs:
            if run.course.program.financial_aid_availability:
                FinancialAidFactory.create(
                    user=cls.user,
                    tier_program=TierProgramFactory.create(
                        program=run.course.program, income_threshold=0, current=True
                    ),
                    status=FinancialAidStatus.RESET,
                )

        cls.enrollments = {
            course_run.edx_course_key: CachedEnrollmentFactory.create(
                user=cls.user, course_run=course_run) for course_run in all_course_runs
        }

        cls.current_grades = {
            course_run.edx_course_key: CachedCurrentGradeFactory.create(
                user=cls.user, course_run=course_run) for course_run in all_course_runs
        }

        cls.certificates = {
            course_run.edx_course_key: CachedCertificateFactory.create(
                user=cls.user, course_run=course_run) for course_run in (cls.run_fa_with_cert, cls.run_no_fa_with_cert)
        }

        cls.user_edx_data = CachedEdxUserData(cls.user)
开发者ID:mitodl,项目名称:micromasters,代码行数:48,代码来源:api_test.py

示例3: test_props

 def test_props(self, program_data):
     """
     Fixture that provides test properties for FinancialAidDetailView test cases
     """
     user = create_enrolled_profile(program_data.program).user
     pending_fa = FinancialAidFactory.create(
         user=user,
         tier_program=program_data.tier_programs["25k"],
         status=FinancialAidStatus.PENDING_DOCS
     )
     docs_sent_url = reverse(
         "financial_aid",
         kwargs={"financial_aid_id": pending_fa.id}
     )
     docs_sent_date = now_in_utc().date()
     docs_sent_request_params = dict(
         content_type="application/json",
         data=json.dumps({
             "date_documents_sent": docs_sent_date.strftime("%Y-%m-%d")
         })
     )
     return SimpleNamespace(
         user=user,
         pending_fa=pending_fa,
         docs_sent_url=docs_sent_url,
         docs_sent_request_params=docs_sent_request_params,
         docs_sent_date=docs_sent_date,
     )
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:views_pytest_test.py

示例4: calculate_users_to_refresh_in_bulk

def calculate_users_to_refresh_in_bulk():
    """
    Calculate the set of user ids which would be updated when running a bulk update. This uses a 6 hour delta
    because this is a bulk operation. For individual updates see CachedEdxDataApi.is_cache_fresh.

    Returns:
        list of int: A list of user ids which need to be updated
    """
    refresh_time_limit = now_in_utc() - datetime.timedelta(hours=6)

    all_users = User.objects.filter(is_active=True, profile__fake_user=False).exclude(social_auth=None)

    con = get_redis_connection("redis")
    user_ids_invalid_credentials = con.smembers(CACHE_KEY_FAILED_USERS_NOT_TO_UPDATE)

    # If one of these fields is null in the database the gte expression will be false, so we will refresh those users
    users_not_expired = all_users.filter(
        usercacherefreshtime__enrollment__gte=refresh_time_limit,
        usercacherefreshtime__certificate__gte=refresh_time_limit,
        usercacherefreshtime__current_grade__gte=refresh_time_limit
    )

    return list(
        all_users
        .exclude(id__in=users_not_expired.values_list("id", flat=True))
        .exclude(id__in=user_ids_invalid_credentials)
        .values_list("id", flat=True)
    )
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:api.py

示例5: get

    def get(self, request, *args, **kargs):  # pylint: disable=unused-argument, no-self-use
        """
        Request for exam SSO parameters
        """
        profile = request.user.profile
        student_id = profile.student_id

        if not ExamProfile.objects.filter(
                profile=profile,
                status=ExamProfile.PROFILE_SUCCESS,
        ).exists():
            # UI should in theory not send a user here in this state,
            # but it's not impossible so let's handle it politely
            return Response(data={
                'error': 'You are not ready to schedule an exam at this time',
            }, status=status.HTTP_403_FORBIDDEN)

        timestamp = int(now_in_utc().timestamp())
        session_timeout = request.session.get_expiry_age()

        try:
            digest = sso_digest(student_id, timestamp, session_timeout)
        except ImproperlyConfigured:
            return Response(status=500)

        return Response(data={
            'sso_digest': digest,
            'timestamp': timestamp,
            'session_timeout': session_timeout,
            'sso_redirect_url': request.build_absolute_uri('/'),
        })
开发者ID:mitodl,项目名称:micromasters,代码行数:31,代码来源:views.py

示例6: create_user_for_login

def create_user_for_login(is_staff=True, username=None):
    """Create a test user that can log into the app"""
    later = now_in_utc() + timedelta(weeks=5000)
    with mute_signals(post_save):
        user = SocialProfileFactory.create(
            validated=True,
            user__is_staff=is_staff,
            image=None,  # make these None so the default image is used
            image_small=None,
            image_medium=None,
            **({'user__username': username} if username is not None else {}),
            user__social_auth__extra_data={
                'access_token': 'fake',
                'refresh_token': 'fake',
                'updated_at': later.timestamp(),
                'expires_in': 3600,
            }
        ).user

    UserCacheRefreshTime.objects.create(
        user=user,
        enrollment=later,
        certificate=later,
        current_grade=later,
    )
    user.set_password(DEFAULT_PASSWORD)
    user.save()
    return user
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:data_util.py

示例7: test_is_cache_fresh

 def test_is_cache_fresh(self):
     """Test for is_cache_fresh"""
     with self.assertRaises(ValueError):
         CachedEdxDataApi.is_cache_fresh(self.user, 'footype')
     # if there is no entry in the table, the cache is not fresh
     assert UserCacheRefreshTime.objects.filter(user=self.user).exists() is False
     for cache_type in CachedEdxDataApi.SUPPORTED_CACHES:
         assert CachedEdxDataApi.is_cache_fresh(self.user, cache_type) is False
     now = now_in_utc()
     user_cache = UserCacheRefreshTimeFactory.create(
         user=self.user,
         enrollment=now,
         certificate=now,
         current_grade=now,
     )
     for cache_type in CachedEdxDataApi.SUPPORTED_CACHES:
         assert CachedEdxDataApi.is_cache_fresh(self.user, cache_type) is True
     # moving back the timestamp of one day, makes the cache not fresh again
     yesterday = now - timedelta(days=1)
     user_cache.enrollment = yesterday
     user_cache.certificate = yesterday
     user_cache.current_grade = yesterday
     user_cache.save()
     for cache_type in CachedEdxDataApi.SUPPORTED_CACHES:
         assert CachedEdxDataApi.is_cache_fresh(self.user, cache_type) is False
开发者ID:mitodl,项目名称:micromasters,代码行数:25,代码来源:api_edx_cache_test.py

示例8: test_sso_get_with_exam_profile_success

    def test_sso_get_with_exam_profile_success(self):
        """
        Test issuing a GET request when user has an ExamProfile in PROFILE_SUCCESS status
        """
        ExamProfile.objects.create(
            profile=self.user.profile,
            status=ExamProfile.PROFILE_SUCCESS,
        )

        with patch('exams.views.sso_digest', return_value='test value'):
            response = self.client.get(reverse("pearson_sso_api"))
            result = response.json()
            assert response.status_code == status.HTTP_200_OK

            timestamp = result['timestamp']
            assert isinstance(timestamp, int)

            now = int(now_in_utc().timestamp())
            assert now - timestamp < 5

            assert result['sso_digest'] == 'test value'

            # best we can assert is that this is an integer
            assert isinstance(result['session_timeout'], int)

            assert result['sso_redirect_url'] == 'http://testserver/'
开发者ID:mitodl,项目名称:micromasters,代码行数:26,代码来源:views_test.py

示例9: from_weeks

def from_weeks(weeks, now=None):
    """Helper function to get a date adjusted by a number of weeks"""
    if weeks is None:
        return None
    if now is None:
        now = now_in_utc()
    return now + timedelta(weeks=weeks)
开发者ID:mitodl,项目名称:micromasters,代码行数:7,代码来源:models_test.py

示例10: save

    def save(self, **kwargs):
        """
        Override save method
        """
        try:
            income_usd = determine_income_usd(
                self.validated_data["original_income"],
                self.validated_data["original_currency"]
            )
        except NotSupportedException:
            raise ValidationError("Currency not supported")
        user = self.context["request"].user
        tier_program = determine_tier_program(self.validated_data["program"], income_usd)

        financial_aid = FinancialAid.objects.create(
            original_income=self.validated_data["original_income"],
            original_currency=self.validated_data["original_currency"],
            tier_program=tier_program,
            user=user,
            income_usd=income_usd,
            country_of_income=user.profile.country,
            date_exchange_rate=now_in_utc(),
            country_of_residence=user.profile.country,
        )

        if determine_auto_approval(financial_aid, tier_program) is True:
            financial_aid.status = FinancialAidStatus.AUTO_APPROVED
        else:
            financial_aid.status = FinancialAidStatus.PENDING_DOCS
        financial_aid.save_and_log(user)

        return financial_aid
开发者ID:mitodl,项目名称:micromasters,代码行数:32,代码来源:serializers.py

示例11: test_no_frozen_runs

 def test_no_frozen_runs(self):
     """
     The course has run with no grading status
     """
     now = now_in_utc()
     self.create_run(freeze_grade_date=now - timedelta(weeks=1))
     assert self.course.has_frozen_runs() is False
开发者ID:mitodl,项目名称:micromasters,代码行数:7,代码来源:models_test.py

示例12: batch_update_user_data

def batch_update_user_data():
    """
    Create sub tasks to update user data like enrollments,
    certificates and grades from edX platform.
    """
    expiration = now_in_utc() + timedelta(hours=5)
    lock = Lock(LOCK_ID, expiration)
    if not lock.acquire():
        # Lock should have expired by now
        log.error("Unable to acquire lock for batch_update_user_data")
        return

    users_to_refresh = calculate_users_to_refresh_in_bulk()

    jobs = release_batch_update_user_data_lock.s(token=lock.token.decode())
    try:
        if len(users_to_refresh) > 0:
            user_id_chunks = chunks(users_to_refresh)

            job = group(
                batch_update_user_data_subtasks.s(user_id_chunk, expiration.timestamp())
                for user_id_chunk in user_id_chunks
            )
            jobs = job | jobs
    finally:
        jobs.delay()
开发者ID:mitodl,项目名称:micromasters,代码行数:26,代码来源:tasks.py

示例13: test_get_pearson_exam_status

    def test_get_pearson_exam_status(self, profile_status, expected_status, make_exam_run,
                                     make_profile, make_auth, log_error_called, log_mock):
        """
        test get_pearson_exam_status
        """
        now = now_in_utc()
        exam_run = None
        if make_exam_run:
            exam_run = ExamRunFactory.create(
                course=self.course,
                date_first_eligible=now - timedelta(weeks=1),
                date_last_eligible=now + timedelta(weeks=1),
            )

        if make_profile:
            ExamProfileFactory.create(
                profile=self.user.profile,
                status=profile_status,
            )

        if make_auth:
            ExamAuthorizationFactory.create(
                user=self.user,
                status=ExamAuthorization.STATUS_SUCCESS,
                exam_run=exam_run,
            )

        mmtrack = MMTrack(
            user=self.user,
            program=self.program,
            edx_user_data=self.cached_edx_user_data
        )

        assert mmtrack.get_pearson_exam_status() == expected_status
        assert log_mock.error.called is log_error_called
开发者ID:mitodl,项目名称:micromasters,代码行数:35,代码来源:utils_test.py

示例14: handle_cdd

    def handle_cdd(self, sftp_conn, remote_path, ratio):
        """Handle a CDD file"""
        now = now_in_utc()
        result_file = io.StringIO()
        writer = csv.DictWriter(result_file, [
            'ClientCandidateID',
            'Status',
            'Date',
            'Message',
        ], delimiter='\t')
        writer.writeheader()
        with sftp_conn.open(remote_path, mode='r') as cdd_file:
            for row in csv.DictReader(cdd_file, delimiter='\t'):
                cid = row['ClientCandidateID']
                error = random.random() > ratio
                status = 'Error' if error else 'Accepted'
                self.stdout.write('Marking profile {cid} as {status}'.format(
                    cid=cid,
                    status=status,
                ))
                writer.writerow({
                    'ClientCandidateID': cid,
                    'Status': 'Error' if error else 'Accepted',
                    'Date': now.strftime(PEARSON_DEFAULT_DATETIME_FORMAT),
                    'Message': 'Invalid Address' if error else '',
                })

        self.write_zip(
            sftp_conn,
            result_file.getvalue(),
            now.strftime('{}-%Y-%m-%d.dat'.format(PEARSON_FILE_TYPES.VCDC)),
            now
        )
开发者ID:mitodl,项目名称:micromasters,代码行数:33,代码来源:simulate_sftp_responses.py

示例15: can_freeze_grades

 def can_freeze_grades(self):
     """
     Checks if the final grades can be frozen.
     """
     if self.freeze_grade_date is None:
         raise ImproperlyConfigured('Missing freeze_grade_date')
     return now_in_utc() > self.freeze_grade_date
开发者ID:mitodl,项目名称:micromasters,代码行数:7,代码来源:models.py


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