コード例 #1
0
class AnswerFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Answer

    user = factory.SubFactory(UserFactory)
    target = factory.SubFactory(FragmentFactory)
    content = factory.LazyFunction(lambda: generate_random_string(length=512))
コード例 #2
0
class AvatarFactory(factory.django.DjangoModelFactory):
    # For special purposes: testing, etc.

    class Meta:
        model = Avatar
        django_get_or_create = [
            'user',
        ]

    user = factory.SubFactory(UserFactory)
    profile_image = factory.LazyFunction(lambda: SimpleUploadedFile(
        name=f'{ generate_random_string(length=16) }.jpg',
        content=b'\x00' * random.randint(1, 65536),
        content_type='image/jpeg'))
    display_name = factory.LazyFunction(
        lambda: generate_random_string(length=16))

    @factory.post_generation
    def introduce_message(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            self.introduce_message = extracted
        else:
            self.introduce_message = generate_random_string(length=64)
コード例 #3
0
class UserFactory(factory.django.DjangoModelFactory):
    # Avatar is created with user by signal

    class Meta:
        model = User

    username = factory.LazyFunction(lambda: generate_random_string(length=16))
コード例 #4
0
class ChatFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Chat

    user = factory.SubFactory(UserFactory)
    room = factory.SubFactory(RoomFactory)
    content = factory.LazyFunction(lambda: generate_random_string(length=64))
コード例 #5
0
    def introduce_message(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            self.introduce_message = extracted
        else:
            self.introduce_message = generate_random_string(length=64)
コード例 #6
0
class NotificationFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Notification

    @factory.post_generation
    def users(self, create, extracted, **kwargs):
        if not create:
            return

        if isinstance(extracted, User):
            self.users.add(extracted)
        elif isinstance(extracted, list):
            self.users.set(extracted)
        else:
            for _ in range(random.randint(1, 10)):
                self.users.add(UserFactory())

    title = factory.LazyFunction(lambda: generate_random_string(length=32))
    body = factory.LazyFunction(lambda: generate_random_string(length=96))
コード例 #7
0
class FragmentFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Fragment

    user = factory.SubFactory(UserFactory)
    title = factory.LazyFunction(lambda: generate_random_string(length=32))
    content = factory.LazyFunction(lambda: generate_random_string(length=1024))

    @factory.post_generation
    def tags(self, create, extracted, **kwargs):
        if not create:
            return

        if isinstance(extracted, Tag):
            self.tags.add(extracted)
        elif isinstance(extracted, list):
            self.tags.set(extracted)
        else:
            for _ in range(random.randint(1, 10)):
                self.tags.add(TagFactory())
コード例 #8
0
 def get_data(self, permission, action):
     return {
         'title':
         'TEST',
         'content':
         'TEST',
         'tags': [
             generate_random_string(length=32)
             for _ in range(random.randint(1, 6))
         ]
     }
コード例 #9
0
class CommentFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Comment

    user = factory.SubFactory(UserFactory)
    target = factory.LazyFunction(lambda: random.choice(
        get_factories_for_model(
            Commentable, search_modules=['core.factories'], abstract=True))())
    parent = factory.LazyAttribute(lambda o: random.choice(
        [None, *Comment.objects.filter(target=o.target)])
                                   if random.random() > 0.5 else None)
    content = factory.LazyFunction(lambda: generate_random_string(length=128))
コード例 #10
0
 async def test_chat_websocket_behavior_send_invalid_message_receive_error(
         self):
     # two communicator in a room
     room = RoomFactory()
     sender = self.get_communicator(room=room.pk)
     await sender.connect()
     receiver = self.get_communicator(room=room.pk)
     await receiver.connect()
     # send message
     await sender.send_json_to(
         data={'content': generate_random_string(length=65536)})
     # sender will receive error message
     response = await sender.receive_json_from(timeout=1)
     assert 'error' in response
     # others will get nothing
     assert await receiver.receive_nothing(timeout=1)
     # teardown
     await sender.disconnect()
     await receiver.disconnect()
コード例 #11
0
class TagFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Tag

    name = factory.LazyFunction(lambda: generate_random_string(length=16))
    is_official = factory.LazyFunction(lambda: random.choice([True, False]))
コード例 #12
0
class RoomFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Room

    name = factory.LazyFunction(lambda: generate_random_string(length=8))
    user = factory.SubFactory(UserFactory)
コード例 #13
0
 def get_data(self, permission, action):
     return {'name': generate_random_string(length=32), 'is_official': True}