Example #1
0
    def test_export_rewards_anonymous(self):
        request = self.request_factory.get('/')
        request.user = MockUser()

        project = ProjectFactory.create()
        reward = RewardFactory.create(project=project, amount=Money(10, 'EUR'))

        reward_order = OrderFactory.create(status='success', user=None)
        donation = DonationFactory.create(project=project,
                                          reward=reward,
                                          order=reward_order,
                                          name='test',
                                          amount=Money(100, 'EUR'))

        order = OrderFactory.create(status='success')
        DonationFactory.create(project=project, order=order)

        response = self.project_admin.export_rewards(request, project.id)
        reader = csv.DictReader(StringIO.StringIO(response.content))

        result = [line for line in reader]
        self.assertEqual(len(result), 1)
        line = result[0]

        self.assertEqual(line['Email'], '')
        self.assertEqual(line['Name'], '')
        self.assertEqual(line['Order id'], str(reward_order.id))
        self.assertEqual(line['Reward'], reward.title)
        self.assertEqual(line['Amount'], str(reward.amount))
        self.assertEqual(line['Actual Amount'], str(donation.amount))
        self.assertEqual(line['Name on Donation'], donation.name)
Example #2
0
    def test_create_reward_different_currency(self, check_status_psp):
        """
        Test donation in the current donation flow where we have just one donation that can't be deleted.
        """
        self.project.currencies = ['EUR', 'USD']
        self.project.save()

        # Create an order
        response = self.client.post(self.manage_order_list_url, {},
                                    token=self.user1_token)

        order_id = response.data['id']
        reward = RewardFactory.create(project=self.project, amount=100)

        donation = {
            "reward": reward.pk,
            "project": self.project.slug,
            "order": order_id,
            "amount": {
                'amount': 200,
                'currency': 'USD'
            }
        }

        response = self.client.post(self.manage_donation_list_url,
                                    donation,
                                    token=self.user1_token)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertTrue('must match reward currency' in
                        response.data['non_field_errors'][0])
Example #3
0
    def test_create_reward_lower_donation_amount(self, check_status_psp):
        """
        Test donation in the current donation flow where we have just one donation that can't be deleted.
        """

        # Create an order
        response = self.client.post(self.manage_order_list_url, {},
                                    token=self.user1_token)
        order_id = response.data['id']

        reward = RewardFactory.create(project=self.project, amount=100)

        donation = {
            "reward": reward.pk,
            "project": self.project.slug,
            "order": order_id,
            "amount": 50
        }

        response = self.client.post(self.manage_donation_list_url,
                                    donation,
                                    token=self.user1_token)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertTrue('less than the reward amount' in
                        response.data['non_field_errors'][0])
Example #4
0
 def test_reward_can_only_be_deleted_by_project_owner(self):
     """
     Non project owner can't delete a reward on that project.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     response = self.client.delete(reward_url, token=self.user2_token)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #5
0
 def test_reward_can_be_deleted(self):
     """
     Project owner can delete a reward on a project.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     response = self.client.delete(reward_url, token=self.user_token)
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Example #6
0
 def test_reward_can_be_deleted(self):
     """
     Project owner can delete a reward on a project.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     response = self.client.delete(reward_url, token=self.user_token)
     self.assertEqual(response.status_code, 204)
Example #7
0
 def test_reward_can_only_be_deleted_by_project_owner(self):
     """
     Non project owner can't delete a reward on that project.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     response = self.client.delete(reward_url, token=self.user2_token)
     self.assertEqual(response.status_code, 403)
Example #8
0
    def setUp(self):
        super(ProjectPermissionsTestCase, self).setUp()
        self.init_projects()

        self.owner = BlueBottleUserFactory.create()
        self.owner_token = "JWT {0}".format(self.owner.get_jwt_token())

        self.not_owner = BlueBottleUserFactory.create()
        self.not_owner_token = "JWT {0}".format(self.not_owner.get_jwt_token())
        self.project = ProjectFactory.create(owner=self.owner)
        RewardFactory.create(project=self.project)
        RewardFactory.create(project=self.project)

        self.project_manage_url = reverse('project_manage_detail',
                                          kwargs={'slug': self.project.slug})

        self.project_detail_url = reverse('project_detail',
                                          kwargs={'slug': self.project.slug})
