def setUpBeforeMigration(self, apps):
     User = apps.get_model('users', 'User')
     Group = apps.get_model('groups', 'Group')
     GroupMembership = apps.get_model('groups', 'GroupMembership')
     Place = apps.get_model('places', 'Place')
     Activity = apps.get_model('activities', 'Activity')
     ActivityParticipant = apps.get_model('activities', 'ActivityParticipant')
     Feedback = apps.get_model('activities', 'Feedback')
     group = Group.objects.create(name=faker.name())
     place = Place.objects.create(name=faker.name(), group=group)
     activity1 = Activity.objects.create(place=place, date=to_range(timezone.now()), feedback_as_sum=False)
     activity2 = Activity.objects.create(place=place, date=to_range(timezone.now()), feedback_as_sum=False)
     user1 = User.objects.create()
     user2 = User.objects.create()
     user3 = User.objects.create()
     for user in [user1, user2, user3]:
         GroupMembership.objects.create(group=group, user=user)
         ActivityParticipant.objects.create(activity=activity1, user=user)
         ActivityParticipant.objects.create(activity=activity2, user=user)
     feedback1 = Feedback.objects.create(given_by=user1, about=activity1, weight=10)
     feedback2 = Feedback.objects.create(given_by=user2, about=activity1, weight=20)
     feedback3 = Feedback.objects.create(given_by=user3, about=activity1)  # no weight!
     for user in [user1, user2, user3]:
         # and an activity with no weight feedback at all
         Feedback.objects.create(given_by=user, about=activity2)
     self.activity1_id = activity1.id
     self.activity2_id = activity2.id
     self.feedback1_id = feedback1.id
     self.feedback2_id = feedback2.id
     self.feedback3_id = feedback3.id
Exemplo n.º 2
0
    def setUp(self):
        self.url = '/api/places/'

        # group with two members and one place
        self.member = UserFactory()
        self.member2 = UserFactory()
        self.group = GroupFactory(members=[self.member, self.member2])
        self.place = PlaceFactory(group=self.group)
        self.place_url = self.url + str(self.place.id) + '/'

        # not a member
        self.user = UserFactory()

        # another place for above group
        self.place_data = {
            'name': faker.name(),
            'description': faker.name(),
            'group': self.group.id,
            'address': faker.address(),
            'latitude': faker.latitude(),
            'longitude': faker.longitude()
        }

        # another group
        self.different_group = GroupFactory(members=[self.member2])
Exemplo n.º 3
0
    def setUpTestData(cls):
        cls.url = '/api/places/'

        # group with two members and one place
        cls.member = UserFactory()
        cls.member2 = UserFactory()
        cls.group = GroupFactory(members=[cls.member, cls.member2])
        cls.place = PlaceFactory(group=cls.group)
        cls.place_url = cls.url + str(cls.place.id) + '/'

        # not a member
        cls.user = UserFactory()

        # another place for above group
        cls.place_data = {
            'name': faker.name(),
            'description': faker.name(),
            'group': cls.group.id,
            'address': faker.address(),
            'latitude': faker.latitude(),
            'longitude': faker.longitude()
        }

        # another group
        cls.different_group = GroupFactory(members=[cls.member2])
    def setUpBeforeMigration(self, apps):
        User = apps.get_model('users', 'User')
        Group = apps.get_model('groups', 'Group')
        Place = apps.get_model('places', 'Place')
        PickupDateSeries = apps.get_model('places', 'PickupDateSeries')
        PickupDate = apps.get_model('places', 'PickupDate')
        Feedback = apps.get_model('places', 'Feedback')

        self.email = faker.email()
        self.now = datetime.datetime.now(tz=pytz.utc)
        self.date = faker.date_time_between(start_date='now',
                                            end_date='+24h',
                                            tzinfo=pytz.utc)
        self.group_name = 'Group ' + faker.name()
        self.place_name = 'Place ' + faker.name()

        user = User.objects.create(email=self.email, display_name='Peter')
        group = Group.objects.create(name=self.group_name)
        place = Place.objects.create(name=self.place_name, group=group)
        pickup_date_series = PickupDateSeries.objects.create(
            place=place, start_date=self.now)
        pickup_date = PickupDate.objects.create(series=pickup_date_series,
                                                place=place,
                                                date=self.date)
        pickup_date.collectors.add(user)
        Feedback.objects.create(given_by=user, about=pickup_date)
 def setUp(self):
     self.user = UserFactory()
     self.url = '/api/auth/user/'
     self.user_data = {
         'email': '*****@*****.**',
         'password': faker.name(),
         'display_name': faker.name()
     }
 def setUpBeforeMigration(self, apps):
     Group = apps.get_model('groups', 'Group')
     Place = apps.get_model('places', 'Place')
     PickupDate = apps.get_model('pickups', 'PickupDate')
     group = Group.objects.create(name=faker.name())
     place = Place.objects.create(name=faker.name(), group=group)
     pickup = PickupDate.objects.create(place=place, date=timezone.now())
     self.assertIsNone(pickup.date_range)
     self.pickup_id = pickup.id
 def setUpBeforeMigration(self, apps):
     Group = apps.get_model('groups', 'Group')
     Place = apps.get_model('places', 'Place')
     Activity = apps.get_model('activities', 'Activity')
     group = Group.objects.create(name=faker.name())
     place = Place.objects.create(name=faker.name(), group=group)
     activity = Activity.objects.create(place=place, date=timezone.now())
     self.assertIsNone(activity.date_range)
     self.activity_id = activity.id
