def test_checkin_of_already_returned_gear(self):
     """Test checkin of available gear by valid staffer is fine"""
     gear = Gear.objects.get(rfid=GEAR_RFID)
     self.assertEqual(gear.is_available(), True)
     do_checkin(ADMIN_RFID, GEAR_RFID)
     gear = Gear.objects.get(rfid=GEAR_RFID)
     self.assertEqual(gear.is_available(), True)
Esempio n. 2
0
    def post(request, rfid):
        form = HomeForm(request.POST)
        if form.is_valid():
            gear_rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid
            member_rfid = rfid

            try:
                gear = Gear.objects.get(rfid=gear_rfid)
            except Gear.DoesNotExist:
                gear = None

            if gear:
                if gear.is_available():
                    do_checkout(staffer_rfid, member_rfid, gear_rfid)
                    alert_message = f'{gear.name} was checked out successfully'
                    messages.add_message(request, messages.INFO, alert_message)
                else:
                    do_checkin(staffer_rfid, gear_rfid)
                    alert_message = f'{gear.name} was checked in successfully'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
            else:
                alert_message = 'The RFID tag is not registered to a piece of gear'
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('kiosk:check_out', member_rfid)
 def test_checkin_gear_by_nonexistent_member(self):
     """Do checkout then test checkin of checked out gear by nonexistent member fails"""
     do_checkout(ADMIN_RFID, MEMBER_RFID1, GEAR_RFID)
     with self.assertRaises(Member.DoesNotExist):
         do_checkin("0000010002", GEAR_RFID)
     gear = Gear.objects.get(rfid=GEAR_RFID)
     self.assertEqual(gear.is_rented_out(), True)
Esempio n. 4
0
    def post(self, request):
        form = HomeForm(request.POST)
        if form.is_valid():
            rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid
            gear = Gear.objects.filter(rfid=rfid)
            member = Member.objects.filter(rfid=rfid)

            if member and member.get():
                return redirect('check_out', rfid)
            elif gear:
                gear = gear.get()
                if gear.is_rented_out():
                    do_checkin(staffer_rfid, rfid)
                    alert_message = gear.name + " was checked in successfully"
                    messages.add_message(request, messages.INFO, alert_message)
                else:
                    alert_message = gear.name + " is already checked in"
                    messages.add_message(request, messages.INFO, alert_message)
                    return redirect('home')
            else:
                alert_message = "The RFID tag is not registered to a user or gear"
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('home')
Esempio n. 5
0
 def test_checkin_gear_by_unauthorized_member(self):
     """Do checkout then test checkin of checked out gear by unauthorized member fails"""
     do_checkout(ADMIN_RFID, MEMBER_RFID1, GEAR_RFID)
     with self.assertRaises(ValidationError):
         do_checkin(MEMBER_RFID1, GEAR_RFID)
     gear = Gear.objects.get(rfid=GEAR_RFID)
     self.assertEqual(gear.is_rented_out(), True)
Esempio n. 6
0
    def post_member_or_gear_rfid(request, rfid: str):
        """Check in item or check it out to a member"""
        form = HomeForm(request.POST)
        if form.is_valid():
            form_rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid

            try:
                gear_rfid = form_rfid
                gear = Gear.objects.get(rfid=gear_rfid)
            except Gear.DoesNotExist:
                try:
                    gear_rfid = rfid
                    gear = Gear.objects.get(rfid=gear_rfid)
                except Gear.DoesNotExist:
                    gear = None
                    gear_rfid = None

            try:
                member_rfid = form_rfid
                member = Member.objects.get(rfid=member_rfid)
            except Member.DoesNotExist:
                try:
                    member_rfid = form_rfid
                    member = Member.objects.get(rfid=member_rfid)
                except Member.DoesNotExist:
                    member = None
                    member_rfid = None

            if gear:
                if gear_rfid == form_rfid:
                    if gear.is_rented_out():
                        do_checkin(staffer_rfid, gear.rfid)
                        alert_message = f'{gear.name} was checked in successfully'
                        messages.add_message(request, messages.INFO,
                                             alert_message)
                    else:
                        alert_message = 'Gear is already checked in'
                        messages.add_message(request, messages.WARNING,
                                             alert_message)
                elif member and member_rfid == form_rfid:
                    if gear.is_rented_out():
                        do_checkin(staffer_rfid, gear_rfid)
                    do_checkout(staffer_rfid, member_rfid, gear_rfid)
                    alert_message = 'Gear checked out!'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
                else:
                    alert_message = 'The RFID is not registered to any gear'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
            else:
                alert_message = 'The RFID is not registered to any gear'
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('kiosk:gear', gear_rfid)
 def test_checkin_gear(self):
     """Do checkout then test checkin of checked out gear by valid staffer succeeds"""
     do_checkout(ADMIN_RFID, MEMBER_RFID1, GEAR_RFID)
     do_checkin(ADMIN_RFID, GEAR_RFID)
     gear = Gear.objects.get(rfid=GEAR_RFID)
     self.assertEqual(gear.is_available(), True)