Ejemplo n.º 1
0
    def testProjectAdminRenders(self):
        # Create a campaign for the project
        CampaignFactory(project=self.project)

        # Verify that the change project page on admin renders
        self.assertResponseRenders(
            "/admin/campaign/project/{project_id}/change/".format(
                project_id=self.project.id))
Ejemplo n.º 2
0
    def testProjectGeneratedRevenue(self):
        # Generate campaign and revenue report
        campaign = CampaignFactory()
        revenue_report = RevenueReportFactory(project=campaign.project,
                                              amount=100)

        # Verify that the amount generated is considered revenue for the project
        self.assertEqual(revenue_report.project.generated_revenue(), 100)
        self.assertEqual(revenue_report.project.generated_revenue_fans(), 20)
Ejemplo n.º 3
0
 def test_post_twibbon_with_2x1_image(self):
     campaign = CampaignFactory()
     response = self.client.post(
         reverse('twibbon-list-create',
                 kwargs={'campaign_url': campaign.campaign_url}),
         {'img': open(get_sample_image_file_path('2x1.png'), 'rb')},
         secure=True)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data['img'], ['image ratio must be 1:1'])
Ejemplo n.º 4
0
 def test_post_twibbon_without_user(self):
     user = UserFactory()
     campaign = CampaignFactory(user=user)
     response = self.client.post(
         reverse('twibbon-list-create',
                 kwargs={'campaign_url': campaign.campaign_url}),
         {'img': open(get_sample_image_file_path('1x1.png'), 'rb')},
         secure=True)
     self.assertEqual(response.status_code, 201)
     self.assertEqual(Twibbon.objects.all().count(), 1)
Ejemplo n.º 5
0
 def test_post_campaign_owner_is_valid(self):
     campaign = CampaignFactory()
     user = UserFactory(email="*****@*****.**")
     self.client.force_authenticate(user=user)
     response = self.client.post(
         reverse('twibbon-list-create',
                 kwargs={'campaign_url': campaign.campaign_url}),
         {'img': open(get_sample_image_file_path('1x1.png'), 'rb')},
         secure=True)
     twibbon = Twibbon.objects.first()
     self.assertEqual(response.status_code, 201)
     self.assertEqual(twibbon.owner_id, user.id)
Ejemplo n.º 6
0
 def test_post_twibbon_success(self):
     user = UserFactory(email="[email protected]")
     campaign1 = CampaignFactory(user=user)
     self.client.force_authenticate(user=user)
     response = self.client.post(
         reverse('twibbon-list-create',
                 kwargs={'campaign_url': campaign1.campaign_url}),
         {'img': open(get_sample_image_file_path('1x1.png'), 'rb')},
         secure=True)
     self.assertEqual(response.status_code, 201)
     self.assertEqual(Twibbon.objects.all().count(), 1)
     self.assertEqual(campaign1.twibbons.all().count(), 1)
Ejemplo n.º 7
0
 def test_get_twibbons_success(self):
     user1 = UserFactory(email="[email protected]")
     user2 = UserFactory(email="[email protected]")
     campaign = CampaignFactory(user=user1)
     TwibbonFactory(campaign=campaign, user=user2, caption="caption")
     response = self.client.get(reverse(
         'twibbon-list-create',
         kwargs={'campaign_url': campaign.campaign_url}),
                                secure=True)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data['results'][0]['caption'], 'caption')
     self.assertEqual(response.data['results'][0]['user'], user2.id)
Ejemplo n.º 8
0
 def test_put_campaign_user_unauthorized(self):
     campaign = CampaignFactory(name="campaign1")
     response = self.client.put(
         reverse('campaign-retrieve-update-destroy',
                 kwargs={'campaign_url': campaign.campaign_url}), {
                     'name': 'Nama',
                     'campaign_url': 'url',
                     'twibbon_img': open(
                         get_sample_image_file_path('1x1.png'), 'rb')
                 },
         secure=True)
     self.assertEqual(response.status_code, 401)
