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()
Esempio n. 2
0
class GroupFactory(DjangoModelFactory):
    class Meta:
        model = GroupModel

    @post_generation
    def members(self, created, members, **kwargs):
        if not created:
            return
        if members:
            for member in members:
                self.members.add(member)

    name = LazyAttribute(lambda x: faker.sentence(nb_words=4))
    description = LazyAttribute(lambda x: faker.name())
    public_description = LazyAttribute(lambda x: faker.sentence(nb_words=20))
Esempio n. 3
0
class StoreFactory(DjangoModelFactory):
    class Meta:
        model = StoreModel

    group = SubFactory(GroupFactory)
    name = LazyAttribute(lambda x: faker.sentence(nb_words=4))
    description = LazyAttribute(lambda x: faker.name())
Esempio n. 4
0
class GroupFactory(DjangoModelFactory):
    class Meta:
        model = GroupModel

    @post_generation
    def members(self, created, members, **kwargs):
        if not created:
            return
        if members:
            for member in members:
                GroupMembership.objects.create(group=self, user=member)

    name = LazyAttribute(lambda x: 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))
Esempio n. 5
0
 def test_applicant_replies_in_conversation(self):
     self.client.force_login(user=self.applicant)
     chat_message = faker.sentence()
     response = self.client.post('/api/messages/', {
         'conversation': self.conversation.id,
         'content': chat_message,
     })
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     notification = mail.outbox[0]
     self.assertEqual(notification.to[0], self.member.email)
     self.assertIn('New message in', notification.subject)
     self.assertIn(chat_message, notification.body)
Esempio n. 6
0
 def test_newcomer_replies_in_conversation(self):
     newcomer = UserFactory()
     self.group.groupmembership_set.create(user=newcomer)
     mail.outbox = []
     self.client.force_login(user=newcomer)
     chat_message = faker.sentence()
     response = self.client.post('/api/messages/', {
         'conversation': self.conversation.id,
         'content': chat_message,
     })
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     notification = mail.outbox[0]
     self.assertIn('New message in', notification.subject)
     self.assertIn(chat_message, notification.body)
Esempio n. 7
0
class GroupFactory(DjangoModelFactory):
    class Meta:
        model = GroupModel

    @post_generation
    def members(self, created, extracted, **kwargs):
        if created and extracted:
            for member in extracted:
                GroupMembership.objects.create(group=self,
                                               user=member,
                                               roles=[roles.GROUP_EDITOR])

    @post_generation
    def newcomers(self, created, extracted, **kwargs):
        if created and extracted:
            for member in extracted:
                GroupMembership.objects.create(group=self, 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))
Esempio n. 8
0
class FeedbackFactory(DjangoModelFactory):
    class Meta:
        model = FeedbackModel

    comment = LazyAttribute(lambda x: faker.sentence(nb_words=4))
    weight = LazyAttribute(lambda x: randint(0, 32))