Пример #1
0
    def setUp(self):
        super(DonationApiTestCase, self).setUp()

        self.create_session()

        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())

        self.init_projects()

        self.project1 = ProjectFactory.create(amount_asked=5000)
        self.project1.set_status('campaign')

        self.project2 = ProjectFactory.create(amount_asked=3750)
        self.project2.set_status('campaign')

        self.manage_order_list_url = reverse('manage-order-list')
        self.manage_donation_list_url = reverse('manage-donation-list')

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.user2 = BlueBottleUserFactory.create(is_co_financer=True)
        self.user2_token = "JWT {0}".format(self.user2.get_jwt_token())

        self.project = ProjectFactory.create()
        self.order = OrderFactory.create(user=self.user)

        self.dollar_project = ProjectFactory.create(currencies=['USD'])
        self.multi_project = ProjectFactory.create(currencies=['EUR', 'USD', 'NGN'])
Пример #2
0
    def setUp(self):
        super(PayoutBaseTestCase, self).setUp()

        self.init_projects()

        # Set up a project ready for payout
        self.organization = OrganizationFactory.create()
        self.organization.save()
        self.project = ProjectFactory.create(organization=self.organization,
                                             amount_asked=50)
        self.project_incomplete = ProjectFactory.create(
            organization=self.organization, amount_asked=100)

        # Update phase to campaign.
        self.project.status = ProjectPhase.objects.get(slug='campaign')
        self.project.save()

        self.project_incomplete.status = ProjectPhase.objects.get(
            slug='campaign')
        self.project_incomplete.save()

        self.order = OrderFactory.create()

        self.donation = DonationFactory.create(project=self.project,
                                               order=self.order,
                                               amount=60)
        self.donation.save()

        self.donation2 = DonationFactory.create(
            project=self.project_incomplete, order=self.order, amount=60)
        self.donation2.save()
Пример #3
0
    def setUp(self):
        super(TaskApiIntegrationTests, self).setUp()

        self.init_projects()

        campaign = ProjectPhase.objects.get(slug='campaign')

        self.some_user = BlueBottleUserFactory.create()
        self.some_token = "JWT {0}".format(self.some_user.get_jwt_token())
        self.some_project = ProjectFactory.create(owner=self.some_user,
                                                  status=campaign)

        self.another_user = BlueBottleUserFactory.create()
        self.another_token = "JWT {0}".format(
            self.another_user.get_jwt_token())
        self.another_project = ProjectFactory.create(owner=self.another_user)

        self.task = TaskFactory.create(project=self.some_project)

        self.skill1 = SkillFactory.create()
        self.skill2 = SkillFactory.create()
        self.skill3 = SkillFactory.create()
        self.skill4 = SkillFactory.create()

        self.task_url = reverse('task-list')
        self.task_preview_url = reverse('task_preview_list')
        self.task_members_url = reverse('task-member-list')
        self.task_detail_url = reverse('task_detail', args=(self.task.pk, ))
Пример #4
0
    def test_total_raised(self):
        """ Calculate the total amount raised by successful donations """
        project1 = ProjectFactory.create(amount_asked=1000)
        project2 = ProjectFactory.create(amount_asked=1000)

        user1 = BlueBottleUserFactory.create()
        user2 = BlueBottleUserFactory.create()
        user3 = BlueBottleUserFactory.create()

        order1 = OrderFactory.create(user=user1)
        donation1 = DonationFactory(order=order1, amount=10, project=project1)
        order1.locked()
        order1.failed()

        order2 = OrderFactory.create(user=user2)
        donation2 = DonationFactory(order=order2, amount=10, project=project1)
        order2.locked()
        order2.succeeded()

        order3 = OrderFactory.create(user=user2)
        donation3 = DonationFactory(order=order3, amount=10, project=project2)
        order3.locked()
        order3.succeeded()

        order4 = OrderFactory.create(user=user3)
        donation4 = DonationFactory(order=order4, amount=10, project=project1)
        order4.locked()
        order4.succeeded()

        # order2, order3, order4 should be counted
        self.assertEqual(self.metrics.calculate_total_raised(), 30)
Пример #5
0
    def setUp(self):
        super(DonationApiTestCase, self).setUp()

        self.create_session()

        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())

        self.init_projects()

        self.project1 = ProjectFactory.create(amount_asked=5000)
        self.project1.set_status('campaign')

        self.project2 = ProjectFactory.create(amount_asked=3750)
        self.project2.set_status('campaign')

        self.manage_order_list_url = reverse('order-manage-list')
        self.manage_donation_list_url = reverse('manage-donation-list')

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.user2 = BlueBottleUserFactory.create(is_co_financer=True)
        self.user2_token = "JWT {0}".format(self.user2.get_jwt_token())

        self.project = ProjectFactory.create()
        self.order = OrderFactory.create(user=self.user)

        self.dollar_project = ProjectFactory.create(currencies=['USD'])
        self.multi_project = ProjectFactory.create(
            currencies=['EUR', 'USD', 'NGN'])
Пример #6
0
    def setUp(self):
        super(TestMultiTenant, self).setUp()

        now = timezone.now()

        self.init_projects()
        self.tenant1 = connection.tenant

        # Create a project for the main tenant
        self.project = ProjectFactory.create(
            status=ProjectPhase.objects.get(slug='campaign'),
            deadline=now - timezone.timedelta(days=5),
            campaign_started=now - timezone.timedelta(days=5),
            organization=None,
            amount_asked=0)

        # Create a second tenant
        self.tenant2 = get_tenant_model().objects.get(schema_name='test2')
        connection.set_tenant(self.tenant2)

        self.init_projects()
        self.project2 = ProjectFactory.create(
            status=ProjectPhase.objects.get(slug='campaign'),
            deadline=now - timezone.timedelta(days=5),
            campaign_started=now - timezone.timedelta(days=5),
            organization=None,
            amount_asked=0)
