Example #1
0
    def test_update_existing_data(self):

        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
            self.curriculum,
            self.course,
            self.course_run,
            self.curriculum_course_membership,
        ])
        self._mock_fixture_response(fixture)
        self._call_load_program_fixture([str(self.program.uuid)])

        self.program.title = 'program-title-modified'
        self.course.title = 'course-title-modified'
        new_course = CourseFactory(partner=self.partner,
                                   authoring_organizations=[self.organization])
        new_course_run = CourseRunFactory(course=new_course)
        new_course_membership = CurriculumCourseMembershipFactory(
            course=new_course, curriculum=self.curriculum)

        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
            self.curriculum,
            self.course,
            self.course_run,
            self.curriculum_course_membership,
            new_course_membership,
            new_course,
            new_course_run,
        ])
        responses.reset()
        self._mock_oauth_request()
        self._mock_fixture_response(fixture)
        self.reset_db_state()
        self._call_load_program_fixture([str(self.program.uuid)])

        stored_program = Program.objects.get(uuid=self.program.uuid)
        self.assertEqual(stored_program.title, 'program-title-modified')

        stored_program_courses = stored_program.curricula.first(
        ).course_curriculum.all()
        modified_existing_course = stored_program_courses.get(
            uuid=self.course.uuid)
        stored_new_course = stored_program_courses.get(uuid=new_course.uuid)

        self.assertEqual(len(stored_program_courses), 2)
        self.assertEqual(modified_existing_course.title,
                         'course-title-modified')
        self.assertEqual(stored_new_course.key, new_course.key)
Example #2
0
    def test_update_existing_program_type(self):

        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        # set DB to have a conflicting program type on load
        seat_type = SeatTypeFactory(
            name='Something',
            slug='something',
        )
        existing_program_type = ProgramTypeFactory(
            name='Masters', slug='masters', applicable_seat_types=[seat_type])

        self._call_load_program_fixture([str(self.program.uuid)])

        stored_program = Program.objects.get(uuid=self.program.uuid)

        # assert existing DB value is used
        stored_program_type = stored_program.type
        self.assertEqual(stored_program_type, existing_program_type)

        # assert existing DB value is updated to match fixture
        stored_seat_types = list(
            stored_program_type.applicable_seat_types.all())
        self.assertEqual(len(stored_seat_types), 1)
        self.assertEqual(stored_seat_types[0].name,
                         self.seat_type_verified.name)
Example #3
0
    def test_existing_seat_types(self):

        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        # create existing verified seat with different pk than fixture and
        # a second seat type with the same pk but different values
        new_pk = self.seat_type_verified.id + 1
        SeatType.objects.create(id=new_pk, name='Verified', slug='verified')
        SeatType.objects.create(id=self.seat_type_verified.id,
                                name='Test',
                                slug='test')
        self._call_load_program_fixture([str(self.program.uuid)])

        stored_program = Program.objects.get(uuid=self.program.uuid)
        stored_seat_type = stored_program.type.applicable_seat_types.first()

        self.assertEqual(stored_seat_type.id, new_pk)
        self.assertEqual(stored_seat_type.name, self.seat_type_verified.name)
Example #4
0
 def get(self, request):
     uuids_string = self.request.GET.get(self.QUERY_PARAM)
     if not uuids_string:
         return HttpResponse(self.HELP_STRING, status=404)
     uuids_split = uuids_string.split(',')
     try:
         uuids = {UUID(uuid_str) for uuid_str in uuids_split}
     except ValueError:
         return HttpResponse(self.HELP_STRING, status=404)
     if len(uuids) > self.MAX_REQUESTED_PROGRAMS:
         return HttpResponse(
             'Too many programs requested, only {} allowed.'.format(
                 self.MAX_REQUESTED_PROGRAMS),
             status=422,
         )
     programs = use_read_replica_if_available(
         Program.objects.filter(uuid__in=list(uuids)))
     loaded_uuids = {program.uuid for program in programs}
     bad_uuids = uuids - loaded_uuids
     if bad_uuids:
         return HttpResponse(
             "Could not load programs from UUIDs: [{}]".format(",".join(
                 str(uuid) for uuid in bad_uuids)),
             status=404,
         )
     objects = load_program_fixture(programs)
     json_text = json.Serializer().serialize(objects)
     return HttpResponse(json_text, content_type='text/json')
