Пример #1
0
    def test_get_items_checked_out_by(self):
        """Test get_items_checked_out_by method."""
        lendables = get_items_checked_out_by(None)
        self.assertEqual(lendables, [])

        lendables = get_items_checked_out_by(AnonymousUser())
        self.assertEqual(lendables, [])
Пример #2
0
    def test_get_items_checked_out_by(self):
        """Test get_items_checked_out_by method."""
        lendables = get_items_checked_out_by(None)
        self.assertEqual(lendables, [])

        lendables = get_items_checked_out_by(AnonymousUser())
        self.assertEqual(lendables, [])
Пример #3
0
    def test_lendable_flow(self):
        """Test the flow of lendables."""
        self.c.login(username=self.user.username, password='******')

        # Test check out lendable
        response = self.c.get(reverse('library:checkout',
                                      args=['lendable']),
                              follow=True)

        self.assertContains(response, 'is checked out to you',
                            status_code=200)
        self.assertEqual(Lendable.all_types.count(), 1)

        # Test get lendables for user
        lendables = get_items_checked_out_by(self.user)
        self.assertEqual(len(lendables), 1)

        # Test renew lendable, renew the max amount of times
        max_renewals = lendables[0].max_renewals
        lending_period_in_days = lendables[0].lending_period_in_days

        for i in range(max_renewals):
            self.c.get(reverse('library:renew', args=[lendables[0].id]),
                       follow=True)

        renewed_lendable = Lendable.all_types.get(id=lendables[0].id)

        # Confirm the proper due on date exists and matches
        # the max_due_date for lendable resource.
        d = renewed_lendable.due_on - lendables[0].due_on
        self.assertEqual(d.days, lending_period_in_days * max_renewals)
        self.assertEqual(renewed_lendable.due_on, lendables[0].max_due_date())

        # Test no more renewals available
        response = self.c.get(reverse('library:renew',
                                      args=[lendables[0].id]),
                              follow=True)
        self.assertContains(response, 'No more renewals are available '
                                      'for this item.')

        # Test renew catches generic exception
        with patch.object(Lendable,
                          'renew',
                          side_effect=Exception('Renew Failed!')):
            response = self.c.get(reverse('library:renew',
                                          args=[lendables[0].id]),
                                  follow=True)

        # Confirm error message displayed
        message = list(response.context['messages'])[0].message
        self.assertEqual(message, 'Renew Failed!')

        # Test request extension
        with self.settings(ADMINS=[('John', '*****@*****.**')]):
            response = self.c.post(reverse('library:request_extension',
                                           args=[lendables[0].id]),
                                   {'message': 'Extend me!'},
                                   follow=True)

        self.assertContains(response,
                            'Your request was sent to the openbare Admins'
                            ' and will be evaluated.')
        self.assertEqual(len(mail.outbox), 1)

        # Test request extension catches generic exception
        with patch('library.views._admin_emails',
                   side_effect=Exception('Email Failed!')):
            response = self.c.post(reverse('library:request_extension',
                                           args=[lendables[0].id]),
                                   {'message': 'Extend me!'},
                                   follow=True)

        # Confirm error message displayed
        message = list(response.context['messages'])[0].message
        self.assertEqual(message, 'Email Failed!')
Пример #4
0
    def test_lendable_flow(self):
        """Test the flow of lendables."""
        self.c.login(username=self.user.username, password='******')

        # Test check out lendable
        response = self.c.get(reverse('library:checkout',
                                      args=['lendable']),
                              follow=True)

        self.assertContains(response, 'is checked out to you',
                            status_code=200)
        self.assertEqual(Lendable.all_types.count(), 1)

        # Test get lendables for user
        lendables = get_items_checked_out_by(self.user)
        self.assertEqual(len(lendables), 1)

        # Test renew lendable, renew the max amount of times
        max_renewals = lendables[0].max_renewals
        lending_period_in_days = lendables[0].lending_period_in_days

        for i in range(max_renewals):
            self.c.get(reverse('library:renew', args=[lendables[0].id]),
                       follow=True)

        renewed_lendable = Lendable.all_types.get(id=lendables[0].id)

        # Confirm the proper due on date exists and matches
        # the max_due_date for lendable resource.
        d = renewed_lendable.due_on - lendables[0].due_on
        self.assertEqual(d.days, lending_period_in_days * max_renewals)
        self.assertEqual(renewed_lendable.due_on, lendables[0].max_due_date())

        # Test no more renewals available
        response = self.c.get(reverse('library:renew',
                                      args=[lendables[0].id]),
                              follow=True)
        self.assertContains(response, 'No more renewals are available '
                                      'for this item.')

        # Test renew catches generic exception
        with patch.object(Lendable,
                          'renew',
                          side_effect=Exception('Renew Failed!')):
            response = self.c.get(reverse('library:renew',
                                          args=[lendables[0].id]),
                                  follow=True)

        # Confirm error message displayed
        message = list(response.context['messages'])[0].message
        self.assertEqual(message, 'Renew Failed!')

        # Test request extension
        with self.settings(ADMINS=[('John', '*****@*****.**')]):
            response = self.c.post(reverse('library:request_extension',
                                           args=[lendables[0].id]),
                                   {'message': 'Extend me!'},
                                   follow=True)

        self.assertContains(response,
                            'Your request was sent to the openbare Admins'
                            ' and will be evaluated.')
        self.assertEqual(len(mail.outbox), 1)

        # Test request extension catches generic exception
        with patch('library.views._admin_emails',
                   side_effect=Exception('Email Failed!')):
            response = self.c.post(reverse('library:request_extension',
                                           args=[lendables[0].id]),
                                   {'message': 'Extend me!'},
                                   follow=True)

        # Confirm error message displayed
        message = list(response.context['messages'])[0].message
        self.assertEqual(message, 'Email Failed!')