Exemplo n.º 8
0
 def test_sign_up_with_rejected_address_fails(self):
     response = self.client.post(
         self.url_user, {
             'email': '*****@*****.**',
             'password': faker.name(),
             'display_name': faker.name()
         }
     )
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
    def setUpBeforeMigration(self, apps):
        Group = apps.get_model('groups', 'Group')
        Place = apps.get_model('places', 'Place')
        Activity = apps.get_model('activities', 'Activity')
        ActivitySeries = apps.get_model('activities', 'ActivitySeries')

        for theme in ['foodsaving', 'bikekitchen', 'general']:
            group = Group.objects.create(name=faker.name(), theme=theme)
            place = Place.objects.create(name=faker.name(), group=group)
            Activity.objects.create(place=place, date=to_range(timezone.now()))
            ActivitySeries.objects.create(place=place, start_date=timezone.now())
Exemplo n.º 10
0
 def setUp(self):
     self.user = UserFactory()
     self.url = '/api/auth/user/'
     self.user_data = {
         'email': faker.email(),
         'password': faker.name(),
         'display_name': faker.name(),
         'address': faker.address(),
         'latitude': faker.latitude(),
         'longitude': faker.longitude()
     }
     mail.outbox = []
Exemplo n.º 11
0
def generate_stats(n):
    return [{
        'ms': random.randint(1, 3000),
        'ms_resources': random.randint(1, 3000),
        'first_load': random.choice([True, False]),
        'logged_in': random.choice([True, False]),
        'mobile': random.choice([True, False]),
        'app': random.choice([True, False]),
        'browser': faker.name(),
        'os': faker.name(),
        'dev': random.choice([True, False]),
        'group': random.choice([random.randint(1, 100), None]),
        'route_name': faker.name(),
        'route_path': faker.name(),
    } for n in range(n)]
Exemplo n.º 12
0
    def test_unrelated_user_receives_no_changes(self):
        client = self.connect_as(self.unrelated_user)

        self.member.display_name = faker.name()
        self.member.save()

        self.assertEqual(len(client.messages), 0)
Exemplo n.º 13
0
    def setUpBeforeMigration(self, apps):
        logging.disable(logging.CRITICAL)
        self.email = faker.email()
        User = apps.get_model('users', 'User')
        History = apps.get_model('history', 'History')
        Group = apps.get_model('groups', 'Group')
        GroupMembership = apps.get_model('groups', 'GroupMembership')
        self.user = User.objects.create(email=self.email, display_name='Peter')
        self.group = Group.objects.create(
            name=faker.name(),
            description=faker.sentence(nb_words=40),
            public_description=faker.sentence(nb_words=20),
        )
        membership = GroupMembership.objects.create(group=self.group,
                                                    user=self.user)
        self.membership_id = membership.id
        self.history = History.objects.create(
            typus=HistoryTypus.GROUP_CREATE,
            group=self.group,
            payload={},
        )
        self.history.users.add(self.user)
        self.history.save()

        self.history.date = timezone.now() - relativedelta(days=100)
        self.history.save()

        self.user.created_at = timezone.now() - relativedelta(days=200)
        self.user.save()