Example #5
0
    def test_remapping_courserun_programtype(self):
        """
        Tests whether the remapping of program types works for the course run field that points to them
        """
        self.course_run.expected_program_type = self.program_type_masters
        self.course_run.save()
        fixture = json_serializer.Serializer().serialize([
            self.program_type_masters,
            self.program_type_mm,
            self.organization,
            self.seat_type_verified,
            self.program,
            self.program_mm,
            self.curriculum_program_membership,
            self.curriculum_course_membership,
            self.curriculum,
            self.course,
            self.course_mm,
            self.course_run,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        existing_program_type = self._set_up_masters_program_type()

        self._call_load_program_fixture([str(self.program.uuid)])

        stored_courserun = CourseRun.objects.get(key=self.course_run.key)
        stored_program_type = stored_courserun.expected_program_type

        self.assertEqual(existing_program_type, stored_program_type)
Example #6
0
    def test_update_existing_program_type(self):

        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        existing_program_type = self._set_up_masters_program_type()

        self._call_load_program_fixture([str(self.program.uuid)])

        stored_program = Program.objects.get(uuid=self.program.uuid)

        # assert existing DB value is used
        stored_program_type = stored_program.type
        self.assertEqual(stored_program_type, existing_program_type)

        # assert existing DB value is updated to match fixture
        stored_seat_types = list(
            stored_program_type.applicable_seat_types.all())
        self.assertEqual(len(stored_seat_types), 1)
        self.assertEqual(stored_seat_types[0].name,
                         self.seat_type_verified.name)
    def test_load_programs(self):

        fixture = json_serializer.Serializer().serialize([
            self.program_type_masters,
            self.program_type_masters_translation,
            self.program_type_mm,
            self.program_type_mm_translation,
            self.organization,
            self.seat_type_verified,
            self.program,
            self.program_2,
            self.program_mm,
            self.curriculum_program_membership,
            self.curriculum_course_membership,
            self.curriculum,
            self.course,
            self.course_mm,
            self.course_run,
            self.course_run_mm,
        ])
        self._mock_fixture_response(fixture)

        requested_programs = [
            str(self.program.uuid),
            str(self.program_2.uuid),
        ]
        self.reset_db_state()
        self._call_load_program_fixture(requested_programs)

        # walk through program structure to validate correct
        # objects have been created
        stored_program = Program.objects.get(uuid=self.program.uuid)
        stored_program_2 = Program.objects.get(uuid=self.program_2.uuid)
        assert stored_program.title == self.program.title
        assert stored_program_2.title == self.program_2.title

        stored_organization = stored_program.authoring_organizations.first()
        assert stored_organization.name == self.organization.name

        # partner should use existing edx value
        assert stored_program.partner == self.default_partner
        assert stored_organization.partner == self.default_partner

        stored_program_type = stored_program.type
        assert stored_program_type.name_t == self.program_type_masters.name

        stored_seat_type = stored_program_type.applicable_seat_types.first()
        assert stored_seat_type.name == self.seat_type_verified.name

        stored_curriculum = stored_program.curricula.first()
        assert stored_curriculum.uuid == self.curriculum.uuid

        stored_course = stored_curriculum.course_curriculum.first()
        assert stored_course.key == self.course.key

        stored_mm = stored_curriculum.program_curriculum.first()
        assert stored_mm.uuid == self.program_mm.uuid

        stored_course_run = stored_course.course_runs.first()
        assert stored_course_run.key == self.course_run.key
    def get(self, request, cat):
        # data = self.request.data
        token = request.META.get('HTTP_AUTHORIZATION')
        print(token)
        if not token:
            return HttpResponse({"Unauthorized": "Unauthorized"}, status="401")
        elif token:
            try:
                tole = jwt.decode(token, "SECRET_KEY")
                print(tole['email'], 'hijuhuyu')
                email = tole['email']
                if Buyer.objects.get(email=email):

                    print(cat)
                    if cat == 'food':
                        category = 100
                    if cat == 'clothes':
                        category = 200
                    if cat == 'babyproducts':
                        print(cat)
                        category = 400
                    if cat == 'accessories':
                        category = 300
                    obj = Item.objects.filter(category=category)
                    json_serializer = json.Serializer()
                    json_serialized = json_serializer.serialize(obj)
                    data = JSON.loads(json_serialized)
                    # print(json_serialized)
                    return Response(data)
            except jwt.DecodeError:
                return HttpResponse({"Unauthorized": "Unauthorized"},
                                    status="401")
Example #9
0
def export_int_conns(request):
    scheme = request.GET.get('scheme', 'xml')
    schemes = ['xml', 'json']

    if scheme not in schemes:
        scheme = 'xml'

    connections = models.InternetConnection.objects.all()

    ser = xml_serializer.Serializer()
    if scheme == 'json':
        ser = json_serializer.Serializer()

    data = ser.serialize(connections)
    return HttpResponse(data, content_type='application/' + scheme)
Example #10
0
    def test_ignore_program_external_key(self):
        fixture = json_serializer.Serializer().serialize([
            self.organization,
            self.seat_type_verified,
            self.program_type_masters,
            self.program,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        self._call_load_program_fixture([
            '{uuid}:{external_key}'.format(uuid=str(self.program.uuid),
                                           external_key='CS-104-FALL-2019')
        ])

        Program.objects.get(uuid=self.program.uuid)
Example #11
0
def export_library_users(request):
    if not _is_auth(request):
        return HttpResponse('Need auth', status=401)
    scheme = request.GET.get('scheme', 'xml')
    schemes = ['xml', 'json']
    if scheme not in schemes:
        scheme = 'xml'

    objects = models.UserLibrary.objects.all()

    ser = xml_serializer.Serializer()
    if scheme == 'json':
        ser = json_serializer.Serializer()

    data = ser.serialize(objects)
    return HttpResponse(data, content_type='application/' + scheme)
Example #12
0
    def test_fail_on_constraint_error(self):

        # duplicate programs should successfully save but fail final constraint check
        fixture = json_serializer.Serializer().serialize([
            self.program,
            self.program,
            self.seat_type_verified,
            self.program_type_masters,
        ])
        self._mock_fixture_response(fixture)
        self.reset_db_state()

        with pytest.raises(IntegrityError) as err:
            self._call_load_program_fixture([str(self.program.uuid)])
        expected_msg = (
            r'Checking database constraints failed trying to load fixtures. Unable to save program\(s\):'
        ).format(pk=self.organization.id)
        assert re.match(expected_msg, str(err.value))
Example #13
0
    def test_fail_on_save_error(self):

        fixture = json_serializer.Serializer().serialize([
            self.organization,
        ])

        #  Should not be able to save an organization without uuid
        fixture_json = json.loads(fixture)
        fixture_json[0]['fields']['uuid'] = None
        fixture = json.dumps(fixture_json)

        self._mock_fixture_response(fixture)
        self.reset_db_state()

        with pytest.raises(IntegrityError) as err:
            self._call_load_program_fixture([str(self.program.uuid)])
        expected_msg = fr'Failed to save course_metadata.Organization\(pk={self.organization.id}\):'
        assert re.match(expected_msg, str(err.value))
Example #14
0
def my_page(request):
    me = request.user
    friends = me.friend_set.all().filter(accepted=True)
    # me = get_object_or_404(User, id=pk) #me = 접속한 user
    # friends = me.self_set.all() #me의 friend들
    friends_enrollment = {}
    motivation_from_friends = me.motivation_friend_set.all()

    for friend in friends:
        friends_enrollment[friend.me.id] = EnrollmentDate.objects.all().filter(enrollment__player=friend.me, date_result=True).count()

    today = date.today() #오늘 날짜에 맞는 챌린지만 가져오게 하기
    enrollmentdates = EnrollmentDate.objects.all().filter(
            enrollment__player=me, date__year=today.year, date__month=today.month, date__day=today.day)
    challenge_success = EnrollmentDate.objects.all().filter(
            enrollment__player=me, date_result=True)#.order_by('-pk')
    
    challenge_success_title = {}
    for ch in challenge_success:
        challenge_success_title[ch.enrollment.pk] = ch.enrollment.challenge.title
    
    challenge_success_serializer = json.Serializer()
    challenge_success_serialized = challenge_success_serializer.serialize(
        challenge_success)
    ctx = {        
        'me': me,
        'friends': friends,
        'enrollmentdates': enrollmentdates,
        'friends_enrollment': friends_enrollment,
        'motivation_from_friends': motivation_from_friends,
        'challenge_success' : JSON.dumps(challenge_success_serialized),
        'challenge_success_title' : JSON.dumps(challenge_success_title),
    }

    print(ctx)
    return render(request, "login/mypage.html", ctx)