Пример #7
0
    def setUp(self):
        super(TestProjectStatusUpdate, self).setUp()

        self.init_projects()

        now = timezone.now()

        self.incomplete = ProjectPhase.objects.get(slug="done-incomplete")
        self.complete = ProjectPhase.objects.get(slug="done-complete")
        self.campaign = ProjectPhase.objects.get(slug="campaign")
        self.closed = ProjectPhase.objects.get(slug="closed")

        some_days_ago = now - timezone.timedelta(days=15)
        self.expired_project = ProjectFactory.create(
            amount_asked=5000,
            campaign_started=some_days_ago,
            status=self.campaign)

        self.expired_project.deadline = timezone.now() - timedelta(days=1)

        self.running_project = ProjectFactory.create(
            amount_asked=5000,
            campaign_started=some_days_ago,
            status=self.campaign)

        self.running_project.deadline = timezone.now() + timedelta(days=1)
Пример #8
0
    def setUp(self):
        super(TestMultiTenant, self).setUp()

        now = timezone.now()

        self.init_projects()
        self.tenant1 = connection.tenant
        status_running = ProjectPhase.objects.get(slug='campaign')

        # Create a project for the main tenant
        self.project = ProjectFactory.create(status=ProjectPhase.objects.get(slug='campaign'),
                                             deadline=now - timezone.timedelta(days=5),
                                             amount_asked=0)

        # Create a second tenant
        connection.set_schema_to_public()
        tenant_domain = 'testserver2'
        self.tenant2 = get_tenant_model()(
            domain_url=tenant_domain,
            schema_name='test2',
            client_name='test2')

        self.tenant2.save(verbosity=0)
        connection.set_tenant(self.tenant2)

        self.init_projects()
        self.project2 = ProjectFactory.create(status=ProjectPhase.objects.get(slug='campaign'),
                                              deadline=now - timezone.timedelta(days=5),
                                              amount_asked=0)
Пример #9
0
    def setUp(self):
        super(PayoutBaseTestCase, self).setUp()

        self.init_projects()

        # Set up a project ready for payout
        self.organization = OrganizationFactory.create()
        self.organization.save()
        self.project = ProjectFactory.create(organization=self.organization, amount_asked=50)
        self.project_incomplete = ProjectFactory.create(organization=self.organization, amount_asked=100)

        # Update phase to campaign.
        self.project.status = ProjectPhase.objects.get(slug='campaign')
        self.project.save()

        self.project_incomplete.status = ProjectPhase.objects.get(slug='campaign')
        self.project_incomplete.save()

        self.order = OrderFactory.create()

        self.donation = DonationFactory.create(
            project=self.project,
            order=self.order,
            amount=60
        )
        self.donation.save()

        self.donation2 = DonationFactory.create(
            project=self.project_incomplete,
            order=self.order,
            amount=60
        )
        self.donation2.save()
Пример #10
0
    def setUp(self):
        super(ProjectEndpointTestCase, self).setUp()

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.init_projects()

        self.phase_1 = ProjectPhase.objects.get(slug='plan-new')
        self.phase_2 = ProjectPhase.objects.get(slug='plan-submitted')
        self.phase_3 = ProjectPhase.objects.get(slug='campaign')

        self.theme_1 = ProjectTheme.objects.get(translations__name='Education')
        self.theme_2 = ProjectTheme.objects.get(translations__name='Climate')
        self.theme_3 = ProjectTheme.objects.get(translations__name='Health')

        self.project_1 = ProjectFactory.create(owner=self.user,
                                               status=self.phase_1,
                                               theme=self.theme_1)
        self.project_2 = ProjectFactory.create(owner=self.user,
                                               status=self.phase_2,
                                               theme=self.theme_2)
        self.project_3 = ProjectFactory.create(owner=self.user,
                                               status=self.phase_3,
                                               theme=self.theme_3)
Пример #11
0
    def setUp(self):
        super(MonthlyDonationApiTest, self).setUp()
        self.init_projects()

        self.phase_campaign = ProjectPhase.objects.get(slug='campaign')
        self.country = CountryFactory()

        self.some_project = ProjectFactory.create(amount_asked=500,
                                                  status=self.phase_campaign)
        self.another_project = ProjectFactory.create(
            amount_asked=750, status=self.phase_campaign)

        self.some_user = BlueBottleUserFactory.create()
        self.some_user_token = "JWT {0}".format(self.some_user.get_jwt_token())
        self.another_user = BlueBottleUserFactory.create()
        self.another_user_token = "JWT {0}".format(
            self.another_user.get_jwt_token())

        self.monthly_donation_url = reverse('monthly-donation-list')
        self.monthly_donation_project_url = reverse(
            'monthly-donation-project-list')

        self.monthly_profile = {
            'iban': 'NL13TEST0123456789',
            'bic': 'TESTNL2A',
            'name': 'Nijntje het Konijntje',
            'city': 'Amsterdam',
            'country': self.country.id,
            'amount': 50.00
        }
