Exemplo n.º 1
0
    def handle(self, *args, **options):
        with open(options['file'], 'rb') as csvfile:
            students = csv.reader(csvfile)
            num = 0

            ceitba_service = Service.objects.get(
                name=config.CEITBA_SERVICE_NAME)

            for row in students:
                try:
                    student = Student.objects.get(student_id=row[0])

                    enrollment = Enrollment(student=student,
                                            service=ceitba_service)
                    enrollment.date_created = datetime.date(2016, 3, 15)

                    enrollment.save()

                except Student.DoesNotExist:
                    self.stdout.write(
                        self.style.ERROR(
                            u'Student with ID = %s, Name = %s does not exist' %
                            (row[0], row[1].decode('utf-8'))))

                num += 1

                if num % 100 == 0:
                    self.stdout.write(
                        self.style.NOTICE('Updated %d students so far' % num))

            self.stdout.write(
                self.style.SUCCESS('Update finished!\n\tUpdated %d students' %
                                   num))
Exemplo n.º 2
0
    def test_auto_add_exam_success(self):
        product = Product(name=config.YMCA_MEDICALEXAM_PRODUCT_NAME, price=10)
        product.save()

        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        service_ymca = Service.objects.get(name=config.YMCA_SERVICE_NAME)

        enrollment = Enrollment(student=student, service=service_ymca)
        enrollment.save(add_ymca_medical_exam=True)

        self.assertIsNotNone(enrollment.pk)

        purchases = Purchase.objects.filter(student=student)

        self.assertEqual(purchases.count(), 1)

        purchase = purchases.get()

        purchaseitems = purchase.purchaseitem_set

        self.assertEqual(purchaseitems.count(), 1)

        purchaseitem = purchaseitems.get()

        self.assertEqual(purchaseitem.product.pk, product.pk)
        self.assertEqual(purchaseitem.quantity, 1)
Exemplo n.º 3
0
    def test_deletion_cascade(self):
        """
        Testea que al eliminar un servicio, todas las suscripciones al mismo sean dadas de baja
        :return:
        """
        ymca_service = Service.objects.get(name=config.YMCA_SERVICE_NAME)

        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        enrollment = Enrollment(service=ymca_service, student=student)
        enrollment.date_created = datetime.date(2016, 1, 1)  # Para evitar same_day deletion
        enrollment.save()

        enrollments = student.enrollment_set.all()

        # Nos aseguramos que existan dos suscripciones, la del YMCA y la del CEITBA
        self.assertEqual(2, enrollments.count())

        report = Report()
        report.save()

        # Borramos el servicio
        ymca_service.delete()

        ymca_enrollment = Enrollment.objects.get(service__name=config.YMCA_SERVICE_NAME)

        self.assertEqual(ymca_enrollment.date_removed, datetime.date.today())
Exemplo n.º 4
0
    def test_auto_deletion_cascade(self):
        """
        Test de que cuando se desuscribe el servicio CEITBA, automaticamente
        se desuscribe del resto de los servicios en cascada
        :return:
        """

        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        student = Student.objects.filter(student_id=TEST_STUDENT_ID).get()
        ymca_service = Service.objects.get(name=config.YMCA_SERVICE_NAME)

        enrollment = Enrollment(service=ymca_service, student=student)
        enrollment.save()

        ceitba_enrollments = Enrollment.objects.filter(
            student=student, service__name=config.CEITBA_SERVICE_NAME)

        self.assertEqual(1, ceitba_enrollments.count())

        ceitba_enrollment = ceitba_enrollments.get()
        ceitba_enrollment.delete()

        enrollments = student.enrollment_set.all()

        self.assertEqual(0, enrollments.count())