Ejemplo n.º 9
0
    def testFilterByFunded(self, mock_percentage_funded):
        mock_percentage_funded.return_value = 100

        # Create two artists
        # One with a campaign and one without
        funded_campaign = CampaignFactory()
        artist_without_campaign = ArtistFactory()
        funded_artists = Artist.objects.filter_by_funded()

        # Verify that the artist with the funded campaign is in the filtered queryset
        # but that the artist without the campaign is not
        self.assertIn(funded_campaign.project.artist, funded_artists)
        self.assertNotIn(artist_without_campaign, funded_artists)
Ejemplo n.º 10
0
 def test_put_campaign_success(self):
     campaign = CampaignFactory(name="campaign1")
     self.client.force_authenticate(user=campaign.user)
     response = self.client.put(
         reverse('campaign-retrieve-update-destroy',
                 kwargs={'campaign_url': campaign.campaign_url}), {
                     'name': 'Nama',
                     'campaign_url': 'url',
                     'twibbon_img': open(
                         get_sample_image_file_path('1x1.png'), 'rb')
                 },
         secure=True)
     new_campaign = Campaign.objects.first()
     self.assertEqual(response.status_code, 200)
     self.assertEqual(new_campaign.name, 'Nama')
Ejemplo n.º 11
0
 def test_put_campaign_user_forbidden(self):
     user1 = UserFactory(email="*****@*****.**")
     user2 = UserFactory(email="*****@*****.**")
     campaign = CampaignFactory(name="campaign1", user=user1)
     self.client.force_authenticate(user=user2)
     response = self.client.put(
         reverse('campaign-retrieve-update-destroy',
                 kwargs={'campaign_url': campaign.campaign_url}), {
                     'name': 'Nama',
                     'campaign_url': 'url',
                     'twibbon_img': open(
                         get_sample_image_file_path('1x1.png'), 'rb')
                 },
         secure=True)
     self.assertEqual(response.status_code, 403)
Ejemplo n.º 12
0
 def test_put_twibbon_user_unauthorized(self):
     user = UserFactory(email="[email protected]")
     campaign = CampaignFactory(name="campaign1", user=user)
     twibbon = TwibbonFactory(campaign=campaign, caption="heho", user=user)
     response = self.client.put(
         reverse('twibbon-retrieve-update-destroy',
                 kwargs={
                     'campaign_url': campaign.campaign_url,
                     'twibbon_id': twibbon.id
                 }),
         {
             'caption': 'Hehe',
             'img': open(get_sample_image_file_path('1x1.png'), 'rb')
         },
         secure=True)
     new_twibbon = Twibbon.objects.first()
     self.assertEqual(response.status_code, 401)
     self.assertEqual(new_twibbon.caption, "heho")
Ejemplo n.º 13
0
 def setUpTestData(cls):
     super(ArtistWebTestCase, cls).setUpTestData()
     cls.campaign = CampaignFactory()
     cls.artist = cls.campaign.project.artist
Ejemplo n.º 14
0
 def test_owner_id(self):
     user = UserFactory()
     campaign = CampaignFactory(user=user)
     self.assertEqual(user.id, campaign.owner_id)
Ejemplo n.º 15
0
 def testCampaignRaisingZeroIsAlreadyFunded(self):
     campaign = CampaignFactory(amount=0)
     self.assertEqual(campaign.percentage_funded(), 100)