Пример #12
0
    def setUp(self):
        settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore()
        store.save()
        self.session = store
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key

        self.addCleanup(self._clear_session)

        self.user1 = BlueBottleUserFactory.create()
        self.user1_token = "JWT {0}".format(self.user1.get_jwt_token())

        self.init_projects()
        self.project1 = ProjectFactory.create(amount_asked=5000)
        self.project1.set_status('campaign')

        self.project2 = ProjectFactory.create(amount_asked=3750)
        self.project2.set_status('campaign')

        self.manage_order_list_url = reverse('manage-order-list')
        self.manage_donation_list_url = reverse('manage-donation-list')

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.user2 = BlueBottleUserFactory.create()
        self.user2_token = "JWT {0}".format(self.user2.get_jwt_token())

        self.project = ProjectFactory.create()
        self.order = OrderFactory.create(user=self.user)
Пример #13
0
 def test_plan_new(self):
     """ plan_new shouldn't be visible """
     ProjectFactory.create(title="plan-new project", slug="plan-new",
                           is_campaign=True,
                           language=self.en,
                           status=self.phases['plan-new'])
     self.assertEquals(HomePage().get('en').projects, None)
Пример #14
0
    def setUp(self):
        super(ManageProjectListRoleTests, self).setUp()

        self.init_projects()

        campaign = ProjectPhase.objects.get(slug='campaign')

        self.other_user = BlueBottleUserFactory.create()
        self.other_token = "JWT {0}".format(self.other_user.get_jwt_token())

        self.some_user = BlueBottleUserFactory.create()
        self.some_token = "JWT {0}".format(self.some_user.get_jwt_token())

        self.another_user = BlueBottleUserFactory.create()
        self.another_token = "JWT {0}".format(
            self.another_user.get_jwt_token())

        self.project1 = ProjectFactory.create(owner=self.some_user,
                                              status=campaign)

        self.project2 = ProjectFactory.create(owner=self.some_user,
                                              task_manager=self.other_user,
                                              status=campaign)

        self.project3 = ProjectFactory.create(owner=self.another_user,
                                              task_manager=self.another_user,
                                              promoter=self.other_user,
                                              status=campaign)
Пример #15
0
    def setUp(self):
        super(MonthlyDonationApiTest, self).setUp()
        self.init_projects()

        self.phase_campaign = ProjectPhase.objects.get(slug='campaign')
        self.country = CountryFactory()

        self.some_project = ProjectFactory.create(amount_asked=500,
                                                  status=self.phase_campaign)
        self.another_project = ProjectFactory.create(amount_asked=750,
                                                     status=self.phase_campaign)

        self.some_user = BlueBottleUserFactory.create()
        self.some_user_token = "JWT {0}".format(self.some_user.get_jwt_token())
        self.another_user = BlueBottleUserFactory.create()
        self.another_user_token = "JWT {0}".format(
            self.another_user.get_jwt_token())

        self.monthly_donation_url = reverse('monthly-donation-list')
        self.monthly_donation_project_url = reverse('monthly-donation-project-list')

        self.monthly_profile = {'iban': 'NL13TEST0123456789',
                                'bic': 'TESTNL2A',
                                'name': 'Nijntje het Konijntje',
                                'city': 'Amsterdam',
                                'country': self.country.id,
                                'amount': 50.00}
Пример #16
0
 def test_not_campaign(self):
     """ if it's not a campaign, don't show """
     ProjectFactory.create(title="done-complete project",
                           is_campaign=False,
                           slug="done-complete",
                           language=self.en,
                           status=self.phases['done-complete'])
     self.assertEquals(HomePage().get('en').projects, None)
Пример #17
0
 def test_plan_needs_work(self):
     """ plan_needs_work shouldn't be visible """
     ProjectFactory.create(title="plan-needs-work project",
                           is_campaign=True,
                           slug="plan-needs-work",
                           language=self.en,
                           status=self.phases['plan-needs-work'])
     self.assertEquals(len(HomePage().get('en').projects), 0)
Пример #18
0
 def test_closed(self):
     """ done_incomplete shouldn't be visible """
     ProjectFactory.create(title="closed project",
                           is_campaign=True,
                           slug="closed",
                           language=self.en,
                           status=self.phases['closed'])
     self.assertEquals(len(HomePage().get('en').projects), 0)
Пример #19
0
 def test_not_campaign(self):
     """ if it's not a campaign, don't show """
     ProjectFactory.create(title="done-complete project",
                           is_campaign=False,
                           slug="done-complete",
                           language=self.en,
                           status=self.phases['done-complete'])
     self.assertEquals(len(HomePage().get('en').projects), 0)
Пример #20
0
 def test_closed(self):
     """ done_incomplete shouldn't be visible """
     ProjectFactory.create(title="closed project",
                           is_campaign=True,
                           slug="closed",
                           language=self.en,
                           status=self.phases['closed'])
     self.assertEquals(HomePage().get('en').projects, None)
Пример #21
0
    def test_tags_translated(self, queue_mock):
        ProjectFactory.create(theme=self.theme, status=self.status,
                              country=self.country)

        # Simple translation added via fake_trans method above
        self.expected_tags['theme'] = 'Cleaning the park'
        args, kwargs = queue_mock.call_args
        self.assertEqual(kwargs['tags'], self.expected_tags)
