Beispiel #1
0
    def test_should_not_create_waitlist_item_and_raise_exception_if_there_are_no_copies(self):
        self.copy.delete()

        with self.assertRaises(ValueError):
            item = WaitlistItem.create_item(
                self.library, self.book, self.user,
            )
Beispiel #2
0
 def test_should_create_and_return_waitlist_item_if_theres_only_unavailable_copies(
         self, _):
     item = WaitlistItem.create_item(
         self.library,
         self.book,
         self.user,
     )
     self.assertIsInstance(item, WaitlistItem)
Beispiel #3
0
    def test_serialize_all_fields(self):
        waitlist_item = WaitlistItem(id=1, **self.waitlist_item_attributes)

        with patch.object(serializers, 'LibrarySerializer', return_value='library'), \
             patch.object(serializers, 'BookCompactSerializer', return_value='book'), \
             patch.object(serializers, 'UserSerializer', return_value='user'):
            serializer = WaitlistItemSerializer(instance=waitlist_item)
            data = serializer.data

        self.assertEqual(set(data.keys()),
                         set(['id', 'library', 'book', 'user', 'added_date']))
Beispiel #4
0
 def test_that_a_creation_of_waitlist_item_starts_a_notification_task(
         self, notification_task):
     borrower1 = User.objects.create(username="******",
                                     email="*****@*****.**")
     self.book.bookcopy_set.create(library=self.library, user=borrower1)
     self.waitlist_item = WaitlistItem.create_item(
         book=self.book,
         library=self.library,
         user=self.user,
     )
     notification_task.delay.assert_called_with(self.waitlist_item.id)
Beispiel #5
0
    def test_should_not_create_waitlist_item_and_raise_exception_if_there_are_available_copies(
            self, _):
        self.copy.user = None
        self.copy.save()

        with self.assertRaises(ValueError):
            item = WaitlistItem.create_item(
                self.library,
                self.book,
                self.user,
            )
Beispiel #6
0
    def test_should_create_waitlist_item_and_return_its_value(self):
        initialCount = WaitlistItem.objects.all().count()

        item = WaitlistItem.create_item(
            self.library, self.book, self.user,
        )

        finalCount = WaitlistItem.objects.all().count()
        self.assertEqual(initialCount + 1, finalCount)

        self.assertEqual(item.book, self.book)
        self.assertEqual(item.user, self.user)
        self.assertEqual(item.library, self.library)
        self.assertIsNotNone(item.added_date)
Beispiel #7
0
    def test_should_return_response_with_waitlist_item_when_create_item_is_successful(self):
        created_item = WaitlistItem(
            book=self.book,
            library=self.library,
            user=self.user,
            added_date=timezone.now())

        with patch.object(WaitlistItem, 'create_item', return_value=created_item):
            response = self.client.post(self.base_url)

        waitlist_item = response.data['waitlist_item']
        self.assertEqual(waitlist_item['user']['username'], 'claudia')
        self.assertIsNotNone(waitlist_item['added_date'])
        self.assertEqual(waitlist_item['library']['slug'], self.library.slug)
        self.assertEqual(waitlist_item['book']['id'], self.book.id)