Exemple #1
0
    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')
Exemple #2
0
    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)
Exemple #3
0
    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'])
Exemple #4
0
    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)