Example #9
0
    def test_reward_without_limit(self):
        reward = RewardFactory.create(project=self.project)
        data = self.donation_data
        data['reward'] = reward.pk

        response = self.client.post(
            self.donations_url,
            self.donation_data,
            token=self.donor_token
        )
        self.assertEqual(response.status_code, 201)
Example #10
0
 def test_reward_with_donations_can_not_be_deleted(self):
     """
     Project owner can't delete a reward which has donations.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     donation = DonationFactory.create(reward=reward, project=self.project)
     donation.order.locked()
     donation.order.succeeded()
     donation.save()
     response = self.client.delete(reward_url, token=self.user_token)
     self.assertEqual(response.status_code, 403)
Example #11
0
 def test_reward_with_donations_can_not_be_deleted(self):
     """
     Project owner can't delete a reward which has donations.
     """
     reward = RewardFactory.create(project=self.project)
     reward_url = reverse('reward-detail', kwargs={'pk': reward.id})
     donation = DonationFactory.create(reward=reward, project=self.project)
     donation.order.locked()
     donation.order.save()
     donation.order.success()
     donation.order.save()
     donation.save()
     response = self.client.delete(reward_url, token=self.user_token)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #12
0
    def test_project_donation_list_without_amounts(self, check_status_psp):
        setattr(properties, 'SHOW_DONATION_AMOUNTS', False)
        reward = RewardFactory.create(project=self.project3)
        order = OrderFactory.create(user=self.user2)
        DonationFactory.create(amount=2000, project=self.project3, reward=reward,
                               order=order)

        response = self.client.get(self.project_donation_list_url,
                                   {'project': self.project3.slug},
                                   token=self.user1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1,
                         'Only the successful donation should be returned')
        self.assertNotIn('amount', response.data['results'][0])
        self.assertNotIn('reward', response.data['results'][0])
Example #13
0
    def test_project_donation_list_without_amounts(self, check_status_psp):
        setattr(properties, 'SHOW_DONATION_AMOUNTS', False)
        reward = RewardFactory.create(project=self.project3)
        order = OrderFactory.create(user=self.user2)
        DonationFactory.create(amount=2000,
                               project=self.project3,
                               reward=reward,
                               order=order)

        response = self.client.get(self.project_donation_list_url,
                                   {'project': self.project3.slug},
                                   token=self.user1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1,
                         'Only the successful donation should be returned')
        self.assertNotIn('amount', response.data['results'][0])
        self.assertNotIn('reward', response.data['results'][0])
Example #14
0
    def test_export_rewards(self):
        request = self.request_factory.get('/')
        request.user = MockUser()

        project = ProjectFactory.create(
            title="¡Tést, with löt's of weird things!")
        reward = RewardFactory.create(project=project, amount=Money(10, 'EUR'))

        reward_order = OrderFactory.create(status='success')
        donation = DonationFactory.create(project=project,
                                          reward=reward,
                                          order=reward_order,
                                          amount=Money(100, 'EUR'))

        order = OrderFactory.create(status='success')
        DonationFactory.create(project=project, order=order)

        response = self.project_admin.export_rewards(request, project.id)
        header = 'Content-Type: text/csv\r\n' \
                 'Content-Disposition: attachment; ' \
                 'filename="test-with-lots-of-weird-things.csv"'
        self.assertEqual(response.serialize_headers(), header)

        reader = csv.DictReader(StringIO.StringIO(response.content))

        result = [line for line in reader]
        self.assertEqual(len(result), 1)
        line = result[0]

        self.assertEqual(line['Email'], reward_order.user.email)
        self.assertEqual(line['Name'], reward_order.user.full_name)
        self.assertEqual(line['Order id'], str(reward_order.id))
        self.assertEqual(line['Reward'], reward.title)
        self.assertEqual(line['Description'], reward.description)
        self.assertEqual(line['Amount'], str(reward.amount))
        self.assertEqual(line['Actual Amount'], str(donation.amount))
Example #15
0
    def test_reward_list_only_own_projects(self):
        """
        Make sure only rewards for the given project are shown.
        """
        RewardFactory.create(project=self.project)
        RewardFactory.create(project=self.project)
        RewardFactory.create(project=self.project2)

        authenticated = Group.objects.get(name='Authenticated')
        authenticated.permissions.remove(
            Permission.objects.get(codename='api_read_reward')
        )
        authenticated.permissions.add(
            Permission.objects.get(codename='api_read_own_reward')
        )

        response = self.client.get(
            self.reward_url,
            token=self.user_token
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)