Exemplo n.º 5
0
    def test_system(self):
        for i in range(1, random.randint(1, ITERATIONS)):
            student = Student.objects.order_by('?').first()
            service = Service.objects.order_by('?').first()

            enrollment = Enrollment(
                student=student,
                service=service,
                date_created=rand_date(START_RAND_YEAR, END_RAND_YEAR),
                date_removed=rand_date(START_RAND_YEAR, END_RAND_YEAR))
            enrollment.save()

        for _ in range(1, random.randint(1, ITERATIONS)):
            student = Student.objects.order_by('?').first()
            purchase = Purchase(student=student,
                                date_created=rand_date(START_RAND_YEAR,
                                                       END_RAND_YEAR))
            purchase.save()

            for __ in range(1, random.randint(2, 10)):
                product = Product.objects.order_by('?').first()
                quantity = random.randint(2, 10)

                item = PurchaseItem(purchase=purchase,
                                    product=product,
                                    quantity=quantity)
                item.save()
    def test_assigned_locker(self):
        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

        locker_enrollments = Enrollment.objects.filter(service=locker_service)

        self.assertEqual(1, locker_enrollments.count())

        lockersite = locker_service.lockersite

        self.assertEqual(10, lockersite.free_spots())
        self.assertEqual(10, locker_enrollments.get().service.lockersite.count)

        new_assignation = LockerAssignation()
        new_assignation.enrollment = locker_enrollments.get()
        new_assignation.locker_id = 1
        new_assignation.clean()
        new_assignation.save()

        # por @cached_property, tenemos que actualizar lockersite
        lockersite = Service.objects.filter(
            name=LOCKER_SERVICE_NAME).get().lockersite

        self.assertEqual(9, lockersite.free_spots())
        self.assertTrue(lockersite.has_free_spots())
        self.assertEqual(2, lockersite.get_free_locker())
        self.assertEqual(1, lockersite.used_spots())

        new_student = Student(name='Test Student 2',
                              student_id=TEST_STUDENT_ID + 1)
        new_student.save()

        new_enrollment = Enrollment(service=locker_service,
                                    student=new_student)
        new_enrollment.save()

        new_assignation = LockerAssignation()
        new_assignation.enrollment = new_enrollment
        new_assignation.locker_id = lockersite.get_free_locker()
        new_assignation.clean()
        new_assignation.save()

        # por @cached_property, tenemos que actualizar lockersite
        lockersite = Service.objects.filter(
            name=LOCKER_SERVICE_NAME).get().lockersite

        self.assertEqual(8, lockersite.free_spots())
        self.assertTrue(lockersite.has_free_spots())
        self.assertEqual(3, lockersite.get_free_locker())
        self.assertEqual(2, lockersite.used_spots())
Exemplo n.º 7
0
    def test_single_subscription_fail(self):
        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        service_gim = Service.objects.get(name='Gimnasio')

        enrollment = Enrollment(service=service_gim, student=student)
        enrollment.full_clean()
        enrollment.save()

        self.assertIsNotNone(enrollment.pk)

        enrollment2 = Enrollment(service=service_gim, student=student)

        with self.assertRaises(ValidationError):
            enrollment2.full_clean()
Exemplo n.º 8
0
    def test_auto_ceitba_enrollment_cascade(self):
        """
        Test de que cuando se suscribe a un alumno a otro servicio, automaticamente se lo suscribe
        al CEITBA
        :return:
        """

        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        student = Student.objects.filter(student_id=TEST_STUDENT_ID).get()

        # Primero eliminamos la suscripcion
        Enrollment.objects.filter(student__student_id=TEST_STUDENT_ID).delete()

        enrollments = Enrollment.objects.filter(
            student__student_id=TEST_STUDENT_ID)
        self.assertEqual(enrollments.count(), 0)

        ymca_service = Service.objects.get(name=config.YMCA_SERVICE_NAME)

        enrollment = Enrollment(service=ymca_service, student=student)
        enrollment.save()

        # Test for CEITBA enrollment
        ceitba_enrollments = Enrollment.objects.filter(
            student__student_id=TEST_STUDENT_ID,
            service__name=config.CEITBA_SERVICE_NAME)
        self.assertEqual(ceitba_enrollments.count(), 1)

        ceitba_enrollment = ceitba_enrollments.get()

        self.assertEqual(ceitba_enrollment.service.name,
                         config.CEITBA_SERVICE_NAME)
        self.assertEqual(ceitba_enrollment.student.student_id, TEST_STUDENT_ID)

        # Test for YMCA enrollment
        ymca_enrollments = Enrollment.objects.filter(
            student__student_id=TEST_STUDENT_ID,
            service__name=config.YMCA_SERVICE_NAME)
        self.assertEqual(ymca_enrollments.count(), 1)
        ymca_enrollment = ymca_enrollments.get()

        self.assertEqual(ymca_enrollment.service.name,
                         config.YMCA_SERVICE_NAME)
        self.assertEqual(ymca_enrollment.student.student_id, TEST_STUDENT_ID)