Ejemplo n.º 16
0
    def testUserInvests(self, mock_stripe_customer_create,
                        mock_stripe_charge_create):
        # Mock responses from Stripe
        mock_stripe_customer_create.return_value = {
            'account_balance': 0,
            'business_vat_id': None,
            'created': 1462665000,
            'currency': None,
            'default_source': 'card_2CXngrrA798I5wA01wQ74iTR',
            'delinquent': False,
            'description': None,
            'discount': None,
            'email': self.USER_EMAIL,
            'id': 'cus_2Pc8xEoaTAnVKr',
            'livemode': False,
            'metadata': {},
            'object': 'customer',
            'shipping': None,
            'sources': {
                'data': [
                    {
                        'address_city': None,
                        'address_country': None,
                        'address_line1': None,
                        'address_line1_check': None,
                        'address_line2': None,
                        'address_state': None,
                        'address_zip': None,
                        'address_zip_check': None,
                        'brand': 'Visa',
                        'country': 'US',
                        'customer': 'cus_2Pc8xEoaTAnVKr',
                        'cvc_check': 'pass',
                        'dynamic_last4': None,
                        'exp_month': 5,
                        'exp_year': 2019,
                        'fingerprint': 'Lq9DFkUmxf7xWHkn',
                        'funding': 'credit',
                        'id': 'card_2CXngrrA798I5wA01wQ74iTR',
                        'last4': '4242',
                        'metadata': {},
                        'name': self.USER_EMAIL,
                        'object': 'card',
                        'tokenization_method': None,
                    },
                ],
                'has_more':
                False,
                'object':
                'list',
                'total_count':
                1,
                'url':
                '/v1/customers/cus_2Pc8xEoaTAnVKr/sources',
            },
            'subscriptions': {
                'data': [],
                'has_more': False,
                'object': 'list',
                'total_count': 0,
                'url': '/v1/customers/cus_2Pc8xEoaTAnVKr/subscriptions',
            },
        }
        mock_stripe_charge_create.return_value = {
            'amount': 235,
            'amount_refunded': 0,
            'application_fee': None,
            'balance_transaction': 'txn_Sazj9jMCau62PxJhOLzBXM3p',
            'captured': True,
            'created': 1462665010,
            'currency': 'usd',
            'customer': 'cus_2Pc8xEoaTAnVKr',
            'description': None,
            'destination': None,
            'dispute': None,
            'failure_code': None,
            'failure_message': None,
            'fraud_details': {},
            'id': 'ch_Upra88VQlJJPd0JxeTM0ZvHv',
            'invoice': None,
            'livemode': False,
            'metadata': {},
            'object': 'charge',
            'order': None,
            'paid': True,
            'receipt_email': None,
            'receipt_number': None,
            'refunded': False,
            'refunds': {
                'data': [],
                'has_more': False,
                'object': 'list',
                'total_count': 0,
                'url': '/v1/charges/ch_Upra88VQlJJPd0JxeTM0ZvHv/refunds',
            },
            'shipping': None,
            'source': {
                'address_city': None,
                'address_country': None,
                'address_line1': None,
                'address_line1_check': None,
                'address_line2': None,
                'address_state': None,
                'address_zip': None,
                'address_zip_check': None,
                'brand': 'Visa',
                'country': 'US',
                'customer': 'cus_2Pc8xEoaTAnVKr',
                'cvc_check': None,
                'dynamic_last4': None,
                'exp_month': 5,
                'exp_year': 2019,
                'fingerprint': 'Lq9DFkUmxf7xWHkn',
                'funding': 'credit',
                'id': 'card_2CXngrrA798I5wA01wQ74iTR',
                'last4': '4242',
                'metadata': {},
                'name': self.USER_EMAIL,
                'object': 'card',
                'tokenization_method': None,
            },
            'source_transfer': None,
            'statement_descriptor': None,
            'status': 'succeeded',
        }

        # Create campaign
        campaign = CampaignFactory()

        # User sends payment to Stripe
        self.assertResponseRenders(
            '/artist/{slug}/'.format(slug=campaign.project.artist.slug))
        self.assertAPIResponseRenders(
            '/api/payments/charge/{campaign_id}/'.format(
                campaign_id=campaign.id),
            status_code=205,
            method='POST',
            data={
                'card': 'tok_6WqQnRecbRRrqvrdT1XXGP1d',
                'num_shares': 1
            })
