Beispiel #1
0
    def test_filter_country(self):
        country1 = CountryFactory.create()
        country2 = CountryFactory.create()

        initiative1 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative2 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))
        initiative3 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative4 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))

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

        second = AssignmentFactory.create(status='open',
                                          initiative=initiative3)

        third = AssignmentFactory.create(status='full', initiative=initiative2)
        ApplicantFactory.create_batch(3, activity=third, status='accepted')

        AssignmentFactory.create(status='open', initiative=initiative4)

        response = self.client.get(
            self.url +
            '?sort=popularity&filter[country]={}'.format(country1.id),
            user=self.owner)

        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))
Beispiel #2
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))
Beispiel #3
0
 def test_create_with_location(self):
     geolocation = GeolocationFactory.create(
         position=Point(23.6851594, 43.0579025))
     data = {
         'data': {
             'type': 'initiatives',
             'attributes': {
                 'title': 'Some title'
             },
             'relationships': {
                 'place': {
                     'data': {
                         'type': 'geolocations',
                         'id': geolocation.id
                     },
                 }
             }
         }
     }
     response = self.client.post(self.url,
                                 json.dumps(data),
                                 user=self.owner)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     geolocation = get_include(response, 'geolocations')
     self.assertEqual(geolocation['attributes']['position'], {
         'latitude': 43.0579025,
         'longitude': 23.6851594
     })
Beispiel #4
0
    def test_date_changed(self):
        event = EventFactory(
            title='Test Title',
            status='open',
            location=GeolocationFactory.create(position=Point(20.0, 10.0)),
            start=now() + timedelta(days=4),
        )

        ParticipantFactory.create_batch(3, activity=event, status='new')
        ParticipantFactory.create(activity=event, status='withdrawn')

        mail.outbox = []

        event.start = event.start + timedelta(days=1)
        event.save()

        recipients = [message.to[0] for message in mail.outbox]

        self.assertTrue(
            event.local_timezone_name in mail.outbox[0].body
        )

        self.assertTrue(
            formats.time_format(event.local_start) in mail.outbox[0].body
        )

        for participant in event.contributions.instance_of(Participant):
            if participant.status == 'new':
                self.assertTrue(participant.user.email in recipients)
            else:
                self.assertFalse(participant.user.email in recipients)
    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'
        )
Beispiel #6
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))
Beispiel #7
0
    def test_search_formatted_address(self):
        location = GeolocationFactory.create(
            formatted_address='Roggeveenstraat')
        first = EventFactory.create(location=location, status='open')
        second = EventFactory.create(title='Roggeveenstraat', status='open')
        EventFactory.create(status='open')

        response = self.client.get(self.url +
                                   '?filter[search]=Roggeveenstraat',
                                   user=self.owner)

        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))
Beispiel #8
0
    def setUp(self):
        super(InitiativeDetailAPITestCase, self).setUp()
        self.initiative = InitiativeFactory(
            owner=self.owner,
            place=GeolocationFactory(position=Point(23.6851594, 43.0579025)))
        self.initiative.states.submit(save=True)
        self.url = reverse('initiative-detail', args=(self.initiative.pk, ))

        self.data = {
            'data': {
                'id': self.initiative.id,
                'type': 'initiatives',
                'attributes': {
                    'title': 'Some title'
                }
            }
        }