Ejemplo n.º 1
0
    def test_attempt_retrieval_expired(self):
        """
        Confirm we can not retrieve a Drop if it is past expiration.
        """

        one_minute_ago = timezone.now() - timezone.timedelta(minutes=1)
        drop = factories.Drop(expires_on=one_minute_ago)

        drop_retrieval = drop.attempt_retrieval()
        self.assertFalse(drop_retrieval.was_successful)
Ejemplo n.º 2
0
    def test_attempt_retrieval_no_limit(self):
        """
        Confirm we can attempt numerous retrievals on a Drop with no retrieval_limit.
        """

        drop = factories.Drop(retrieval_limit=None)

        all_retrievals = [drop.attempt_retrieval() for _ in range(3)]
        self.assertTrue(
            all(retrieval.was_successful for retrieval in all_retrievals))
Ejemplo n.º 3
0
    def test_retrieve_forbidden(self):
        """
        Confirm we get a 403 when attempting to retrieve a Drop that is no longer retrievable.
        """

        drop = factories.Drop(retrieval_limit=1)

        response = self.client.post(drop.link)
        self.assertEqual(response.status_code, 200)

        response = self.client.post(drop.link)
        self.assertEqual(response.status_code, 403)
Ejemplo n.º 4
0
    def test_attempt_retrieval_with_password(self):
        """
        Confirm we can retrieve a Drop providing the proper password.
        """

        password = '******'
        drop = factories.Drop(password=password)

        drop_retrieval = drop.attempt_retrieval(password='******')
        self.assertFalse(drop_retrieval.was_successful)

        drop_retrieval = drop.attempt_retrieval(password=password)
        self.assertTrue(drop_retrieval.was_successful)
Ejemplo n.º 5
0
    def test_attempt_retrieval(self):
        """
        Confirm by default we can retrieve a Drop once.
        """
        drop = factories.Drop()

        drop.attempt_retrieval()
        self.assertEqual(drop.times_retrieved, 1)

        drop.attempt_retrieval()
        drop.attempt_retrieval()

        self.assertEqual(drop.times_rejected, 2)
Ejemplo n.º 6
0
    def test_retrieve_with_password(self):
        """
        Confirm we can retrieve a Drop providing the proper password.
        """

        password = '******'
        drop = factories.Drop(password=password)

        response = self.client.post(drop.link,
                                    {'password': '******'})
        self.assertEqual(response.status_code, 403)

        response = self.client.post(drop.link, {'password': password})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json().get('text'), drop.text)
Ejemplo n.º 7
0
    def test_attempt_retrieval_with_limit(self):
        """
        Confirm we cannot retrieve a Drop more than its retrieval_limit
        """

        num_retrievals = 3
        drop = factories.Drop(retrieval_limit=num_retrievals)

        while num_retrievals:
            drop_retrieval = drop.attempt_retrieval()
            self.assertTrue(drop_retrieval.was_successful)
            num_retrievals -= 1

        drop_retrieval = drop.attempt_retrieval()
        self.assertFalse(drop_retrieval.was_successful)
Ejemplo n.º 8
0
    def test_retrieve(self):
        """
        Confirm we can retrieve a Drop via its uuid.
        """

        drop = factories.Drop(text='retrieve me!')

        self.assertIsNone(drop.last_retrieved_on)
        existing_count = Drop.objects.count()

        response = self.client.post(drop.link)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(Drop.objects.count(), existing_count)
        self.assertIn(response.json().get('text'), drop.text)

        drop.refresh_from_db()
        self.assertIsNotNone(drop.last_retrieved_on)
Ejemplo n.º 9
0
    def test_attempt_retrieval_rejection_limit_reached(self):
        """
        Confirm we can no longer retrieve a Drop once the rejection limit is reached.
        """

        password = '******'
        rejection_limit = 2
        drop = factories.Drop(password=password,
                              rejection_limit=rejection_limit,
                              retrieval_limit=2)

        drop_retrieval = drop.attempt_retrieval(password=password)
        self.assertTrue(drop_retrieval.was_successful)

        while rejection_limit:
            drop_retrieval = drop.attempt_retrieval()
            self.assertFalse(drop_retrieval.was_successful)

            rejection_limit -= 1

        # Show that the Drop became locked even though we have yet to reach the retrieval limit.
        drop_retrieval = drop.attempt_retrieval(password=password)
        self.assertLess(drop.times_retrieved, drop.retrieval_limit)
        self.assertFalse(drop_retrieval.was_successful)
Ejemplo n.º 10
0
 def test_create(self):
     """
     Confirm we can create a basic Drop.
     """
     drop = factories.Drop(text='foo')
     self.assertEqual(drop.text, 'foo')