Пример #1
0
    def test_sort_matching_office_location(self):
        self.owner.location = LocationFactory.create(position='10.0, 20.0')
        self.owner.save()

        first = AssignmentFactory.create(status='full')
        ApplicantFactory.create_batch(3, activity=first, status='accepted')

        second = AssignmentFactory.create(
            status='full',
            is_online=False,
            location=GeolocationFactory.create(position=Point(20.0, 10.0)))
        ApplicantFactory.create_batch(3, activity=second, status='accepted')

        third = AssignmentFactory.create(status='open')
        fourth = AssignmentFactory.create(
            status='open',
            is_online=False,
            location=GeolocationFactory.create(position=Point(21.0, 9.0)))
        fifth = AssignmentFactory.create(
            status='open',
            is_online=False,
            location=GeolocationFactory.create(position=Point(20.0, 10.0)))

        response = self.client.get(self.url + '?sort=popularity',
                                   user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 5)

        self.assertEqual(data['data'][0]['id'], str(fifth.pk))
        self.assertEqual(data['data'][1]['id'], str(fourth.pk))
        self.assertEqual(data['data'][2]['id'], str(third.pk))
        self.assertEqual(data['data'][3]['id'], str(second.pk))
        self.assertEqual(data['data'][4]['id'], str(first.pk))
Пример #2
0
    def test_put_location(self):
        location = LocationFactory.create()

        data = {
            'data': {
                'id': self.initiative.id,
                'type': 'initiatives',
                'relationships': {
                    'location': {
                        'data': {
                            'type': 'locations',
                            'id': location.pk
                        }
                    }
                }
            }
        }
        response = self.client.patch(self.url,
                                     json.dumps(data),
                                     content_type="application/vnd.api+json",
                                     HTTP_AUTHORIZATION="JWT {0}".format(
                                         self.owner.get_jwt_token()))

        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content)
        self.assertEqual(
            data['data']['relationships']['location']['data']['id'],
            str(location.pk))

        self.assertEqual(
            get_include(response, 'locations')['attributes']['name'],
            location.name)
Пример #3
0
    def setUp(self):
        super(TestVoteAnalytics, self).setUp()
        self.init_projects()

        self.location = LocationFactory.create()
        with patch('bluebottle.analytics.signals.queue_analytics_record') as mock_queue:
            self.user = BlueBottleUserFactory.create()
            self.project = ProjectFactory.create(location=self.location)
Пример #4
0
    def test_submit_contact_without_location_has_locations(self):
        LocationFactory.create_batch(5)
        self.initiative = InitiativeFactory.create(
            has_organization=False,
            owner=self.user,
            place=None,
            location=None,
            organization=None
        )

        self.assertEqual(
            self.initiative.status, ReviewStateMachine.draft.value
        )
        self.assertRaises(
            TransitionNotPossible,
            self.initiative.states.submit
        )
Пример #5
0
    def setUp(self):
        super(TestVoteAnalytics, self).setUp()
        self.init_projects()

        self.location = LocationFactory.create()
        with patch('bluebottle.analytics.utils.queue_analytics_record'):
            self.user = BlueBottleUserFactory.create()
            self.project = ProjectFactory.create(location=self.location)
Пример #6
0
    def setUp(self):
        super(LocationFilterTest, self).setUp()
        self.init_projects()

        amsterdam = LocationFactory.create(name='Amsterdam')
        rotterdam = LocationFactory.create(name='Rotterdam')
        durgerdam = LocationFactory.create(name='Durgerdam')
        self.locations = [amsterdam, rotterdam, durgerdam]

        self.user = BlueBottleUserFactory.create(location=amsterdam)
        self.amsterdam_project = ProjectFactory.create(
            title='Project in Amsterdam', location=amsterdam)
        ProjectFactory.create(title='Project in Rotterdam', location=rotterdam)
        ProjectFactory.create(title='Project in Durgerdam', location=durgerdam)
        self.admin = ProjectAdmin(Project, AdminSite())

        self.filter = LocationFilter(None, {'location': amsterdam.pk}, Project,
                                     self.admin)
Пример #7
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)
Пример #8
0
    def setUp(self):
        super(UsedCountryListTestCase, self).setUp()

        belgium = Country.objects.get(translations__name="Belgium")
        location_be = GeolocationFactory.create(country=belgium)

        bulgaria = Country.objects.get(translations__name="Bulgaria")
        location_bg = GeolocationFactory.create(country=bulgaria)

        germany = Country.objects.get(translations__name="Germany")
        location_de = GeolocationFactory.create(country=germany)

        turkey = Country.objects.get(translations__name="Turkey")
        location_tr = LocationFactory.create(country=turkey)
        LocationFactory.create(country=Country.objects.get(translations__name='France'))

        EventFactory.create(
            status='open',
            location=location_be
        )
        EventFactory.create(
            status='full',
            location=location_bg
        )

        AssignmentFactory.create(
            status='draft',
            location=location_de
        )

        EventFactory.create(
            status='submitted',
            location=location_de
        )
        initiative = InitiativeFactory.create(
            status='approved',
            location=location_tr
        )
        FundingFactory.create(
            initiative=initiative,
            status='open'
        )
