Exemplo n.º 1
0
class TestSubscribe(unittest.TestCase):
    '''
    Test class to test behaviours of the Comments class
    Args:
        unittest.TestCase : Test case class that helps create test cases
    '''

    def setUp(self):
        '''
        Set up method that will run before every Test
        '''
        self.new_subscriber = Subscribe(name="New Subscriber",email="*****@*****.**")

    def test_instance(self):
        '''
        Test to check if new_comment is an instance of Comments
        '''

        self.assertTrue( isinstance( self.new_subscriber, Subscribe) )

    def test_save_subscriber(self):
        '''
        Test case to check if comment is saved to the database
        '''

        self.new_subscriber.save_subscriber()

        self.assertTrue( len(Subscribe.query.all()) > 0)
Exemplo n.º 2
0
def before_request():
    """
    Updates users last activity
    """
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()
    g.locale = str(get_locale())

    if not Country.query.all():
        countries = add_countries()
        for country in countries:
            new_country = Country(name=countries[country], code=country)
            db.session.add(new_country)
            db.session.commit()

    if not Subscribe.query.all():
        standard_subs = Subscribe(name='Standard', price=10)
        advanced_subs = Subscribe(name='Advanced', price=11)
        pro_subs = Subscribe(name='Pro', price=13)
        db.session.add(standard_subs)
        db.session.add(advanced_subs)
        db.session.add(pro_subs)
        db.session.commit()

    if current_user.subs_id and current_user.subs_expiration.date() <= date.today():
        current_user.subs_id = None
        current_user.subs_expiration = None
        db.session.commit()

    posts_from_world_news()
Exemplo n.º 3
0
class SubscribeModelTest(unittest.TestCase):
    def setUp(self):
        self.user_James = User(username='******', email='*****@*****.**')

        self.new_subscriber = Subscribe(email='*****@*****.**')

    def tearDown(self):
        Subscribe.query.delete()
        User.query.delete()

    def test_save_subscriber(self):
        self.new_subscriber.save_subscriber()
        self.assertTrue(len(Subscribe.query.all()) > 0)
Exemplo n.º 4
0
def subscribe():
    if request.method == "POST":
        form = request.form
        email = form.get("email")
        if email == None:
            error = "Enter your email required"
            return render_template('index.html', error=error)
        user = Subscribe(email=email)
        user.save()
        users = Subscribe.query.all()
        for user in users:
            mail_message("Hello", "email/subscribe", user.email, user=user)
        return redirect(url_for("main.home"))
    return render_template('index.html')
Exemplo n.º 5
0
class SubscribeTest(unittest.TestCase):
    def setUp(self):
        self.new_subscriber = Subscribe(email="*****@*****.**")
        db.session.add(self.new_subscriber)
        db.session.commit()

    def tearDown(self):
        Subscribe.query.delete()
        db.session.commit()

    def test_is_instance(self):
        self.assertTrue(isinstance(self.new_subscriber, Subscribe))

    def test_save_subscriber(self):
        self.new_subscriber.save_subscriber()
        self.assertTrue(len(Subscribe.query.all()) > 0)
Exemplo n.º 6
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_subscribe = Subscribe(id=1,
                                    name='media',
                                    subscribe='this is good post',
                                    email='*****@*****.**')
Exemplo n.º 7
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_subscribe = Subscribe(id=1,
                                    name='nicole',
                                    subscribe='I love this post',
                                    email='*****@*****.**')
Exemplo n.º 8
0
def subscribe():
    _id = request.args.get('id')
    # js = get_response('https://novel.juhe.im/book-info/' + _id)
    js = get_response('http://api.zhuishushenqi.com/book/' + _id)
    name = js.get('title')
    data = get_response('http://api.zhuishushenqi.com/toc?view=summary&book=' +
                        _id)

    s = Subscribe(user=current_user,
                  book_id=_id,
                  book_name=name,
                  source_id=data[1]['_id'],
                  chapter=0)
    db.session.add(s)
    db.session.commit()
    flash('订阅成功')
    return redirect(url_for('book_detail', book_id=_id))
Exemplo n.º 9
0
def subscribe():
    _id = request.args.get('id')
    js = get_response('http://api.zhuishushenqi.com/book/' + _id)
    name = js.get('title')
    if not name:
        flash('这本书不存在')
        return redirect(url_for('index'))

    data = get_response('http://api.zhuishushenqi.com/toc?view=summary&book=' + _id)

    s = Subscribe(user=current_user, book_id=_id, book_name=name, source_id=data[1]['_id'], chapter=0)
    db.session.add(s)
    db.session.commit()
    flash('订阅成功')
    next_page = request.args.get('next')
    if not next_page or url_parse(next_page).decode_netloc() != '':
        next_page = url_for('index')
    return redirect(next_page)
Exemplo n.º 10
0
 def setUp(self):
     self.new_subscriber = Subscribe(email="*****@*****.**")
     db.session.add(self.new_subscriber)
     db.session.commit()
Exemplo n.º 11
0
    def setUp(self):
        self.user_James = User(username='******', email='*****@*****.**')

        self.new_subscriber = Subscribe(email='*****@*****.**')
Exemplo n.º 12
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_subscriber = Subscribe(name="New Subscriber",email="*****@*****.**")