Example #1
0
 def setUp(self):
     super(CommentFormTests, self).setUp()
     self.c = get_user(username='******')
     self.u = get_user(username='******')
     # TODO: Create a valid diary entry in the test database
     self.d = forms.DiaryForm(creator=self.c, data={'text': DIARY_TEXT})
     self.d = self.d.save()
Example #2
0
 def setUp(self):
     super(ViewsTests, self).setUp()
     self.factory = RequestFactory()
     self.c = get_user('CTO')
     self.u = get_user('zinoma')
     self.f = forms.DiaryForm(creator=self.u, data={'text': 's' * 500})
     self.e = self.f.save()
Example #3
0
def image(file_and_save=True, **kwargs):
    """Return a saved image.

    Requires a users fixture if no creator is provided.

    """
    u = None
    if 'creator' not in kwargs:
        u = get_user()

    defaults = {
        'title': 'Some title',
        'description': 'Some description',
        'creator': u
    }
    defaults.update(kwargs)

    img = Image(**defaults)
    if not file_and_save:
        return img

    if 'file' not in kwargs:
        with open('apps/upload/tests/media/test.jpg') as f:
            up_file = File(f)
            img.file.save(up_file.name, up_file, save=True)

    return img
Example #4
0
def video(file_and_save=True, **kwargs):
    """Return a saved video.

    Requires a users fixture if no creator is provided.

    """
    u = None
    if 'creator' not in kwargs:
        u = get_user()

    defaults = {
        'title': 'Some title',
        'description': 'Some description',
        'creator': u
    }
    defaults.update(kwargs)

    vid = Video(**defaults)
    if not file_and_save:
        return vid

    if 'file' not in kwargs:
        with open('apps/gallery/tests/media/test.webm') as f:
            up_file = File(f)
            vid.webm.save(up_file.name, up_file, save=False)
        with open('apps/gallery/tests/media/test.ogv') as f:
            up_file = File(f)
            vid.ogv.save(up_file.name, up_file, save=False)
        with open('apps/gallery/tests/media/test.flv') as f:
            up_file = File(f)
            vid.flv.save(up_file.name, up_file, save=False)
        vid.save()

    return vid
Example #5
0
def video(file_and_save=True, **kwargs):
    """Return a saved video.

    Requires a users fixture if no creator is provided.

    """
    u = None
    if 'creator' not in kwargs:
        u = get_user()

    defaults = {'title': 'Some title', 'description': 'Some description',
                'creator': u}
    defaults.update(kwargs)

    vid = Video(**defaults)
    if not file_and_save:
        return vid

    if 'file' not in kwargs:
        with open('apps/gallery/tests/media/test.webm') as f:
            up_file = File(f)
            vid.webm.save(up_file.name, up_file, save=False)
        with open('apps/gallery/tests/media/test.ogv') as f:
            up_file = File(f)
            vid.ogv.save(up_file.name, up_file, save=False)
        with open('apps/gallery/tests/media/test.flv') as f:
            up_file = File(f)
            vid.flv.save(up_file.name, up_file, save=False)
        vid.save()

    return vid
Example #6
0
 def test_authenticated(self, unread_count_for):
     """Test authenticated user with flag active."""
     unread_count_for.return_value = 3
     rf = RequestFactory()
     request = rf.get('/')
     request.user = get_user('rrosario')
     eq_(3, unread_message_count(request)['unread_message_count'])
     assert unread_count_for.called
 def test_flag_off(self, flag_is_active, unread_count_for):
     """Test authenticated user with flag inactive."""
     unread_count_for.return_value = 3
     flag_is_active.return_value = False
     rf = RequestFactory()
     request = rf.get('/')
     request.user = get_user('rrosario')
     eq_(0, unread_message_count(request)['unread_message_count'])
     assert not unread_count_for.called