Пример #22
0
    def setUp(self):
        super(HomepageEndpointTestCase, self).setUp()
        self.init_projects()

        self.stats = Statistics()

        """
        Create 10 Project instances for one user with half in the campaign phase
        and the other half in the done-complete phase
        This will create:
            - 10 running or realised projects
            - 10 campaigners (eg 10 new people involved)
        """
        self.user1 = BlueBottleUserFactory.create()
        self.campaign_phase = ProjectPhase.objects.get(slug='campaign')
        self.plan_phase = ProjectPhase.objects.get(slug='done-complete')
        projects = []

        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.campaign_phase)
            else:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.plan_phase)

            projects.append(project)

        """
        Create 10 TaskMember instances for one project.
        This will create:
            - 1 realised task
            - 1 task owner (eg 1 new person involved)
            - 10 task members (eg 10 new people involved)
        """
        self.task = TaskFactory.create(project=projects[0], status=Task.TaskStatuses.realized)
        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                task = TaskMemberFactory.create(task=self.task)
            else:
                task = TaskMemberFactory.create(task=self.task)

        """
        Create 10 Donations with half to fundraisers
        This will create:
            - 10 donations of 1000 (total amount of 10000)
            - 10 donators (eg 10 new people involved)
            - 5 fundraisers (eg 5 new people involved)
        """
        for char in 'abcdefghij':
            if ord(char) % 2 == 1:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order, fundraiser=None)
            else:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order)
Пример #23
0
    def test_bulk_status_change(self, queue_mock):
        for i in range(10):
            ProjectFactory.create(theme=self.theme, country=self.country)

        previous_call_count = queue_mock.call_count
        Project.objects.update(status=self.status)

        self.assertEqual(queue_mock.call_count,
                         previous_call_count + len(Project.objects.all()),
                         'Analytics should be sent when update is called')
Пример #24
0
    def test_location_country_tag(self, queue_mock):
        location = LocationFactory.create()
        ProjectFactory.create(theme=self.theme, status=self.status,
                              location=location, country=None)

        self.expected_tags['country'] = location.country.name
        self.expected_tags['location'] = location.name
        self.expected_tags['location_group'] = location.group.name
        args, kwargs = queue_mock.call_args
        self.assertEqual(kwargs['tags'], self.expected_tags)
Пример #25
0
    def setUp(self):
        super(FundraiserAPITestCase, self).setUp()
        self.some_user = BlueBottleUserFactory.create()
        self.some_token = "JWT {0}".format(self.some_user.get_jwt_token())

        self.some_other_user = BlueBottleUserFactory.create()
        self.some__other_token = "JWT {0}".format(self.some_other_user.get_jwt_token())

        self.some_project = ProjectFactory.create(owner=self.some_user, deadline=timezone.now() + timezone.timedelta(days=15))
        self.some_other_project = ProjectFactory.create(owner=self.some_user, deadline=timezone.now() + timezone.timedelta(days=15))
Пример #26
0
    def setUp(self):
        super(ProjectReviewerFilterTest, self).setUp()
        self.init_projects()

        self.user = BlueBottleUserFactory.create()
        self.project_with_reviewer = ProjectFactory.create(reviewer=self.user)
        self.project = ProjectFactory.create()

        self.request = factory.get('/')
        self.request.user = self.user
        self.admin = ProjectAdmin(Project, AdminSite())
Пример #27
0
    def setUp(self):
        super(ProjectVotesAPITestCase, self).setUp()

        self.init_projects()

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.project1 = ProjectFactory.create(owner=self.user)
        self.project2 = ProjectFactory.create(owner=self.user)
        self.vote_url = reverse('vote_list')
Пример #28
0
    def setUp(self):
        super(SupporterCountTest, self).setUp()

        # Required by Project model save method
        self.init_projects()

        self.some_project = ProjectFactory.create(amount_asked=5000)
        self.another_project = ProjectFactory.create(amount_asked=5000)

        self.some_user = BlueBottleUserFactory.create()
        self.another_user = BlueBottleUserFactory.create()
Пример #29
0
    def test_calculate_project_count(self):
        """ Test the counter for the number of projects a user has started """
        self.assertEqual(self.user.project_count, 0)

        project = ProjectFactory.create(owner=self.user)

        self.assertEqual(self.user.project_count, 1)

        project2 = ProjectFactory.create(owner=self.user)

        self.assertEqual(self.user.project_count, 2)
Пример #30
0
    def setUp(self):
        super(SupporterCountTest, self).setUp()

        # Required by Project model save method
        self.init_projects()

        self.some_project = ProjectFactory.create(amount_asked=5000)
        self.another_project = ProjectFactory.create(amount_asked=5000)

        self.some_user = BlueBottleUserFactory.create()
        self.another_user = BlueBottleUserFactory.create()
Пример #31
0
    def setUp(self):
        super(TestPayoutProjectApi, self).setUp()
        self.init_projects()
        complete = ProjectPhase.objects.get(slug='done-complete')
        incomplete = ProjectPhase.objects.get(slug='done-incomplete')
        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())
        financial = Group.objects.get(name='Financial')
        financial.user_set.add(self.user)

        self.project1 = ProjectFactory.create(campaign_ended=now(), status=complete)
        self.project2 = ProjectFactory.create(campaign_ended=now(), status=incomplete)
Пример #32
0
    def test_bulk_status_change(self, queue_mock):
        for i in range(10):
            ProjectFactory.create(theme=self.theme, country=self.country)

        previous_call_count = queue_mock.call_count
        Project.objects.update(status=self.status)

        self.assertEqual(queue_mock.call_count, previous_call_count + len(Project.objects.all()),
                         'Analytics should be sent when update is called')

        args, kwargs = queue_mock.call_args
        self.assertEqual(kwargs['tags'], self.expected_tags)
