Example #1
0
File: tests.py Project: kfarr2/ITS
    def test_save_staff_and_user_email(self):

        """
        Checks that an email is sent to the user as well as another to staff when a valuable
        item is checked in.
        """

        new_item = make(Item, is_valuable=True)
        new_action = Action.objects.get(machine_name=Action.CHECKED_IN)
        make(Status, action_taken=new_action, item=new_item)
        new_category = make(Category)
        new_location = make(Location)

        data = {'location': new_location,
                'category': new_category,
                'description': new_item.description,
                'is_valuable': new_item.is_valuable,
                'username': "",
                'possible_owner_found': True,
                'first_name': "test",
                'last_name': "test",
                'email': "*****@*****.**", }

        user = create_user()

        with patch('its.items.forms.CheckInForm.clean', return_value=data):
            form = CheckInForm(data)
            form.cleaned_data = data
            with patch("its.items.forms.ModelForm.save", return_value=new_item):
                form.save(current_user=user)

                self.assertEquals(len(mail.outbox), 2)
                self.assertEquals(mail.outbox[0].subject, 'An item belonging to you was found')
                self.assertEquals(mail.outbox[1].subject, 'Valuable item checked in')
Example #2
0
File: tests.py Project: kfarr2/ITS
    def test_save_no_email(self):

        """
        Checks that an email is not sent when a non-valuable item is checked in.
        """

        new_item = make(Item, is_valuable=False)
        new_action = Action.objects.get(machine_name=Action.CHECKED_IN)
        make(Status, action_taken=new_action, item=new_item)
        new_category = make(Category)
        new_location = make(Location)

        data = {'location': new_location,
                'category': new_category,
                'description': new_item.description,
                'is_valuable': new_item.is_valuable,
                'username': "",
                'possible_owner_found': False,
                'first_name': "",
                'last_name': "",
                'email': "", }

        user = create_user()

        with patch('its.items.forms.CheckInForm.clean', return_value=data):
            form = CheckInForm(data)
            form.cleaned_data = data
            with patch("its.items.forms.ModelForm.save", return_value=new_item):
                form.save(current_user=user)

                self.assertEquals(len(mail.outbox), 0)
Example #3
0
File: views.py Project: kfarr2/ITS
def checkin(request):

    """
    Item check in form
    Allows lab attendant to check an item into inventory.
    """

    if request.method == 'POST':
        form = CheckInForm(request.POST)

        if form.is_valid():
            new_item = form.save(current_user=request.user)
            return HttpResponseRedirect(reverse("printoff", args=[new_item.pk]))

    else:
        form = CheckInForm()

    return render(request, 'items/checkin.html', {'form': form})
Example #4
0
File: tests.py Project: kfarr2/ITS
    def test_clean_no_errors(self):

        """
        Tests that the clean method does not return errors when
        the form is filled out correctly.
        """

        data = {"possible_owner_found": "1",
                "first_name": "Test",
                "last_name": "Test",
                "email": "*****@*****.**",
                "username": "******", }

        with patch('its.items.forms.ModelForm.clean', return_value=data):
            with patch('its.items.forms.check_ldap', return_value=True):
                form = CheckInForm()
                form.cleaned_data = form.clean()
                self.assertTrue(form.cleaned_data['possible_owner_found'] == data['possible_owner_found'])
                self.assertTrue(form.cleaned_data['username'] == data['username'])
                self.assertTrue(form.cleaned_data['first_name'] == data['first_name'])
                self.assertTrue(form.cleaned_data['last_name'] == data['last_name'])
                self.assertTrue(form.cleaned_data['email'] == data['email'])
Example #5
0
File: tests.py Project: kfarr2/ITS
    def test_save_new_user(self):

        """
        Tests to make sure that the save method creates a new user when it
        does not already exist in the database.
        """

        new_item = make(Item)
        new_action = Action.objects.get(machine_name=Action.CHECKED_IN)
        make(Status, action_taken=new_action, item=new_item)
        new_category = make(Category)
        new_location = make(Location)

        data = {'location': new_location,
                'category': new_category,
                'description': new_item.description,
                'is_valuable': True,
                'username': "",
                'possible_owner_found': True,
                'first_name': "test",
                'last_name': "test",
                'email': "*****@*****.**", }

        user = create_user()

        with patch('its.items.forms.CheckInForm.clean', return_value=data):
            form = CheckInForm(data)
            form.cleaned_data = data

            with patch("its.items.forms.ModelForm.save", return_value=new_item):
                form.save(current_user=user)

                new_user = User.objects.get(first_name=data['first_name'], last_name=data['last_name'], email=data['email'])

                self.assertTrue(data['first_name'] == new_user.first_name)
                self.assertTrue(data['last_name'] == new_user.last_name)
                self.assertTrue(data['email'] == new_user.email)
Example #6
0
File: tests.py Project: kfarr2/ITS
    def test_clean_errors(self):

        """
        Tests that the clean method does return errors when
        the form is filled out incorrectly.
        """

        data = {
            "possible_owner_found": "1",
            "first_name": "",
            "last_name": "",
            "email": "",
            "username": "******"
        }

        with patch("its.items.forms.ModelForm.clean", return_value=data):
            with patch("its.items.forms.check_ldap", return_value=False):
                with patch("its.items.forms.CheckInForm.add_error") as add_error:
                    form = CheckInForm()
                    form.clean()
                    add_error.assert_any_call_with("first_name", "First name required")
                    add_error.assert_any_call_with("last_name", "Last name required")
                    add_error.assert_any_call_with("email", "Email required")
                    add_error.assert_any_call_with("username", "Invalid username, enter a valid username or leave blank.")