Пример #1
0
    def test_empty_lockersute(self):
        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

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

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

        new_lockersite.save()

        self.assertEqual(new_lockersite.get_free_locker(), 1)

        new_assignation, new_enrollment = LockerAssignation.create_assignation(
            student, new_lockersite, 2)

        self.assertEqual(new_lockersite.get_free_locker(), 1)

        new_assignation, new_enrollment = LockerAssignation.create_assignation(
            student, new_lockersite, 1)

        self.assertEqual(new_lockersite.get_free_locker(), 3)

        new_assignation, new_enrollment = LockerAssignation.create_assignation(
            student, new_lockersite, 3)

        self.assertEqual(new_lockersite.get_free_locker(), None)
        self.assertEqual(new_lockersite.free_spots(), 0)
Пример #2
0
    def setUpTestData(cls):

        logger.info('Populating database.')
        with open('./names.txt') as f:
            names = f.readlines()

        if names is None:
            raise Exception("Couldn't find names")

        random.seed()

        for service, price in TEST_SERVICES:
            logger.info("Adding service %s" % service)
            s = Service(name=service, price=price)
            s.save()

        for name, i in zip(names, range(0, len(names))):
            student = Student(name=name,
                              date_created=rand_date(START_RAND_YEAR,
                                                     END_RAND_YEAR))
            student.student_id = i
            student.save()

            # print "Added student %s" % student.name

        for product in PRODUCTS:
            p = Product(name=product, price=random.randint(1, 300))
            p.save()
Пример #3
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())
Пример #4
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())
Пример #5
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)
    def handle(self, *args, **options):
        with open(options['file'], 'r') as csvfile:
            students = csv.reader(csvfile, delimiter=',')
            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.save()

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

                    student = Student(name=row[1])
                    student.student_id = row[0]
                    student.save(add_ceitba_enrollment=True)

                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))
Пример #7
0
    def test_member_valid_email(self):
        student = Student()
        student.name = STUDENT_NAME
        student.student_id = STUDENT_ID
        student.email = STUDENT_VALID_EMAIL

        student.full_clean()
        student.save()

        self.assertIsNotNone(student.pk)
        self.assertTrue(student.is_active())
    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())
Пример #9
0
    def test_add_queueitem_success(self):
        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

        new_lockersite = LockerSite(count=100)
        new_lockersite.service = locker_service
        new_lockersite.save()

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

        queueitem = LockerQueue(locker_site=new_lockersite, member=student)
        queueitem.full_clean()
        queueitem.save()

        self.assertIsNotNone(queueitem.pk)
Пример #10
0
    def test_member_remove(self):
        student = Student()
        student.name = STUDENT_NAME
        student.student_id = STUDENT_ID
        student.email = STUDENT_VALID_EMAIL

        student.full_clean()
        student.save()

        self.assertIsNotNone(student.pk)
        self.assertIsNone(student.date_removed)

        student.delete()

        self.assertIsNotNone(student.date_removed)
Пример #11
0
    def test_add_queueitem_has_locker(self):
        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

        new_lockersite = LockerSite(count=100)
        new_lockersite.service = locker_service
        new_lockersite.save()

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

        new_assignation, new_enrollment = LockerAssignation.create_assignation(
            student, new_lockersite, 2)

        queueitem = LockerQueue(locker_site=new_lockersite, member=student)
        with self.assertRaises(ValidationError):
            queueitem.full_clean()
Пример #12
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()
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
0
    def test_same_day_deletion(self):
        """
        Test de que al crear y eliminar una suscripcion en el mismo dia, esta de elimina de forma definitiva
        :return:
        """

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

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

        enrollment = Enrollment.objects.filter(
            student__student_id=student.student_id).get()
        enrollment.delete()

        enrollments = Enrollment.objects.filter(
            student__student_id=student.student_id)

        self.assertEqual(enrollments.count(), 0)
Пример #17
0
    def test_auto_ceitba_enrollment(self):
        """
        Test de que cuando se crea un alumno, 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()

        enrollments = Enrollment.objects.filter(
            student__student_id=student.student_id)
        enrollment = enrollments.get()

        self.assertEqual(enrollments.count(), 1)
        self.assertEqual(enrollment.student.student_id, student.student_id)
        self.assertEqual(enrollment.service.name, config.CEITBA_SERVICE_NAME)
        self.assertTrue(enrollment.is_active())
    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()
Пример #19
0
    def handle(self, *args, **options):
        with open(options['file'], 'r') as csvfile:
            students = csv.reader(csvfile, delimiter=',')
            num = 0
            for row in students:

                student_exist = Student.objects.filter(student_id=row[0]).exists()

                if student_exist:
                    self.stdout.write(self.style.WARNING('Student [%s] %s already exists' % (row[0], row[1])))
                    continue

                student = Student(name=row[1])
                student.student_id = row[0]
                student.save(add_ceitba_enrollment=False)
                num += 1
                if num % 100 == 0:
                    self.stdout.write(self.style.NOTICE('Imported %d students so far' % num))

            self.stdout.write(self.style.SUCCESS('Import finished!\n\tImported %d students' % num))
Пример #20
0
    def test_add_queueitem_in_hold(self):
        locker_service = Service.objects.filter(name=LOCKER_SERVICE_NAME).get()

        new_lockersite = LockerSite(count=100)
        new_lockersite.service = locker_service
        new_lockersite.save()

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

        lockerhold = LockerHold(locker_site=new_lockersite,
                                member=student,
                                locker_id=1)
        lockerhold.full_clean()
        lockerhold.save()

        self.assertIsNotNone(lockerhold.pk)

        queueitem = LockerQueue(locker_site=new_lockersite, member=student)
        with self.assertRaises(ValidationError):
            queueitem.full_clean()
Пример #21
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)
Пример #22
0
    def handle(self, *args, **options):
        with open(options['file'], 'r') as csvfile:
            students = csv.reader(csvfile, delimiter=',')
            num = 0

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

                if not student.exists():
                    new_student = Student(name=row[1])
                    new_student.student_id = row[0]
                    new_student.dni = row[2]
                    new_student.save(add_ceitba_enrollment=True)

                num += 1

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

            self.stdout.write(
                self.style.SUCCESS('Update finished!\n\tUpdated %d students' %
                                   num))