Exemplo n.º 14
0
class GroupFactory(DjangoModelFactory):
    class Meta:
        model = GroupModel

    @post_generation
    def members(self, created, extracted, **kwargs):
        if created and extracted:
            for member in extracted:
                membership = self.groupmembership_set.create(
                    user=member, roles=[roles.GROUP_EDITOR])
                membership.add_notification_types(
                    [GroupNotificationType.NEW_APPLICATION])
                membership.save()

    @post_generation
    def newcomers(self, created, extracted, **kwargs):
        if created and extracted:
            for member in extracted:
                self.groupmembership_set.create(user=member)

    name = Sequence(lambda n: ' '.join(['Group', str(n), faker.name()]))
    description = LazyAttribute(lambda x: faker.sentence(nb_words=40))
    public_description = LazyAttribute(lambda x: faker.sentence(nb_words=20))
    application_questions = LazyAttribute(
        lambda x: faker.sentence(nb_words=20))
    welcome_message = LazyAttribute(lambda x: faker.sentence(nb_words=30))
Exemplo n.º 15
0
 def test_normal_member_cannot_create_agreement(self):
     self.client.force_login(user=self.normal_member)
     response = self.client.post('/api/agreements/', {
         'title': faker.name(),
         'content': faker.text(),
         'group': self.group.id
     })
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 16
0
 def test_update_offer_as_another_user(self):
     offer = OfferFactory(user=self.user, group=self.group, images=[image_path])
     self.client.force_login(user=self.another_user)
     data = {
         'name': faker.name(),
     }
     response = self.client.patch('/api/offers/{}/'.format(offer.id), data, format='json')
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.data)
Exemplo n.º 17
0
    def test_receive_offer_changes(self):
        client = self.connect_as(self.member)

        self.offer.name = faker.name()
        self.offer.save()
        response = client.messages_by_topic.get('offers:offer')[0]
        self.assertEqual(response['payload']['name'], self.offer.name)
        self.assertEqual(len(client.messages), 1)
Exemplo n.º 18
0
 def test_update_offer(self):
     self.client.force_login(user=self.user)
     data = {
         'name': faker.name(),
     }
     response = self.client.patch('/api/offers/{}/'.format(self.offer.id), data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
     self.assertEqual(response.data['name'], data['name'])
Exemplo n.º 19
0
 def setUp(self):
     self.user = UserFactory()
     self.user.photo = 'photo.jpg'
     self.user.save()
     self.user2 = UserFactory()
     self.url = '/api/users/'
     self.user_data = {
         'email': faker.email(),
         'password': faker.name(),
         'display_name': faker.name(),
         'address': faker.address(),
         'latitude': faker.latitude(),
         'longitude': faker.longitude()
     }
     self.group = GroupFactory(members=[self.user, self.user2])
     self.another_common_group = GroupFactory(members=[self.user, self.user2])
     self.user_in_another_group = UserFactory()
     self.another_group = GroupFactory(members=[self.user_in_another_group])
     mail.outbox = []
Exemplo n.º 20
0
 def modify_place(place):
     response = c.patch(
         '/api/places/{}/'.format(place), {
             'name': 'Place (edited) ' + faker.name(),
             'description': faker.text(),
         })
     if response.status_code != 200:
         raise Exception('could not modify place', place, response.data)
     print('modified place: ', place)
     return response.data
Exemplo n.º 21
0
    def test_receive_place_changes(self):
        client = self.connect_as(self.member)

        name = faker.name()
        self.place.name = name
        self.place.save()

        response = client.messages_by_topic.get('places:place')[0]
        self.assertEqual(response['payload']['name'], name)

        self.assertEqual(len(client.messages), 1)
Exemplo n.º 22
0
    def test_receive_group_changes_as_nonmember(self):
        client = self.connect_as(self.user)

        name = faker.name()
        self.group.name = name
        self.group.save()

        response = client.messages_by_topic.get('groups:group_preview')[0]
        self.assertEqual(response['payload']['name'], name)
        self.assertTrue('description' not in response['payload'])

        self.assertEqual(len(client.messages), 1)
Exemplo n.º 23
0
 def test_create_offer_without_image(self):
     self.client.force_login(user=self.user)
     data = {
         'name': faker.name(),
         'description': faker.text(),
         'group': self.group.id,
         'images': [],
     }
     response = self.client.post('/api/offers/',
                                 data=encode_data_with_images(data))
     self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                      response.data)
     self.assertEqual(response.data['name'], data['name'])
