Пример #1
0
    def test_saving_validates_name(self):
        """
        Creates shakes with valid and invalid names
        """
        valid_names = [
            'a-b-c', 'qwerty', '1234', '2a93sfj', 'asdfgasdfgasdfgasdfgasdfg'
        ]
        invalid_names = [
            '',
            None,
            'a x',
            'AsDf',
            'static',  #asdf exists in the setup, static is reserved
            'asdfgasdfgasdfgasdfgasdfgx'
        ]  #too long

        for name in valid_names:
            self.assertTrue(
                Shake(user_id=self.user.id,
                      title="some text",
                      name=name,
                      type='group').save())
        for name in invalid_names:
            self.assertFalse(
                Shake(user_id=self.user.id,
                      title="some text",
                      name=name,
                      type='group').save())
Пример #2
0
    def post(self):
        name = self.get_argument("name", '')
        description = self.get_argument("description", '')
        title = self.get_argument("title", '')
        user_object = self.get_current_user_object()

        if not user_object.is_plus():
            return self.redirect('/account/membership?upgrade=1')

        if len(user_object.shakes()) < 101:
            new_shake = Shake(name=name,
                              title=title,
                              description=description,
                              user_id=user_object.id,
                              type='group')
            try:
                if new_shake.save():
                    return self.redirect('/%s' % (new_shake.name))
            except torndb.IntegrityError:
                # This is a rare edge case, so we handle it lazily -- IK.
                pass
            self.add_errors(new_shake.errors)
            return self.render("shakes/create.html", shake=new_shake)
        else:
            return self.render("shakes/no-create.html")
Пример #3
0
    def test_quick_notifications(self):
        """
        /account/quick-notifications should return without error when populated with
        all possible  notification types.

        Page should also not be accessible if you're not signed in.
        """
        self.user2 = User(name='example2',email='*****@*****.**', \
            verify_email_token = 'created', password='******', email_confirmed=1,
            is_paid=1)
        self.user2.save()
        self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \
            thumb_key="asdf_t")
        self.sourcefile.save()
        self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \
            user_id=self.user.id, content_type="image/png", share_key="ok")
        self.sharedfile.save()
        self.shake = Shake(user_id=self.user2.id,
                           name='asdf',
                           type='group',
                           title='My Test Shake',
                           description='Testing this shake test.')
        self.shake.save()

        # new subscription
        new_sub = Subscription(user_id=self.user2.id, shake_id=1)
        new_sub.save()
        new_subscriber = Notification.new_subscriber(sender=self.user2,
                                                     receiver=self.user,
                                                     action_id=new_sub.id)
        # new favorite
        new_favorite = Notification.new_favorite(sender=self.user2,
                                                 sharedfile=self.sharedfile)
        # new save
        new_save = Notification.new_save(sender=self.user2,
                                         sharedfile=self.sharedfile)
        # new comment
        new_comment = Comment(user_id=self.user2.id,
                              sharedfile_id=self.sharedfile.id,
                              body="Testing comment")
        new_comment.save()
        # new mention
        new_mention = Notification.new_mention(receiver=self.user,
                                               comment=new_comment)
        # new invitation
        new_mention = Notification.new_invitation(sender=self.user2,
                                                  receiver=self.user,
                                                  action_id=self.shake.id)

        response = self.fetch_url('/account/quick-notifications')
        self.assertEqual(200, response.code)
        self.sign_out()
        response = self.fetch_url('/account/quick-notifications',
                                  follow_redirects=False)
        self.assertEqual(302, response.code)
Пример #4
0
 def get(self):
     user_object = self.get_current_user_object()
     
     if not user_object.is_paid:
         return self.redirect('/account/subscribe')
     
     if len(user_object.shakes()) < 100:
         new_shake = Shake(name='', title='', description='')
         return self.render("shakes/create.html", shake=new_shake)
     else:
         return self.render("shakes/no-create.html")
Пример #5
0
    def test_saving_validates_title(self):
        """
        Creates shakes with valid and invalid titles
        """
        valid_titles = ['asdf', 'This is a test.']
        invalid_titles = ['', None]
        identifier = 1

        for title in valid_titles:
            self.assertTrue(
                Shake(user_id=self.user.id,
                      title=title,
                      name='testing%s' % (identifier),
                      type='group').save())
            identifier += 1
        for title in invalid_titles:
            self.assertFalse(
                Shake(user_id=self.user.id,
                      title=title,
                      name='testing%s' % (identifier),
                      type='group').save())
            identifier += 1