Example #8
0
    def test_send_message(self):
        to = [get_user('jsocol'), get_user('pcraciunoiu')]
        sender = get_user('rrosario')
        msg_text = "hi there!"
        send_message(to=to, text=msg_text, sender=sender)

        msgs_in = InboxMessage.objects.all()
        msgs_out = OutboxMessage.objects.all()
        eq_(1, msgs_out.count())
        msg_out = msgs_out[0]
        eq_(sender, msg_out.sender)
        eq_(msg_text, msg_out.message)
        for user in msg_out.to.all():
            assert user in to
        eq_(2, msgs_in.count())
        for message in msgs_in:
            eq_(sender, message.sender)
            assert message.to in to
            eq_(msg_text, message.message)
Example #9
0
def revision(**kwargs):
    """Return an empty revision with enough stuff filled out that it can be
    saved.

    Revision's is_approved=False unless you specify otherwise.

    Requires a users fixture if no creator is provided.

    """
    d = kwargs.pop('document', None) or document(save=True)

    defaults = {'summary': 'đSome summary', 'content': u'đSome content',
                'significance': SIGNIFICANCES[0][0], 'comment': 'đSome comment',
                'creator': kwargs.get('creator', get_user()), 'document': d}
    defaults.update(kwargs)

    return Revision(**defaults)
Example #10
0
def revision(**kwargs):
    """Return an empty revision with enough stuff filled out that it can be
    saved.

    Revision's is_approved=False unless you specify otherwise.

    Requires a users fixture if no creator is provided.

    """
    d = kwargs.pop('document', None) or document(save=True)

    defaults = {'summary': 'Some summary', 'content': 'Some content',
                'significance': SIGNIFICANCES[0][0], 'comment': 'Some comment',
                'creator': kwargs.get('creator', get_user()), 'document': d}
    defaults.update(kwargs)

    return Revision(**defaults)
Example #11
0
    def setUp(self):
        super(DeleteDraftsCronTests, self).setUp()
        self.c = get_user(username='******')
        grace_days = (datetime.now() -
                      timedelta(days=settings.DIARY_GRACE_DAYS + 1))

        self.draft = DiaryEntry(creator=self.c, created=grace_days,
                               is_draft=True)
        self.draft.save()
        self.draft_pk = self.draft.pk
        draft_pic = DiaryPicture(entry=self.draft)
        draft_pic2 = DiaryPicture(entry=self.draft)

        self.entry = DiaryEntry(creator=self.c, is_draft=False)
        self.entry.save()
        self.entry_pk = self.entry.pk
        entry_pic = DiaryPicture(entry=self.entry)
        entry_pic2 = DiaryPicture(entry=self.entry)

        with open('apps/diary/tests/media/django.jpg') as f:
            img = File(f)
            draft_pic.image.save('cowboy', img, save=False)
            draft_pic.thumbnail.save('cowboy', img, save=False)

            entry_pic.image.save('cowboy_new', img, save=False)
            entry_pic.thumbnail.save('cowboy_new', img, save=False)

            draft_pic.save()
            entry_pic.save()

        with open('apps/diary/tests/media/hawk.jpg') as f:
            img = File(f)
            draft_pic2.image.save('hawk', img, save=False)
            draft_pic2.thumbnail.save('hawk', img, save=False)

            entry_pic2.image.save('hawk_new', img, save=False)
            entry_pic2.thumbnail.save('hawk_new', img, save=False)

            draft_pic2.save()
            entry_pic2.save()
Example #12
0
def image(file_and_save=True, **kwargs):
    """Return a saved image.

    Requires a users fixture if no creator is provided.

    """
    u = None
    if 'creator' not in kwargs:
        u = get_user()

    defaults = {'title': 'Some title', 'description': 'Some description',
                'creator': u}
    defaults.update(kwargs)

    img = Image(**defaults)
    if not file_and_save:
        return img

    if 'file' not in kwargs:
        with open('apps/upload/tests/media/test.jpg') as f:
            up_file = File(f)
            img.file.save(up_file.name, up_file, save=True)

    return img
Example #13
0
 def setUp(self):
     super(LetsFormTests, self).setUp()
     self.c = get_user(username='******')
Example #14
0
 def setUp(self):
     super(ViewsTests, self).setUp()
     self.factory = RequestFactory()
     self.u = get_user('ccarlos')
     self.c = get_user('CTO')