Exemplo n.º 24
0
 def make_user():
     response = c.post(
         '/api/auth/user/', {
             'email': str(timezone.now().microsecond) + faker.email(),
             'password': default_password,
             'display_name': faker.name(),
             'description': 'I am a fake user',
             'mobile_number': faker.phone_number()
         })
     if response.status_code != 201:
         raise Exception('could not make user', response.data)
     print('created user:'******'email'])
     return response.data
Exemplo n.º 25
0
    def setUpBeforeMigration(self, apps):
        Group = apps.get_model('groups', 'Group')
        Place = apps.get_model('places', 'Place')
        PickupDateSeries = apps.get_model('pickups', 'PickupDateSeries')
        PickupDate = apps.get_model('pickups', 'PickupDate')
        History = apps.get_model('history', 'History')

        # upcoming pickup is moved to a later date
        date1 = faker.date_time_between(start_date='+1h',
                                        end_date='+24h',
                                        tzinfo=pytz.utc)
        date2 = faker.date_time_between(start_date='+24h',
                                        end_date='+48h',
                                        tzinfo=pytz.utc)

        group = Group.objects.create(name=faker.name())
        place = Place.objects.create(name=faker.name(), group=group)
        pickup_date_series = PickupDateSeries.objects.create(
            place=place, start_date=timezone.now())
        pickup_date = PickupDate.objects.create(series=pickup_date_series,
                                                place=place,
                                                date=date2,
                                                is_date_changed=True)
        # PICKUP_MODIFY history entry
        History.objects.create(typus=8,
                               group=group,
                               before={
                                   'id': pickup_date.id,
                                   'is_date_changed': False,
                                   'date': date1.isoformat()
                               },
                               after={'is_date_changed': True})

        # past moved pickup
        PickupDate.objects.create(series=pickup_date_series,
                                  place=place,
                                  date=timezone.now() - relativedelta(days=1),
                                  is_date_changed=True)
Exemplo n.º 26
0
    def test_do_not_send_too_many_updates(self):
        [
            GroupFactory(members=[self.member, self.other_member])
            for _ in range(3)
        ]

        client = self.connect_as(self.member)

        name = faker.name()
        self.other_member.display_name = name
        self.other_member.save()

        self.assertEqual(len(client.messages), 1)
        self.assertIn('users:user', client.messages_by_topic.keys())
Exemplo n.º 27
0
class PlaceFactory(DjangoModelFactory):
    class Meta:
        model = PlaceModel

    group = SubFactory(GroupFactory)
    name = LazyAttribute(lambda x: faker.sentence(nb_words=4))
    description = LazyAttribute(lambda x: faker.name())
    status = 'active'

    @post_generation
    def subscribers(self, created, extracted, **kwargs):
        if created and extracted:
            for user in extracted:
                self.placesubscription_set.create(user=user)
Exemplo n.º 28
0
 def setUp(self):
     self.user = UserFactory()
     self.member = UserFactory()
     self.group = GroupFactory(members=[self.member,
                                        UserFactory()],
                               is_open=True)
     self.url = '/api/groups/'
     self.group_data = {
         'name': faker.name(),
         'description': faker.text(),
         'address': faker.address(),
         'latitude': faker.latitude(),
         'longitude': faker.longitude(),
         'timezone': 'Europe/Berlin'
     }
Exemplo n.º 29
0
class OfferFactory(DjangoModelFactory):
    class Meta:
        model = Offer

    group = SubFactory(GroupFactory)
    user = SubFactory(UserFactory)
    name = LazyAttribute(lambda x: faker.sentence(nb_words=4))
    description = LazyAttribute(lambda x: faker.name())
    status = 'active'

    @post_generation
    def images(self, created, extracted, **kwargs):
        if created and extracted:
            for index, image_path in enumerate(extracted):
                self.images.create(image=image_upload_for(image_path), position=index)
Exemplo n.º 30
0
    def test_receive_changes_of_other_user(self):
        client = self.connect_as(self.member)

        name = faker.name()
        self.other_member.display_name = name
        self.other_member.save()

        response = client.messages_by_topic.get('users:user')[0]
        self.assertEqual(response['payload']['display_name'], name)
        self.assertTrue('current_group' not in response['payload'])
        self.assertTrue(
            response['payload']['photo_urls']['full_size'].startswith(
                settings.HOSTNAME))

        self.assertEqual(len(client.messages), 1)