Ejemplo n.º 1
0
    def test_add_submission_error_max_submissions(self) -> None:
        interface.feature_flag_client.set_applications_opening_date(
            datetime.now() - timedelta(minutes=30))
        interface.feature_flag_client.set_applications_closing_date(
            datetime.now() + timedelta(minutes=30))
        a = Application.objects.create(user=User.objects.create(
            email="*****@*****.**"))

        for _ in range(0, 251):
            Submission.objects.create(
                application=a,
                submission_type=SubmissionTypes.coding_test.uname)
            Submission.objects.create(
                application=a, submission_type=SubmissionTypes.slu01.uname)
            Submission.objects.create(
                application=a, submission_type=SubmissionTypes.slu02.uname)
            Submission.objects.create(
                application=a, submission_type=SubmissionTypes.slu03.uname)

        a.coding_test_started_at = datetime.now()
        a.save()

        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.coding_test, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu01, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu02, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu03, Submission())

        self.assertEqual(a.submissions.count(), 251 * 4)
Ejemplo n.º 2
0
    def test_add_submission_error_close_applications(self) -> None:
        interface.feature_flag_client.set_applications_opening_date(
            datetime.now() - timedelta(hours=5))
        interface.feature_flag_client.set_applications_closing_date(
            datetime.now() - timedelta(hours=2))
        a = Application.objects.create(user=User.objects.create(
            email="*****@*****.**"))

        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.coding_test, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu01, Submission())
Ejemplo n.º 3
0
def candidate_submission_upload_view(request: HttpRequest,
                                     submission_type: str) -> HttpResponse:
    submission_type_ = getattr(SubmissionTypes, submission_type)

    file = request.FILES["file"]
    now_str = datetime.now().strftime("%m_%d_%Y__%H_%M_%S")
    upload_key = f"{submission_type_.uname}/{request.user.uuid}/{file.name}@{now_str}"
    interface.storage_client.save(upload_key, file)

    submission_result = interface.grader_client.grade(
        assignment_id=submission_type_.uname,
        user_uuid=request.user.uuid,
        submission_s3_bucket=settings.STORAGE_BUCKET,
        submission_s3_key=upload_key,
    )

    application = Application.objects.get(user=request.user)
    sub = Submission(file_location=upload_key,
                     score=submission_result.score,
                     feedback_location=submission_result.feedback_s3_key)
    Domain.add_submission(application, submission_type_, sub)

    if submission_type == SubmissionTypes.coding_test.uname:
        return HttpResponseRedirect("/candidate/coding-test")
    return HttpResponseRedirect(f"/candidate/slu/{submission_type}")
Ejemplo n.º 4
0
    def test_add_submission_error_already_ended(self) -> None:
        interface.feature_flag_client.set_applications_opening_date(
            datetime.now() - timedelta(minutes=60))
        interface.feature_flag_client.set_applications_closing_date(
            datetime.now() - timedelta(minutes=30))
        a = Application.objects.create(user=User.objects.create(
            email="*****@*****.**"))

        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.coding_test, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu01, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu02, Submission())
        with self.assertRaises(DomainException):
            Domain.add_submission(a, SubmissionTypes.slu03, Submission())

        self.assertEqual(a.submissions.count(), 0)
Ejemplo n.º 5
0
    def test_add_submission(self) -> None:
        interface.feature_flag_client.set_applications_opening_date(
            datetime.now() - timedelta(minutes=30))
        interface.feature_flag_client.set_applications_closing_date(
            datetime.now() + timedelta(minutes=30))
        a = Application.objects.create(user=User.objects.create(
            email="*****@*****.**"))

        a.coding_test_started_at = datetime.now()
        a.save()

        Domain.add_submission(a, SubmissionTypes.coding_test, Submission())
        Domain.add_submission(a, SubmissionTypes.slu01, Submission())
        Domain.add_submission(a, SubmissionTypes.slu02, Submission())
        Domain.add_submission(a, SubmissionTypes.slu03, Submission())
        self.assertEqual(a.submissions.count(), 4)

        interface.feature_flag_client.set_applications_closing_date(
            datetime.now() - timedelta(minutes=30))
        # will work because end-date will be based on start_end + duration, not on the ff.closing_date
        Domain.add_submission(a, SubmissionTypes.coding_test, Submission())
        self.assertEqual(a.submissions.count(), 5)