Пример #33
0
    def setUp(self):
        super(TestDonationEmails, self).setUp()
        self.init_projects()

        self.user = BlueBottleUserFactory.create(first_name='user')

        self.project_owner = BlueBottleUserFactory.create(
            first_name='projectowner')
        campaign_status = ProjectPhase.objects.get(slug='campaign')
        self.some_project = ProjectFactory.create(owner=self.project_owner,
                                                  status=campaign_status)

        self.order = OrderFactory.create(
            user=self.user,
        )

        self.recurring_order = OrderFactory.create(
            user=self.user,
            order_type="recurring"
        )

        self.donation = DonationFactory.create(
            order=self.order,
            project=self.some_project,
            fundraiser=None
        )

        self.recurring_donation = DonationFactory.create(
            order=self.recurring_order,
            project=self.some_project,
            fundraiser=None
        )

        self.fund_order = OrderFactory.create(
            user=self.user,
        )

        self.fund_project = ProjectFactory.create(owner=self.project_owner,
                                                  status=campaign_status)

        self.fund_owner = BlueBottleUserFactory.create(first_name='fundraiser')

        self.fundraiser_project = FundraiserFactory.create(
            owner=self.fund_owner,
            project=self.fund_project,
        )

        self.fund_donation = DonationFactory.create(
            order=self.fund_order,
            project=self.fund_project,
            fundraiser=self.fundraiser_project
        )
Пример #34
0
    def test_matched_stats(self):
        complete_status = ProjectPhase.objects.get(slug='done-complete')
        ProjectFactory.create(amount_asked=Money(1000, 'EUR'),
                              amount_extra=Money(100, 'EUR'),
                              owner=self.some_user,
                              status=complete_status)

        ProjectFactory.create(amount_asked=Money(1000, 'USD'),
                              amount_extra=Money(100, 'USD'),
                              owner=self.some_user,
                              status=complete_status)

        self.assertEqual(self.stats.amount_matched, Money(250, 'EUR'))
Пример #35
0
    def setUp(self):
        super(ProjectVotesAPITestCase, self).setUp()

        self.init_projects()

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        phase = ProjectPhase.objects.get(slug='voting')

        self.project1 = ProjectFactory.create(owner=self.user, status=phase)
        self.project2 = ProjectFactory.create(owner=self.user, status=phase)
        self.project3 = ProjectFactory.create(owner=self.user, status=phase)
        self.vote_url = reverse('vote_list')
Пример #36
0
    def setUp(self):
        super(ParticipationStatisticsTest, self).setUp()

        # Required by Project model save method
        self.init_projects()

        self.user_1 = BlueBottleUserFactory.create()
        self.user_2 = BlueBottleUserFactory.create()
        self.user_3 = BlueBottleUserFactory.create()

        self.location = LocationFactory.create()

        self.project_status_plan_new = ProjectPhase.objects.get(
            slug='plan-new')
        self.project_status_plan_submitted = ProjectPhase.objects.get(
            slug='plan-submitted')
        self.project_status_voting = ProjectPhase.objects.get(slug='voting')
        self.project_status_voting_done = ProjectPhase.objects.get(
            slug='voting-done')
        self.project_status_campaign = ProjectPhase.objects.get(
            slug='campaign')
        self.project_status_done_complete = ProjectPhase.objects.get(
            slug='done-complete')
        self.project_status_done_incomplete = ProjectPhase.objects.get(
            slug='done-incomplete')
        self.project_status_closed = ProjectPhase.objects.get(slug='closed')

        self.some_project = ProjectFactory.create(
            owner=self.user_1,
            status=self.project_status_done_complete,
            location=self.location)
        self.another_project = ProjectFactory.create(owner=self.user_2)

        self.some_task = TaskFactory.create(project=self.some_project,
                                            author=self.user_1)
        self.another_task = TaskFactory.create(project=self.another_project,
                                               author=self.user_2)

        self.some_task_member = TaskMemberFactory.create(member=self.user_1,
                                                         task=self.some_task)
        self.another_task_member = TaskMemberFactory.create(
            member=self.user_2, task=self.another_task)

        start = pendulum.create().subtract(days=7)
        end = pendulum.create().add(days=7)

        # TODO: Create atleast one project, task and task member outside the time range

        self.statistics = ParticipationStatistics(start=start, end=end)