Ejemplo n.º 17
0
    def testUserInvests(self, mock_stripe_customer_create,
                        mock_stripe_charge_create):
        # Mock responses from Stripe
        mock_stripe_customer_create.return_value = {
            "account_balance": 0,
            "business_vat_id": None,
            "created": 1462665000,
            "currency": None,
            "default_source": "card_2CXngrrA798I5wA01wQ74iTR",
            "delinquent": False,
            "description": None,
            "discount": None,
            "email": self.USER_EMAIL,
            "id": "cus_2Pc8xEoaTAnVKr",
            "livemode": False,
            "metadata": {},
            "object": "customer",
            "shipping": None,
            "sources": {
                "data": [{
                    "address_city": None,
                    "address_country": None,
                    "address_line1": None,
                    "address_line1_check": None,
                    "address_line2": None,
                    "address_state": None,
                    "address_zip": None,
                    "address_zip_check": None,
                    "brand": "Visa",
                    "country": "US",
                    "customer": "cus_2Pc8xEoaTAnVKr",
                    "cvc_check": "pass",
                    "dynamic_last4": None,
                    "exp_month": 5,
                    "exp_year": 2019,
                    "fingerprint": "Lq9DFkUmxf7xWHkn",
                    "funding": "credit",
                    "id": "card_2CXngrrA798I5wA01wQ74iTR",
                    "last4": "4242",
                    "metadata": {},
                    "name": self.USER_EMAIL,
                    "object": "card",
                    "tokenization_method": None,
                }],
                "has_more":
                False,
                "object":
                "list",
                "total_count":
                1,
                "url":
                "/v1/customers/cus_2Pc8xEoaTAnVKr/sources",
            },
            "subscriptions": {
                "data": [],
                "has_more": False,
                "object": "list",
                "total_count": 0,
                "url": "/v1/customers/cus_2Pc8xEoaTAnVKr/subscriptions",
            },
        }
        mock_stripe_charge_create.return_value = {
            "amount": 235,
            "amount_refunded": 0,
            "application_fee": None,
            "balance_transaction": "txn_Sazj9jMCau62PxJhOLzBXM3p",
            "captured": True,
            "created": 1462665010,
            "currency": "usd",
            "customer": "cus_2Pc8xEoaTAnVKr",
            "description": None,
            "destination": None,
            "dispute": None,
            "failure_code": None,
            "failure_message": None,
            "fraud_details": {},
            "id": "ch_Upra88VQlJJPd0JxeTM0ZvHv",
            "invoice": None,
            "livemode": False,
            "metadata": {},
            "object": "charge",
            "order": None,
            "paid": True,
            "receipt_email": None,
            "receipt_number": None,
            "refunded": False,
            "refunds": {
                "data": [],
                "has_more": False,
                "object": "list",
                "total_count": 0,
                "url": "/v1/charges/ch_Upra88VQlJJPd0JxeTM0ZvHv/refunds",
            },
            "shipping": None,
            "source": {
                "address_city": None,
                "address_country": None,
                "address_line1": None,
                "address_line1_check": None,
                "address_line2": None,
                "address_state": None,
                "address_zip": None,
                "address_zip_check": None,
                "brand": "Visa",
                "country": "US",
                "customer": "cus_2Pc8xEoaTAnVKr",
                "cvc_check": None,
                "dynamic_last4": None,
                "exp_month": 5,
                "exp_year": 2019,
                "fingerprint": "Lq9DFkUmxf7xWHkn",
                "funding": "credit",
                "id": "card_2CXngrrA798I5wA01wQ74iTR",
                "last4": "4242",
                "metadata": {},
                "name": self.USER_EMAIL,
                "object": "card",
                "tokenization_method": None,
            },
            "source_transfer": None,
            "statement_descriptor": None,
            "status": "succeeded",
        }

        # Create campaign
        campaign = CampaignFactory()

        # User sends payment to Stripe
        self.assertResponseRenders(f"/artist/{campaign.project.artist.slug}/")
        self.assertAPIResponseRenders(
            f"/api/payments/charge/{campaign.id}/",
            status_code=205,
            method="POST",
            data={
                "card": "tok_6WqQnRecbRRrqvrdT1XXGP1d",
                "num_shares": 1
            },
        )