Ejemplo n.º 6
0
    def handle(self, *args, **options) -> None:
        # admin / staff user
        logger.info("creating admin user: user=admin; pw=admin")
        User.objects.create_admin_user(email="*****@*****.**", password="******")

        logger.info("creating staff user: user=staff; pw=staff")
        User.objects.create_staff_user(email="*****@*****.**", password="******")

        # user with nothing
        new_user("nothing")

        # user with confirmed email
        new_user("with_confirmed_email", with_email_confirmation())

        # user with confirmed email
        new_user("with_accepted_coc", with_accepted_coc())

        # user with profiles
        new_user(
            "profile_student",
            with_profile(
                full_name="User With Student Profile",
                profession="Student",
                gender=ProfileGenders.female,
                ticket_type=ProfileTicketTypes.student,
            ),
        )
        new_user(
            "profile_regular",
            with_profile(
                full_name="User With Regular Profile",
                profession="Worker",
                gender=ProfileGenders.male,
                ticket_type=ProfileTicketTypes.regular,
            ),
        )
        new_user(
            "profile_company",
            with_profile(
                full_name="User With Company Profile",
                profession="Spotify",
                gender=ProfileGenders.other,
                ticket_type=ProfileTicketTypes.company,
            ),
        )

        # users with applications
        new_user("with_application_not_started", with_application())
        new_user("with_submissions_ongoing",
                 with_application(coding_test_started_at=datetime.now()))
        new_user(
            "with_submissions_passed",
            with_application(coding_test_started_at=datetime.now()),
            with_submission(SubmissionTypes.coding_test, 85),
            with_submission(SubmissionTypes.slu01, 91),
            with_submission(SubmissionTypes.slu02, 82),
            with_submission(SubmissionTypes.slu03, 76),
        )
        new_user(
            "with_submissions_failed",
            with_application(coding_test_started_at=datetime.now() -
                             timedelta(hours=4)))

        # users with payments
        # new_user("with_regular_payment", with_profile(ticket_type=ProfileTicketTypes.regular), with_payment())
        # new_user(
        #     "with_regular_payment_with_docs",
        #     with_profile(ticket_type=ProfileTicketTypes.regular),
        #     with_payment(), with_document()
        # )
        # new_user(
        #     "with_student_payment_with_docs",
        #     with_profile(ticket_type=ProfileTicketTypes.student),
        #     with_payment(),
        #     with_document(),
        #     with_document(doc_type="student_id", file_location=ASSET_STUDENT_ID_PNG),
        # )
        # new_user("with_company_payment", with_profile(ticket_type=ProfileTicketTypes.company),
        # with_payment(), with_document())

        # randoms (will be bulk created)
        users: List[User] = []
        # random - users
        logger.info(
            f"creating {_random_n} random users with profiles and applications"
        )
        for i in range(0, _random_n):
            u = User(email=f"random_{i}@adm.com")
            users.append(u)

        User.objects.bulk_create(users)
        users = User.objects.filter(email__in=[u.email for u in users])

        # random - profiles
        profiles: List[Profile] = []
        for prof_u in users:
            gender = random.choice([
                ProfileGenders.female, ProfileGenders.male,
                ProfileGenders.other
            ])
            ticket_type = random.choice([
                ProfileTicketTypes.regular, ProfileTicketTypes.company,
                ProfileTicketTypes.student
            ])
            p = Profile(
                user=prof_u,
                full_name=f"Random User {prof_u.id}",
                profession=f"Random Profession {prof_u.id}",
                gender=gender,
                ticket_type=ticket_type,
            )
            profiles.append(p)
        Profile.objects.bulk_create(profiles)

        # random - applications
        applications: List[Application] = []
        for app_u in users:
            minutes_delta = random.randrange(0, 300, 20)
            a = Application(user=app_u,
                            coding_test_started_at=datetime.now() -
                            timedelta(minutes=minutes_delta))
            applications.append(a)
        Application.objects.bulk_create(applications)
        applications = Application.objects.filter(user__in=users)

        # random - submissions
        submissions: List[Submission] = []
        for sub_a in applications:
            for j in range(0, 15):
                s_type = random.choice([
                    SubmissionTypes.coding_test.uname,
                    SubmissionTypes.slu01.uname,
                    SubmissionTypes.slu02.uname,
                    SubmissionTypes.slu03.uname,
                ])
                score = random.randrange(60, 100, 2)
                s = Submission(application=sub_a,
                               submission_type=s_type,
                               score=score,
                               feedback_location="404")
                submissions.append(s)

        Submission.objects.bulk_create(submissions)

        logger.info(self.summary())