Exemplo n.º 9
0
    def test_report_creation(self):
        # FIXME
        pass
        student = Student(name=TEST_STUDENT_NAME, student_id=TEST_STUDENT_ID)
        student.save()
        student = Student.objects.get()
        # Costo suscripcion ceitba por defecto = 100

        enrollment = Enrollment(student=student,
                                service=Service.objects.filter(name=config.YMCA_SERVICE_NAME).get())
        enrollment.save()  # Cuesta 10

        enrollment2 = Enrollment(student=student,
                                 service=Service.objects.filter(name='Gimnasio').get())
        enrollment2.save()  # Cuesta 15

        # Costo de suscripciones hasta aca: 25

        for e in Enrollment.objects.all():
            print(e.service.name + '=' + str(e.service.price))

        purchase1 = Purchase(student=student)
        purchase1.save()

        purchaseitem1 = PurchaseItem(purchase=purchase1, product=Product.objects.filter(name='Cuaderno').get(),
                                     quantity=2)
        purchaseitem1.save()  # Costo: 2* 25=50

        purchaseitem1 = PurchaseItem(purchase=purchase1, product=Product.objects.filter(name='Taza').get(), quantity=3)
        purchaseitem1.save()  # Costo: 3* 40=120

        for item in PurchaseItem.objects.all():
            print(item.product.name + '=' + str(item.product.price) + "*" + str(item.quantity))

        # Costo compra 1 : 170

        report = Report()
        report.save()

        # 100 + 25 + 170 = 295

        self.assertEqual(report.totalin, 295)
        self.assertEqual(report.totalout, 0)
        self.assertEqual(report.students, 1)
        self.assertEqual(report.active_members, 1)
        self.assertEqual(report.subscriptions, 1)
        self.assertEqual(report.unsubscriptions, 0)
Exemplo n.º 10
0
    def create_assignation(cls, member, lockersite, locker_id):
        new_enrollment = Enrollment()
        new_enrollment.student = member
        new_enrollment.service = lockersite.service
        new_enrollment.save()

        new_assignation = LockerAssignation()
        new_assignation.locker_id = locker_id
        new_assignation.enrollment = new_enrollment
        new_assignation.save()

        return new_assignation, new_enrollment
    def setUpTestData(cls):
        for service, price in TEST_SERVICES:
            logger.info("Adding service %s" % service)
            s = Service(name=service, price=price)
            s.save()

        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

        new_lockersite = LockerSite(count=10)
        new_lockersite.service = locker_service

        new_lockersite.save()

        print("Added lockersite %s (%d)" %
              (new_lockersite, new_lockersite.count))

        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        Enrollment(service=locker_service, student=student).save()
Exemplo n.º 12
0
    def test_debt_creation(self):

        student = Student(name=TEST_STUDENT_NAME, student_id=TEST_STUDENT_ID)
        student.save()

        enrollment = Enrollment()
        enrollment.service = Service.objects.get(name=config.YMCA_SERVICE_NAME)
        enrollment.student = student
        enrollment.billable = False
        enrollment.save()

        self.assertIsNotNone(enrollment.pk)

        report = Report()
        report.save()

        debts = Debt.objects.filter(student=student)

        self.assertEqual(debts.count(), 1)

        debt = debts.get()

        self.assertEqual(debt.student.pk, student.pk)

        enrollments = debt.enrollments

        self.assertEqual(enrollments.count(), 1)

        debt_enrollment = enrollments.get()

        self.assertEqual(debt_enrollment.pk, enrollment.pk)

        self.assertEqual(debt.amount, enrollment.service.price)

        self.assertFalse(debt.is_paid)

        debt.date_paid = date.today()
        debt.save()

        self.assertTrue(debt.is_paid)
Exemplo n.º 13
0
    def test_single_subscription_success(self):
        student = Student(name='Test Student', student_id=TEST_STUDENT_ID)
        student.save()

        service_gim = Service.objects.get(name='Gimnasio')
        service_gim.single_subscription = False
        service_gim.save()

        enrollment = Enrollment(service=service_gim, student=student)
        enrollment.full_clean()
        enrollment.save()

        self.assertIsNotNone(enrollment.pk)

        enrollment2 = Enrollment(service=service_gim, student=student)
        enrollment2.full_clean()
        enrollment2.save()

        self.assertIsNotNone(enrollment2.pk)