def testBumpSubject(self): """Test bump subjects""" 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() #bump subject r = json.loads( bumpSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertIn("success", r['status']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #bump subject not exists r = json.loads( bumpSubject({ "id": esdu.id + 50 }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("success", r['status']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #bump subject not confirmed esdu.confirmed = False esdu.save() r = json.loads( bumpSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("success", r['status']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status'])
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'])
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'])
def testNoShowSubject(self): """Test no show subjects""" 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() r = json.loads( noShowSubject({ "id": esdu.id + 50 }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotEquals("success", r['status'])
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'])
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'])
def testStripeReaderCheckin(self): """Test subject confirm and cancel no conflicts""" 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() self.assertIsInstance(esdu, experiment_session_day_users) #check leading zeros r = json.loads( getStripeReaderCheckin( { "value": ";00123456=1234", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check no zeros r = json.loads( getStripeReaderCheckin( { "value": ";123456=1234", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check no equals r = json.loads( getStripeReaderCheckin( { "value": ";123456", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check no semi colon r = json.loads( getStripeReaderCheckin( { "value": "123456=", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check wrong number r = json.loads( getStripeReaderCheckin( { "value": ";56456565=", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check checkin similar id numbers r = json.loads( getStripeReaderCheckin( { "value": ";1234=", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertEquals("success", r['status']) #check in unconfirmed r = json.loads( changeConfirmationStatus( { "userId": self.u.id, "confirmed": "unconfirm", "actionAll": "false", "esduId": esdu.id }, self.es1.id, False).content.decode("UTF-8")) self.assertEqual(r['status'], "success") r = json.loads( getStripeReaderCheckin( { "value": ";00123456=1234", "autoAddUsers": False, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( noShowSubject({ "id": esdu.id }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']) #check add to sessin esdu = experiment_session_day_users.objects.filter( experiment_session_day__id=esd1.id, user__id=self.u3.id).first() self.assertEquals(esdu, None) r = json.loads( getStripeReaderCheckin( { "value": ";00121212=1234", "autoAddUsers": True, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertIn("is now attending", r['status']['message']) #check add again: r = json.loads( getStripeReaderCheckin( { "value": ";00121212=1234", "autoAddUsers": True, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) #check recruitment violation #remove user 3 from sessoin esdu = experiment_session_day_users.objects.filter( experiment_session_day__id=esd1.id, user__id=self.u3.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( changeConfirmationStatus( { "userId": self.u3.id, "confirmed": "unconfirm", "actionAll": "false", "esduId": esdu.id }, self.es1.id, False).content.decode("UTF-8")) self.assertEqual(r['status'], "success") r = json.loads( removeSubject({ "userId": self.u3.id, "esduId": "", }, self.es1.id).content.decode("UTF-8")) self.assertIn("success", r['status']) #remove all genders self.es1.recruitment_params.gender.clear() self.es1.recruitment_params.save() r = json.loads( getStripeReaderCheckin( { "value": ";00121212=1234", "autoAddUsers": True, "ignoreConstraints": False }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertNotIn("is now attending", r['status']['message']) r = json.loads( getStripeReaderCheckin( { "value": ";00121212=1234", "autoAddUsers": True, "ignoreConstraints": True }, esd1.id, self.staff_u).content.decode("UTF-8")) self.assertIn("is now attending", r['status']['message'])
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)