Пример #37
0
    def test_less_than_20_done_stopped(self):
        """
        Test that a campaign with 20 euros or less and hits the deadline gets
        the status "Done-stopped"
        """
        now = timezone.now()

        some_project = ProjectFactory.create(title='test',
                                             amount_asked=500,
                                             campaign_started=now - timezone.
                                             timedelta(days=15),
                                             deadline=now - timezone.
                                             timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(
            project=some_project,
            order=order,
            amount=20
        )
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.succeeded()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised', 'test')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.closed)
Пример #38
0
    def test_tagging_multiple_models(self):
        """
        A smoke test to check that tagging is working how we want to use it.
        This is here because the Taggit tests don't all pass right now.
        """

        # Add the same tag to the 3 models we're currently tagging.
        tag_name = "Tag1"

        user = BlueBottleUserFactory.create()
        user.tags.add(tag_name)
        user.save()

        organization = OrganizationFactory.create()
        organization.save()

        organization.tags.add(tag_name)

        project = ProjectFactory.create()
        project.save()

        project.tags.add(tag_name)

        # Check that we only have one tag created.
        self.assertEquals(1, Tag.objects.count())

        # Check the tag name.
        tag = Tag.objects.all()[0]
        self.assertEquals(tag.name, tag_name)

        # Check that there are three objects tagged.
        num_tagged = len(tag.taggit_taggeditem_items.all())
        self.assertEquals(3, num_tagged)
Пример #39
0
    def test_fully_funded(self):
        """
        Test that a campaign that is fully funded
        and hits the deadline gets the status done-complete
        """
        now = timezone.now()

        some_project = ProjectFactory.create(title='test',
                                             amount_asked=500,
                                             campaign_started=now - timezone.
                                             timedelta(days=15),
                                             deadline=now - timezone.
                                             timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(
            project=some_project,
            order=order,
            amount=500
        )
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.succeeded()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised', 'test')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.complete)
Пример #40
0
    def setUp(self):
        super(TestDonationList, self).setUp()

        # Make user 1 a staff user
        self.user1.is_staff = True
        self.user1.save()

        # Create a target project/fundraiser
        self.project = ProjectFactory.create(amount_asked=5000, owner=self.user1)
        self.project.set_status('campaign')

        self.fundraiser = FundRaiserFactory.create(amount=4000, owner=self.user1, 
            project=self.project)

        # Two users make a donations
        order1 = OrderFactory.create(user=self.user1)
        self.donation1 = DonationFactory.create(amount=15, project=self.project, 
            fundraiser=self.fundraiser, order=order1)
        order1.locked()
        order1.succeeded()

        # Create the second without fundraiser
        order2 = OrderFactory.create(user=self.user2)
        self.donation2 = DonationFactory.create(amount=10, 
            project=self.project, fundraiser=None, order=order2)
        order2.locked()
        order2.succeeded()

        self.fundraiser_donation_list_url = reverse('fund-ticker-list')
Пример #41
0
    def test_suggestion_project_link(self):
        SuggestionFactory.create(title="Adoptable",
                                 destination="Amsterdam",
                                 status="accepted",
                                 project=None,
                                 token='x',
                                 org_name='Acme Inc.',
                                 org_email='*****@*****.**',
                                 org_website='http://example.com',
                                 org_phone='123123123',
                                 org_contactname='John Doe',
                                 pitch='Eat more cheese'
                                 )
        response = self.client.get(self.suggestion_list_url,
                      {'destination': "Amsterdam", status: "accepted"},
                      HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)[0]
        project = ProjectFactory.create(title="Adopting project")

        data['project'] = project.slug

        r = self.client.put(reverse('suggestion_detail',
                                    kwargs={'pk':data['id']}),
                            HTTP_AUTHORIZATION=self.user_1_token,
                            data=data)

        suggestion = Suggestion.objects.get(pk=data['id'])
        self.assertEquals(Project.objects.get(pk=project.pk), suggestion.project)
Пример #42
0
    def test_more_than_20_not_fully_funded(self):
        """
        Test that a campaign with more than 20 euros but is not fully funded,
        and hits the deadline gets the status done-incomplete
        """
        now = timezone.now()

        some_project = ProjectFactory.create(
            title='test',
            amount_asked=500,
            campaign_started=now - timezone.timedelta(days=15),
            deadline=now - timezone.timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(project=some_project,
                                          order=order,
                                          amount=21)
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.save()
        donation.order.success()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.incomplete)
Пример #43
0
    def test_supporters(self):
        """ Test return value of supporters, users who did a succesful donation """

        project = ProjectFactory.create(amount_asked=1000)
        user1 = BlueBottleUserFactory.create()
        user2 = BlueBottleUserFactory.create()
        user3 = BlueBottleUserFactory.create()

        order1 = OrderFactory.create(user=user1)
        donation1 = DonationFactory(order=order1, amount=20)
        order1.locked()
        order1.failed()

        order2 = OrderFactory.create(user=user2)
        donation2 = DonationFactory(order=order2, amount=25)
        order2.locked()
        order2.succeeded()

        order3 = OrderFactory.create(user=user2)
        donation3 = DonationFactory(order=order3, amount=30)
        order3.locked()
        order3.succeeded()

        order4 = OrderFactory.create(user=user3)
        donation4 = DonationFactory(order=order4, amount=35)
        order4.locked()
        order4.succeeded()

        # User two should be counted once, and user 3 should be counted
        self.assertEqual(self.metrics.calculate_supporters(), 2)
Пример #44
0
    def test_task_ignored_non_active_project(self):
        """
        Task that are connected to a project that hasn't started yet should be ignored.
        """
        now = timezone.now()
        project = ProjectFactory.create(status=ProjectPhase.objects.get(
            slug='plan-new'))

        task = TaskFactory.create(title='task1',
                                  people_needed=2,
                                  project=project,
                                  status='open',
                                  deadline=now - timezone.timedelta(days=5))

        TaskMemberFactory.create(task=task, status='accepted')
        self.assertEquals(len(mail.outbox), 1)

        call_command('cron_status_realised')

        # There should not be additional mails
        self.assertEquals(len(mail.outbox), 1)

        # Task should still be open
        task1 = Task.objects.get(title='task1')
        self.assertEquals(task1.status, 'open')
Пример #45
0
    def setUp(self):
        super(TestTaskSurveyAggregation, self).setUp()

        self.init_projects()

        self.project = ProjectFactory.create()
        self.task1 = TaskFactory.create(project=self.project)
        self.task2 = TaskFactory.create(project=self.project)
        self.task3 = TaskFactory.create(project=self.project)

        self.survey = SurveyFactory(title='test survey')

        self.project_response = ResponseFactory.create(
            project=self.project,
            survey=self.survey
        )

        self.task_response1 = ResponseFactory.create(
            project=self.project,
            task=self.task1,
            survey=self.survey
        )

        self.task_response2 = ResponseFactory.create(
            project=self.project,
            task=self.task2,
            survey=self.survey
        )

        self.task_response3 = ResponseFactory.create(
            project=self.project,
            task=self.task3,
            survey=self.survey
        )
Пример #46
0
    def setUp(self):
        super(TaskApiTestcase, self).setUp()

        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()
        self.some_token = "JWT {0}".format(self.some_user.get_jwt_token())

        campaign_status = ProjectPhase.objects.get(slug='campaign')
        self.some_project = ProjectFactory.create(owner=self.some_user,
                                                  status=campaign_status)

        self.task1 = TaskFactory.create(
            status=Task.TaskStatuses.open,
            author=self.some_project.owner,
            project=self.some_project,
            people_needed=2
        )

        self.another_user = BlueBottleUserFactory.create()
        self.another_token = "JWT {0}".format(self.another_user.get_jwt_token())

        self.yet_another_user = BlueBottleUserFactory.create()
        self.yet_another_token = "JWT {0}".format(
            self.yet_another_user.get_jwt_token())

        self.previews_url = reverse('project_preview_list')
        self.task_preview_url = reverse('task_preview_list')
        self.tasks_url = reverse('task_list')
        self.task_member_url = reverse('task_member_list')
Пример #47
0
    def setUp(self):
        super(TaskEmailTests, self).setUp()
        self.some_user = BlueBottleUserFactory.create(first_name='King')
        self.another_user = BlueBottleUserFactory.create(first_name='Kong')

        self.some_project = ProjectFactory.create()

        self.task = TaskFactory.create(
            status=TASK_MODEL.TaskStatuses.in_progress,
            author=self.some_project.owner,
        )

        self.taskmember1 = TaskMemberFactory.create(
            member=self.some_user,
            status=TASKS_MEMBER_MODEL.TaskMemberStatuses.applied,
            task=self.task

        )
        self.taskmember2 = TaskMemberFactory.create(
            member=self.another_user,
            status=TASKS_MEMBER_MODEL.TaskMemberStatuses.applied,
            task=self.task
        )

        self.task.save()
Пример #48
0
    def setUp(self):
        from bluebottle.bb_projects.models import ProjectPhase, ProjectTheme

        super(WallpostMailTests, self).setUp()

        self.init_projects()

        self.user_a = self.create_user(email='*****@*****.**',
                                       first_name='aname ',
                                       last_name='alast',
                                       primary_language='fr')
        self.user_b = self.create_user(email='*****@*****.**',
                                       first_name='bname ',
                                       last_name='blast',
                                       primary_language='nl')
        self.user_c = self.create_user(email='*****@*****.**',
                                       first_name='cname ',
                                       last_name='clast',
                                       primary_language='en')

        #self.project = self.create_project(owner=self.user_a)

        self.theme_1 = ProjectTheme.objects.get(name='Education')
        self.phase_1 = ProjectPhase.objects.get(slug='campaign')

        self.project_1 = ProjectFactory.create(
            owner=self.user_a, status=self.phase_1, theme=self.theme_1)

        self.task_1 = TaskFactory(author=self.user_a, project=self.project_1)
Пример #49
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)
Пример #50
0
    def test_no_campaign_started_date(self):
        """
        Test that a campaign that never started gets the phase stopped.
        """
        now = timezone.now()

        some_project = ProjectFactory.create(title='test',
                                             amount_asked=500,
                                             deadline=now - timezone.
                                             timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(
            project=some_project,
            order=order,
            amount=20
        )
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.succeeded()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised', 'test')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.closed)
Пример #51
0
    def test_fully_funded_before_deadline(self):
        """
        Test that a campaign that is fully funded
        and hits the deadline gets the status done-complete
        """
        now = timezone.now()

        some_project = ProjectFactory.create(
            title='test',
            amount_asked=500,
            campaign_started=now - timezone.timedelta(days=15),
            deadline=now + timezone.timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(project=some_project,
                                          order=order,
                                          amount=500)
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.save()
        donation.order.success()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised')

        project = Project.objects.get(title='test')
        self.assertTrue(project.campaign_funded)
Пример #52
0
 def test_payout_status(self):
     request = self.request_factory.get('/')
     request.user = MockUser(['projects.approve_payout'])
     project = ProjectFactory.create(project_type='funding')
     self.assertIn(
         'payout_status',
         self.project_admin.get_fieldsets(request, project)[3][1]['fields'])
Пример #53
0
    def test_less_than_20_done_stopped(self):
        """
        Test that a campaign with 20 euros or less and hits the deadline gets
        the status "Done-stopped"
        """
        now = timezone.now()

        some_project = ProjectFactory.create(
            title='test',
            amount_asked=500,
            campaign_started=now - timezone.timedelta(days=15),
            deadline=now - timezone.timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(project=some_project,
                                          order=order,
                                          amount=20)
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.save()
        donation.order.success()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.closed)
Пример #54
0
    def test_status_overfunded_projects(self):
        """ Overfunded projects should have status 'done-complete' """
        project = ProjectFactory.create(title='test', amount_asked=100)
        project.status = ProjectPhase.objects.get(slug='campaign')
        project.save()

        order = OrderFactory.create()

        donation = DonationFactory.create(
            project=project,
            order=order,
            amount=110
        )

        donation.save()

        order.locked()
        order.succeeded()
        order.save()

        project = Project.objects.get(title='test')
        project.deadline = timezone.now() - timezone.timedelta(days=1)
        project.save()

        project = Project.objects.get(title='test')
        self.assertEqual(project.status,
                         ProjectPhase.objects.get(slug='done-complete'))
Пример #55
0
    def test_no_campaign_started_date(self):
        """
        Test that a campaign that never started gets the phase stopped.
        """
        now = timezone.now()

        some_project = ProjectFactory.create(title='test',
                                             amount_asked=500,
                                             deadline=now -
                                             timezone.timedelta(days=5))

        order = OrderFactory.create()

        donation = DonationFactory.create(project=some_project,
                                          order=order,
                                          amount=20)
        donation.save()

        # Set status of donation to paid
        donation.order.locked()
        donation.order.save()
        donation.order.success()
        donation.order.save()

        some_project.status = self.campaign
        some_project.save()

        call_command('cron_status_realised')

        project = Project.objects.get(title='test')
        self.assertEqual(project.status, self.closed)
Пример #56
0
    def test_status_overfunded_projects(self):
        """ Overfunded projects should have status 'done-complete' """
        project = ProjectFactory.create(title='test', amount_asked=100)
        project.status = ProjectPhase.objects.get(slug='campaign')
        project.save()

        order = OrderFactory.create()

        donation = DonationFactory.create(project=project,
                                          order=order,
                                          amount=110)

        donation.save()

        order.locked()
        order.save()
        order.success()
        order.save()

        project = Project.objects.get(title='test')
        project.deadline = timezone.now() - timezone.timedelta(days=1)
        project.save()

        project = Project.objects.get(title='test')
        self.assertEqual(project.status,
                         ProjectPhase.objects.get(slug='done-complete'))
Пример #57
0
    def setUp(self):
        super(TestRefund, self).setUp()

        self.init_projects()

        self.project = ProjectFactory.create(status=ProjectPhase.objects.get(
            slug='refunded'))

        self.order = OrderFactory.create()
        self.order_payment = OrderPaymentFactory.create(
            order=self.order,
            payment_method='docdataIdeal',
            integration_data={'default_pm': 'ideal'},
        )
        payment = DocdataPaymentFactory.create(
            order_payment=self.order_payment,
            payment_cluster_key='123-4',
            default_pm='ideal',
            total_gross_amount=100)

        DonationFactory.create(
            project=self.project,
            order=self.order,
            amount=Money(100, 'EUR'),
        )
        payment.status = 'authorized'
        payment.save()
        payment.status = 'settled'
        payment.save()

        self.project.refresh_from_db()
Пример #58
0
    def setUp(self):
        super(TaskEmailTests, self).setUp()
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create(first_name='King',
                                                      primary_language='fr')
        self.another_user = BlueBottleUserFactory.create(first_name='Kong',
                                                         primary_language='nl')

        self.yet_another_user = BlueBottleUserFactory.create(first_name='Gong',
                                                             primary_language='en')

        self.some_project = ProjectFactory.create()
        self.some_project.owner.primary_language = 'en'

        self.task = TaskFactory.create(
            status=Task.TaskStatuses.in_progress,
            author=self.some_project.owner,
        )

        self.taskmember1 = TaskMemberFactory.create(
            member=self.some_user,
            status=TaskMember.TaskMemberStatuses.applied,
            task=self.task

        )
        self.taskmember2 = TaskMemberFactory.create(
            member=self.another_user,
            status=TaskMember.TaskMemberStatuses.applied,
            task=self.task
        )

        self.task.save()
Пример #59
0
    def test_save_custom_fields(self):
        project = ProjectFactory.create(title='Test')
        CustomProjectFieldSettings.objects.create(name='Purpose')

        data = project.__dict__
        # Set some foreignkeys and money fields
        # TODO: There should be a more elegant solution for this.
        data['status'] = 1
        data['theme'] = 1
        data['owner'] = 1
        data['amount_extra_0'] = 100.0
        data['amount_extra_1'] = 'EUR'
        data['amount_needed_0'] = 100.0
        data['amount_needed_1'] = 'EUR'
        data['amount_asked_0'] = 100.0
        data['amount_asked_1'] = 'EUR'
        data['amount_donated_0'] = 0.0
        data['amount_donated_1'] = 'EUR'

        # Set the extra field
        data['purpose'] = 'Do good better'
        form = ProjectAdminForm(instance=project, data=data)
        self.assertEqual(form.errors, {})
        form.save()
        project.refresh_from_db()
        self.assertEqual(project.extra.get().value, 'Do good better')
Пример #60
0
    def setUp(self):
        super(TestDonationRewardStock, self).setUp()

        self.init_projects()

        self.user = BlueBottleUserFactory.create()
        self.user_token = "JWT {0}".format(self.user.get_jwt_token())

        self.project = ProjectFactory.create(amount_asked=5000)
        self.project.set_status('campaign')

        self.reward = RewardFactory(project=self.project, limit=1)

        self.donations_url = reverse('manage-donation-list')
        self.reward_url = reverse('reward-detail', args=(self.reward.pk, ))

        self.donor = BlueBottleUserFactory.create()
        self.donor_token = "JWT {0}".format(self.donor.get_jwt_token())

        self.order = OrderFactory.create(user=self.donor)

        self.donation_data = {
            'order': self.order.id,
            'reward': self.reward.id,
            'amount': {
                'amount': self.reward.amount.amount,
                'currency': str(self.reward.amount.currency)
            },
            'project': self.project.slug,
        }