Пример #6
0
    def setUp(self):
        super(ShakeModelTests, self).setUp()
        self.user = User(name='admin',
                         email='*****@*****.**',
                         email_confirmed=1)
        self.user.set_password('asdfasdf')
        self.user.save()

        self.shake = Shake(user_id=self.user.id,
                           name='asdf',
                           type='group',
                           title='My Test Shake',
                           description='Testing this shake test.')
        self.shake.save()
Пример #7
0
    def test_sharedfile_saved_to_group_shake(self):
        test_files = os.path.join(os.path.dirname(os.path.dirname(__file__)), "files")
        file_key = Sourcefile.get_sha1_file_key(test_files + "/1.png")
        shutil.copyfile("%s/1.png" % (test_files), "/tmp/%s" % (file_key))

        #create a new shake
        group_shake = Shake(user_id=self.user.id, type='group', title='asdf', name='asdf')
        group_shake.save()

        a_shared_file = Sharedfile.create_from_file("/tmp/%s" % (file_key),"1.png", file_key, "image/png", self.user.id, group_shake.id)
        self.assertTrue(group_shake.can_update(self.user.id))

        a_shared_file.add_to_shake(self.user.shake())

        ssfs = Shakesharedfile.all()
        for ssf in ssfs:
            self.assertEqual(ssf.sharedfile_id, a_shared_file.id)
Пример #8
0
    def setUp(self):
        super(RequestInvitationTests, self).setUp()
        self.user = User(name='joe',
                         email='*****@*****.**',
                         email_confirmed=1)
        self.user.set_password('asdfasdf')
        self.user.save()
        self.sign_in("joe", "asdfasdf")

        self.manager = User(name='admin',
                            email='*****@*****.**',
                            email_confirmed=1)
        self.manager.set_password('asdfasdf')
        self.manager.save()

        self.shake = Shake(user_id=self.manager.id,
                           type='group',
                           title="derp",
                           name='derp')
        self.shake.save()
Пример #9
0
    def test_can_user_delete_from_shake(self):
        """
        A user can only delete from a shake if they are the owner of the sharedfile
        or the owner of the shake.
        """
        user_shake = self.user.shake()
        self.sharedfile.add_to_shake(user_shake)
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(self.user, user_shake))

        # A user that doesn't own the sharedfile
        new_user = User(name='new_user',email='*****@*****.**',verify_email_token='created', email_confirmed=0)
        new_user.save()
        self.assertEqual(False, self.sharedfile.can_user_delete_from_shake(new_user, user_shake))

        # Owner of a group shake, but file doesn't belong to them.
        group_shake = Shake(user_id=new_user.id, type='group', title='Bears', name='bears')
        group_shake.save()
        self.sharedfile.add_to_shake(group_shake)
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(new_user, group_shake))
        # owner of file, but not of shake.
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(self.user, group_shake))
Пример #10
0
    def setUp(self):
        super(VoucherTests, self).setUp()
        self.admin = test.factories.user()
        self.sign_in("admin", "password")

        self.shake = Shake(user_id=self.admin.id,
                           name='promotion-shake',
                           title='Promotion Shake',
                           type='group')
        self.shake.save()
        self.expired_promotion = Promotion(name="Expired Promotion",
                                           membership_months=60,
                                           expires_at=datetime.utcnow() -
                                           timedelta(seconds=50),
                                           promotion_shake_id=0)
        self.expired_promotion.save()
        self.promotion = Promotion(name="Unit Test Sale",
                                   membership_months=60,
                                   promotion_shake_id=self.shake.id,
                                   expires_at=datetime.utcnow() +
                                   timedelta(seconds=60 * 60 * 24 * 365))
        self.promotion.save()

        self.used_voucher = Voucher(offered_by_user_id=0,
                                    promotion_id=self.promotion.id,
                                    voucher_key="abc123")
        # apply_to_user saves the voucher object (because it touches the
        # claimed_by_user_id and dates) and also the user object (by
        # updating the is_paid status)
        self.used_voucher.apply_to_user(self.admin)

        self.unused_voucher = Voucher(offered_by_user_id=0,
                                      claimed_by_user_id=0,
                                      promotion_id=self.promotion.id,
                                      voucher_key="unclaimed")
        self.unused_voucher.save()

        tornado.httpclient.HTTPClient()