Beispiel #1
0
    def testBumpAll(self):
        """Test bump all"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        #bump all attended subjects
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            bumpAll({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()
        self.assertEquals(esdu.bumped, True)
        self.assertEquals(esdu2.bumped, False)

        #junk data
        r = json.loads(
            bumpAll({}, esd1.id + 50, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])
Beispiel #2
0
    def testFillDefaultShowUpFee(self):
        """Test fill default show up fees"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        #one confirmed, one no show
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            fillDefaultShowUpFee({}, esd1.id,
                                 self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(esdu.show_up_fee,
                          esd1.experiment_session.experiment.showUpFee)
        self.assertEquals(esdu2.show_up_fee, 0)

        #bumped
        r = json.loads(
            bumpSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            fillDefaultShowUpFee({}, esd1.id,
                                 self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()
        self.assertEquals(esdu2.show_up_fee,
                          esd1.experiment_session.experiment.showUpFee)

        #session not found
        r = json.loads(
            fillDefaultShowUpFee({}, esd1.id + 50,
                                 self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])
Beispiel #3
0
    def testFillEarningsWithFixedAmount(self):
        """Test fill earning with fixed amount"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        #one confirmed, one no show
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            fillEarningsWithFixed({
                "amount": 6.23
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(float(esdu.earnings), 6.23)
        self.assertEquals(float(esdu2.earnings), 0)

        #bumped
        r = json.loads(
            bumpSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            fillEarningsWithFixed({
                "amount": 6.23
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()
        self.assertEquals(float(esdu2.earnings), 0)

        #session not found
        r = json.loads(
            fillEarningsWithFixed({}, esd1.id + 50,
                                  self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])
Beispiel #4
0
    def testSavePayouts(self):
        """Test save payouts"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()

        #save attend subject's pay out
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        p = {
            "payoutList": [{
                "id": esdu.id,
                "earnings": 6.23,
                "showUpFee": 7.00
            }]
        }

        r = json.loads(
            savePayouts(p, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()

        self.assertEquals(float(esdu.earnings), 6.23)
        self.assertEquals(float(esdu.show_up_fee), 7.00)

        #try to save junk
        p = {
            "payoutList": [{
                "id": esdu.id,
                "earnings": "a",
                "showUpFee": "b"
            }]
        }

        r = json.loads(
            savePayouts(p, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])

        #save to user that does not exist
        p = {
            "payoutList": [{
                "id": esdu.id + 50,
                "earnings": 6.23,
                "showUpFee": 7.00
            }]
        }

        r = json.loads(
            savePayouts(p, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])

        #save junk
        p = {"payoutList": [{"id": esdu.id + 50, "showUpFee": 7.00}]}

        r = json.loads(
            savePayouts(p, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])
Beispiel #5
0
    def testCompleteSession(self):
        """Test complete session"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        #fill with earnings then bump, check earnings removed
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            attendSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            fillEarningsWithFixed({
                "amount": 6.23
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            bumpSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            completeSession({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(float(esdu.earnings), 6.23)
        self.assertEquals(float(esdu2.earnings), 0)

        #check now show earnings bump fee
        r = json.loads(
            completeSession({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            attendSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            fillEarningsWithFixed({
                "amount": 6.23
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            fillDefaultShowUpFee({}, esd1.id,
                                 self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            completeSession({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(float(esdu.earnings), 0)
        self.assertEquals(float(esdu.earnings), 0)

        #test invalid session day
        r = json.loads(
            completeSession({}, esd1.id + 50,
                            self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])
Beispiel #6
0
    def testAttendSubject(self):
        """Test super user manual check in"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()

        #super user check in
        r = json.loads(
            attendSubject(
                {
                    "id": esdu.id
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject(
                {
                    "id": esdu.id
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        #unconfirmed user checkin
        esdu.confirmed = False
        esdu.save()
        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertNotIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject(
                {
                    "id": esdu.id
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        #none super user user manaul check in
        self.staff_u.is_superuser = False
        self.staff_u.save()

        r = json.loads(
            attendSubject(
                {
                    "id": esdu.id
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertNotIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject(
                {
                    "id": esdu.id
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        #attend subject not exists
        r = json.loads(
            attendSubject(
                {
                    "id": esdu.id + 50
                },
                esd1.id,
                self.staff_u,
            ).content.decode("UTF-8"))
        self.assertNotIn("is now attending", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])
Beispiel #7
0
    def testAutoBump(self):
        """Test auto bump"""
        logger = logging.getLogger(__name__)

        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(esdu.bumped, False)
        self.assertEquals(esdu2.bumped, False)

        #try auto bump subjects that were previously bumped
        r = json.loads(
            cancelAcceptInvitation({
                "id": self.es1.id
            }, self.u).content.decode("UTF-8"))
        self.assertFalse(r['failed'])

        r = json.loads(
            cancelAcceptInvitation({
                "id": self.es1.id
            }, self.u2).content.decode("UTF-8"))
        self.assertFalse(r['failed'])

        d_now = self.d_now

        session_day_data = {
            'status':
            'updateSessionDay',
            'id':
            esd1.id,
            'formData': [{
                'name': 'location',
                'value': str(self.l1.id)
            }, {
                'name':
                'date',
                'value':
                d_now.strftime("%#m/%#d/%Y") + ' 01:00 am -0000'
            }, {
                'name': 'length',
                'value': '60'
            }, {
                'name': 'account',
                'value': str(self.account1.id)
            }, {
                'name': 'auto_reminder',
                'value': 'true'
            }, {
                'name': 'enable_time',
                'value': 'true'
            }, {
                'name': 'custom_reminder_time',
                'value': 'false'
            }, {
                'name': 'reminder_time',
                'value': '01/05/2021 12:04 pm -0800'
            }],
            'sessionCanceledChangedMessage':
            False
        }
        r = json.loads(
            updateSessionDay(session_day_data,
                             esd1.id).content.decode("UTF-8"))
        self.assertEqual(r['status'], "success")

        esdu.confirmed = True
        esdu.save()

        esdu2.confirmed = True
        esdu2.save()

        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            attendSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            bumpAll({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esd2 = self.es2.ESD.first()
        r = json.loads(
            acceptInvitation({
                "id": self.es2.id
            }, self.u).content.decode("UTF-8"))
        self.assertFalse(r['failed'])

        r = json.loads(
            acceptInvitation({
                "id": self.es2.id
            }, self.u2).content.decode("UTF-8"))
        self.assertFalse(r['failed'])

        r = json.loads(
            autoBump({}, esd2.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd2.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd2.id, user__id=self.u2.id).first()

        self.assertEquals(esdu.bumped, False)
        self.assertEquals(esdu2.bumped, False)

        #bump 1 of two
        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        # r = json.loads(noShowSubject({"id":esdu.id},esd1.id).content.decode("UTF-8"))
        # self.assertEquals("success",r['status'])

        # r = json.loads(noShowSubject({"id":esdu2.id},esd1.id).content.decode("UTF-8"))
        # self.assertEquals("success",r['status'])

        r = json.loads(
            attendSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            attendSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertIn("is now attending", r['status'])

        r = json.loads(
            autoBump({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(True if esdu.bumped != esdu2.bumped else False, True)

        #bump 0 of two
        esd1 = self.es1.ESD.first()
        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        r = json.loads(
            noShowSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            autoBump({}, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(esdu.bumped, False)
        self.assertEquals(esdu2.bumped, False)

        #test junk input
        r = json.loads(
            noShowSubject({
                "id": esdu.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            noShowSubject({
                "id": esdu2.id
            }, esd1.id, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("success", r['status'])

        r = json.loads(
            autoBump({}, esd2.id + 50, self.staff_u).content.decode("UTF-8"))
        self.assertEquals("fail", r['status'])

        esdu = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u.id).first()
        esdu2 = experiment_session_day_users.objects.filter(
            experiment_session_day__id=esd1.id, user__id=self.u2.id).first()

        self.assertEquals(esdu.bumped, False)
        self.assertEquals(esdu2.bumped, False)