Пример #9
0
 def test_location_country_tag(self, queue_mock):
     location = LocationFactory.create()
     project = ProjectFactory.create(theme=self.theme,
                                     status=self.status,
                                     location=location,
                                     country=None)
     self.expected_tags['id'] = project.id
     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)
Пример #10
0
    def test_user_created_location(self, authenticate_request):
        location = LocationFactory.create(name='Amsterdam', slug='AMS')
        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()

            self.assertEqual(authenticate_request.call_count, 1)
            self.assertTrue(created)

            user.refresh_from_db()

            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(user.location, location)
Пример #11
0
    def test_user_profile_location_update(self):
        """
        Test that updating your location sets your country
        """
        country = CountryFactory.create()
        location = LocationFactory.create(country=country)
        user_profile_url = "{0}{1}".format(self.user_private_profile_api_url, self.user_1.id)
        changes = {"location": location.id}

        # Profile should not be able to be updated by anonymous users.
        response = self.client.put(user_profile_url, changes, token=self.user_1_token)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(country.id, response.data["address"]["country"])
Пример #12
0
    def test_filter_location(self):
        location = LocationFactory.create()
        initiative = InitiativeFactory.create(status='approved',
                                              location=location)
        InitiativeFactory.create(status='approved')

        response = self.client.get(
            self.url + '?filter[location.id]={}'.format(location.pk),
            HTTP_AUTHORIZATION="JWT {0}".format(self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 1)
        self.assertEqual(data['data'][0]['id'], str(initiative.pk))
Пример #13
0
    def test_initiative_location(self):
        location = LocationFactory.create()
        initiative = InitiativeFactory.create(status='open', location=location)
        activity = EventFactory.create(status='open', initiative=initiative)
        EventFactory.create(status='open')

        response = self.client.get(
            self.url +
            '?filter[initiative_location.id]={}'.format(location.pk),
            user=self.owner)

        data = json.loads(response.content)
        self.assertEqual(data['meta']['pagination']['count'], 1)
        self.assertEqual(data['data'][0]['id'], str(activity.pk))
Пример #14
0
    def test_submit_contact_location_has_locations(self):
        locations = LocationFactory.create_batch(5)
        self.initiative = InitiativeFactory.create(
            has_organization=False,
            owner=self.user,
            place=None,
            location=locations[0],
            organization=None
        )

        self.initiative.states.submit()
        self.assertEqual(
            self.initiative.status, ReviewStateMachine.submitted.value
        )
Пример #15
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)
Пример #16
0
    def test_user_profile_location_update(self):
        """
        Test that updating your location sets your country
        """
        country = CountryFactory.create()
        location = LocationFactory.create(country=country)
        user_profile_url = reverse('manage-profile', kwargs={'pk': self.user_1.id})
        changes = {'location': location.id}

        # Profile should not be able to be updated by anonymous users.
        response = self.client.put(user_profile_url, changes,
                                   token=self.user_1_token)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(country.id, response.data['address']['country'])
Пример #17
0
    def test_search_location(self):
        location = LocationFactory.create(name='nameofoffice')
        first = InitiativeFactory.create(status='approved', location=location)

        second = InitiativeFactory.create(status='approved',
                                          title='nameofoffice')

        InitiativeFactory.create(status='approved')

        response = self.client.get(self.url + '?filter[search]=nameofoffice',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
        self.assertEqual(data['data'][0]['id'], str(second.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
Пример #18
0
    def test_sort_matching_combined(self):
        theme = ProjectThemeFactory.create()
        self.owner.favourite_themes.add(theme)

        skill = SkillFactory.create()
        self.owner.skills.add(skill)

        self.owner.location = LocationFactory.create(position='10.0, 20.0')
        self.owner.save()

        initiative = InitiativeFactory.create(theme=theme)

        first = EventFactory.create(status='open',
                                    initiative=initiative,
                                    is_online=False)
        second = AssignmentFactory.create(
            status='open',
            location=GeolocationFactory.create(position=Point(21.0, 9.0)),
            initiative=initiative,
            is_online=False)
        third = AssignmentFactory.create(
            status='open',
            location=GeolocationFactory.create(position=Point(21.0, 9.0)),
            initiative=initiative,
            expertise=skill,
            is_online=False)

        response = self.client.get(self.url + '?sort=popularity',
                                   user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 3)

        self.assertEqual(data['data'][0]['id'], str(third.pk))
        self.assertEqual(data['data'][1]['id'], str(second.pk))
        self.assertEqual(data['data'][2]['id'], str(first.pk))
Пример #19
0
    def test_location_sets_country(self):
        country = CountryFactory.create()
        location = LocationFactory.create(country=country)

        BlueBottleUserFactory.create(email='*****@*****.**',
                                     location=location)
Пример #20
0
    def test_location_sets_country(self):
        country = CountryFactory.create()
        location = LocationFactory.create(country=country)

        BlueBottleUserFactory.create(email='*****@*****.**', location=location)