Exemplo n.º 1
0
    def test_add_post_page_li(self):
        p_cat = PostCategory(name='Resources')
        p_cat1 = PostCategory(name='Ressdgources')
        p_cat2 = PostCategory(name='Ressdgsdgources')
        p_cat3 = PostCategory(name='Reurces')
        db.session.add(p_cat)
        db.session.add(p_cat1)
        db.session.add(p_cat2)
        db.session.add(p_cat3)
        db.session.commit()

        all_cats = PostCategory.query.all()

        self.assertEqual([p_cat, p_cat1, p_cat2, p_cat3], all_cats)

        response = self.client.get('/add_post', follow_redirects=False)
        self.assertEqual(response.status_code, 200)

        data = dict(title='Hello', content='fagkjkjas', category=p_cat.id)

        response_1 = self.client.post('/add_post',
                                      follow_redirects=False,
                                      data=data,
                                      content_type='multipart/form-data')

        self.assertEqual(response_1.status_code, 302)

        new_post = db.session.query(Post).filter_by(name='Hello').first()

        self.assertNotEqual(new_post, None)
Exemplo n.º 2
0
def add_category():
    if request.method == 'POST':
        category = PostCategory().query.filter_by(
            category_name=request.form['category']).first()
        if category is None:
            category = PostCategory(category_name=request.form['category'])
            db.session.add(category)
            db.session.commit()
            flash('Category added Successfully!', 'success')
        else:
            flash('Category already exists!', 'alert')
        return render_template('site/post/add_post_catalog.html')
Exemplo n.º 3
0
def show_post(postID):
    categories = PostCategory().query.all()
    post = Post().query.get(int(postID))
    if post.post_url is not None:
        article = post.post_url
    else:
        article = 'site/post.html'

    newsletter_form = NewsLetterForm()
    comments = Comment.query.filter_by(post_id=postID).all()
    ref = 'blog/post/' + str(postID)
    # comment adder
    commentform = CommentForm()
    if commentform.validate_on_submit():
        comment = Comment(comment=commentform.comment.data,
                          post_id=post.id,
                          user_id=current_user.id)
        db.session.add(comment)
        db.session.commit()
        flash(
            'Your comment has been successfully added and pending Administrators approval to get live on blog.'
        )
        return redirect(ref)
    try:
        return render_template('site/post.html',
                               title=post.heading,
                               post=post,
                               newsletter_form=newsletter_form,
                               commentform=commentform,
                               comments=comments,
                               ref=ref,
                               post_categories=categories)
    except:
        return file_not_found(404)
Exemplo n.º 4
0
    def test_edit_post_page_li(self):
        p_cat = PostCategory(name='froots')

        db.session.add(p_cat)
        db.session.commit()

        post = Post(name='Hello',
                    content='3fhskajlga',
                    category_id=1,
                    category=p_cat)
        db.session.add(post)
        db.session.commit()

        response = self.client.get('/edit_post/1', follow_redirects=False)
        self.assertEqual(response.status_code, 200)

        data = dict(title='Good Day',
                    content='fagkjkjas whate',
                    category=p_cat.id)

        response_1 = self.client.post('/edit_post/1',
                                      follow_redirects=True,
                                      data=data)

        self.assertEqual(response_1.status_code, 200)

        edited_post = Post.query.filter_by(name='Good Day').first()

        self.assertNotEqual(edited_post, None)
Exemplo n.º 5
0
def add_article():
    form = ArticleForm()
    postcategories = PostCategory().query.all()
    tags = Tag().query.all()

    if form.validate_on_submit():
        category = PostCategory().query.filter_by(
            category_name=request.form['post-category-selector']).first()

        article = Post(heading=form.heading.data,
                       author=current_user.username,
                       timestamp=datetime.utcnow(),
                       body=form.body.data,
                       thumbnail=request.form['thumbnail'])

        string = request.form['tags'] + ','
        tag_list = []
        char = []
        for i in string:
            if i != ',':
                char.append(i)
            elif i == ',':
                char = ''.join(char)
                char = char.strip()
                get_tag = Tag.query.filter_by(tag_name=char).first()
                if get_tag is not None:
                    tag_list.append(get_tag)
                elif get_tag is None:
                    Tag().new_tag(char)
                    get_tag = Tag.query.filter_by(tag_name=char).first()
                    if get_tag is not None:
                        tag_list.append(get_tag)

                char = []

        article.tags = tag_list
        category.posts.append(article)
        db.session.commit()
        flash('Your Article has been successfully added !', 'success')
        return redirect(url_for('dashboard'))
    return render_template('user/add_article.html',
                           title='Add Article',
                           form=form,
                           postcategories=postcategories,
                           tags=tags)
Exemplo n.º 6
0
def before_request():

    # ads scripts
    g.categories = PostCategory().query.all()

    # last seen logger
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()
Exemplo n.º 7
0
def post_category(categoryID):
    tags = Tag().query.all()
    category = PostCategory().query.get(int(categoryID))
    if category is None:
        return file_not_found(404)
    posts = category.posts
    return render_template('site/post/post_category.html',
                           posts=posts,
                           category=category,
                           tags=tags)
Exemplo n.º 8
0
def blog(page=1):
    categories = PostCategory().query.all()
    tags = Tag().query.all()
    featured = Post().query.order_by(Post.likes)
    latest = Post().latest_posts().paginate(page, app.config['POSTS_PER_PAGE'],
                                            False)
    return render_template('site/blog.html',
                           title='Blog',
                           latest=latest,
                           featured_posts=featured,
                           post_categories=categories,
                           tags=tags)
Exemplo n.º 9
0
    def test_delete_blog_category_page_li(self):
        p_cat = PostCategory(name='froots')

        db.session.add(p_cat)
        db.session.commit()

        response = self.client.get('/delete_blog_category/1',
                                   follow_redirects=False)
        self.assertEqual(response.status_code, 302)

        p_cat = PostCategory.query.filter_by(name='froots').first()

        self.assertEqual(p_cat, None)
Exemplo n.º 10
0
    def test_Post_model(self):

        p_cat = PostCategory(name='froots')

        db.session.add(p_cat)
        db.session.commit()

        post = Post(name='Hello',
                    content='3fhskajlga',
                    category_id=1,
                    category=p_cat)
        db.session.add(post)
        db.session.commit()

        assert post in db.session
Exemplo n.º 11
0
    def test_edit_blog_category_page_li(self):
        post_cat = PostCategory(name='tudoloos')
        db.session.add(post_cat)
        db.session.commit()

        response = self.client.get('/edit_blog_category/1',
                                   follow_redirects=False)
        self.assertEqual(response.status_code, 200)

        response_1 = self.client.post('/edit_blog_category/1',
                                      follow_redirects=True,
                                      data=dict(name='yippe'))

        self.assertEqual(response_1.status_code, 200)

        edited_post_category = PostCategory.query.filter_by(
            name='yippe').first()

        self.assertNotEqual(edited_post_category, None)
Exemplo n.º 12
0
    def test_delete_post_page_li(self):
        p_cat = PostCategory(name='froots')

        db.session.add(p_cat)
        db.session.commit()

        post = Post(name='Hello',
                    content='3fhskajlga',
                    category_id=1,
                    category=p_cat)
        db.session.add(post)
        db.session.commit()

        response = self.client.get('/delete_post/1', follow_redirects=False)
        self.assertEqual(response.status_code, 302)

        deleted_post = Post.query.filter_by(name='Hello').first()

        self.assertEqual(deleted_post, None)

        assert post not in db.session
Exemplo n.º 13
0
def post_catalog():
    categories = PostCategory().query.all()
    tags = Tag().query.all()
    return render_template('site/post/post_catalog.html',
                           post_categories=categories,
                           tags=tags)
Exemplo n.º 14
0
    def test_blog_view_page(self):
        # blog page
        response = self.client.get('/blog', follow_redirects=True)
        self.assertEqual(response.status_code, 200)

        p_cat = PostCategory(name='froots')

        db.session.add(p_cat)
        db.session.commit()

        post = Post(name='Hello',
                    content='3fhskajlga',
                    category_id=1,
                    category=p_cat)
        db.session.add(post)
        db.session.commit()

        post = Post.query.filter_by(name='Hello').first()

        p_cat = PostCategory.query.filter_by(name='froots').first()

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get('/blog')
                template, context = templates[0]
                self.assertEqual(context['posts'], [post])
                self.assertEqual(context['categories'], [p_cat])
                self.assertEqual(context['next_url'], None)
                self.assertEqual(context['prev_url'], None)

        p_cat_1 = PostCategory(name='Tondits')
        db.session.add(p_cat_1)

        p_cat_2 = PostCategory(name='frootsLoops')
        db.session.add(p_cat_2)

        p_cat_3 = PostCategory(name='Roger')
        db.session.add(p_cat_3)

        db.session.commit()

        post_1 = Post(name='Post 1',
                      content='Stephen king is awesome',
                      category_id=1,
                      category=p_cat)
        post_2 = Post(name='Hello 2',
                      content='Shoe dog is a great book',
                      category_id=2,
                      category=p_cat_1)
        post_3 = Post(name='Hello 3',
                      content='Zappos was a great company',
                      category_id=3,
                      category=p_cat_2)
        post_4 = Post(name='Hello 4',
                      content='Gary bettman is crazy',
                      category_id=4,
                      category=p_cat_3)

        post_5 = Post(name='Hello 5',
                      content='Today will be a great day',
                      category_id=1,
                      category=p_cat)
        post_6 = Post(name='Hello 6',
                      content='Untested code is broken code',
                      category_id=2,
                      category=p_cat_1)
        post_7 = Post(name='Hello 7',
                      content='Seeding is over!',
                      category_id=3,
                      category=p_cat_2)
        post_8 = Post(name='Hello 8',
                      content='It is raining out',
                      category_id=4,
                      category=p_cat_3)

        post_9 = Post(name='Hello 9',
                      content='I get confused easily',
                      category_id=1,
                      category=p_cat)
        post_10 = Post(name='Hello 10',
                       content='I wonder if I should get water',
                       category_id=2,
                       category=p_cat_1)
        post_11 = Post(name='Hello 11',
                       content='Hopefully I figure out that one test soon',
                       category_id=3,
                       category=p_cat_2)
        post_12 = Post(name='Hello 12',
                       content='It is really frustrating me',
                       category_id=4,
                       category=p_cat_3)

        post_13 = Post(name='Hello 91',
                       content='I get confused easily what',
                       category_id=1,
                       category=p_cat)
        post_14 = Post(name='Hello 101',
                       content='I wonder if I should gewhatt water',
                       category_id=2,
                       category=p_cat_1)
        post_15 = Post(name='Hello 111',
                       content='Hopefully I figure out thawhet one test soon',
                       category_id=3,
                       category=p_cat_2)
        post_16 = Post(name='Hello 121',
                       content='It is really frustrating mewheat',
                       category_id=4,
                       category=p_cat_3)

        post_17 = Post(name='Hello 916',
                       content='I get confused easilddy',
                       category_id=1,
                       category=p_cat)
        post_18 = Post(name='Hello 1031',
                       content='I wonder if I shoulddsa get water',
                       category_id=2,
                       category=p_cat_1)
        post_19 = Post(
            name='Hello1 11',
            content='Hopefully I figure out thellohat one test soon',
            category_id=3,
            category=p_cat_2)
        post_20 = Post(name='Hello 112',
                       content='It is really frustrating mdse',
                       category_id=4,
                       category=p_cat_3)

        post_21 = Post(name='Hello 924',
                       content='I get confused easily mais ou menos',
                       category_id=1,
                       category=p_cat)
        post_22 = Post(name='Hello 102',
                       content='I wonder if I should get water holy fuch',
                       category_id=2,
                       category=p_cat_1)
        post_23 = Post(name='Hello 411',
                       content='Hopefully I figure out that one test soosdgn',
                       category_id=3,
                       category=p_cat_2)
        post_24 = Post(name='Hello 142',
                       content='It is really frustrating me. It will be OK!',
                       category_id=4,
                       category=p_cat_3)

        db.session.commit()

        #
        # Testing specifying a category
        #
        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(url_for('blogs.blog', category=3, post=None, page=0))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_23, post_19, post_15, post_11, post_7])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(
                    context['next_url'],
                    url_for('blogs.blog', category=3, page=1, post=None))
                self.assertEqual(context['prev_url'], None)

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(url_for('blogs.blog', category=3, post=None, page=1))
                template, context = templates[0]
                self.assertEqual(context['posts'], [post_3])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(context['next_url'], None)
                self.assertEqual(
                    context['prev_url'],
                    url_for('blogs.blog', category=3, page=0, post=None))

        #
        # Test specifying a post
        #
        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(url_for('blogs.blog', post=2, page=0, category=None))
                template, context = templates[0]
                self.assertEqual(context['posts'], [post_1])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(context['next_url'], None)
                self.assertEqual(context['prev_url'], None)

        #
        # Test not specifying anything
        #
        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(
                    url_for('blogs.blog', category=None, post=None, page=0))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_24, post_23, post_22, post_21, post_20])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(
                    context['next_url'],
                    url_for('blogs.blog', category=None, page=1, post=None))
                self.assertEqual(context['prev_url'], None)

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(
                    url_for('blogs.blog', category=None, post=None, page=1))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_19, post_18, post_17, post_16, post_15])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(
                    context['next_url'],
                    url_for('blogs.blog', category=None, page=2, post=None))
                self.assertEqual(
                    context['prev_url'],
                    url_for('blogs.blog', category=None, page=0, post=None))

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(
                    url_for('blogs.blog', category=None, post=None, page=2))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_14, post_13, post_12, post_11, post_10])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(
                    context['next_url'],
                    url_for('blogs.blog', category=None, page=3, post=None))
                self.assertEqual(
                    context['prev_url'],
                    url_for('blogs.blog', category=None, page=1, post=None))

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(
                    url_for('blogs.blog', category=None, post=None, page=3))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_9, post_8, post_7, post_6, post_5])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(
                    context['next_url'],
                    url_for('blogs.blog', category=None, page=4, post=None))
                self.assertEqual(
                    context['prev_url'],
                    url_for('blogs.blog', category=None, page=2, post=None))

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get(
                    url_for('blogs.blog', category=None, post=None, page=4))
                template, context = templates[0]
                self.assertEqual(context['posts'],
                                 [post_4, post_3, post_2, post_1, post])
                self.assertEqual(context['categories'],
                                 [p_cat, p_cat_1, p_cat_2, p_cat_3])
                self.assertEqual(context['next_url'], None)
                self.assertEqual(
                    context['prev_url'],
                    url_for('blogs.blog', category=None, page=3, post=None))
Exemplo n.º 15
0
    def test_blog_category_model(self):
        post_cat = PostCategory(name='tudoloos')
        db.session.add(post_cat)
        db.session.commit()

        assert post_cat in db.session
Exemplo n.º 16
0
from app import db
from app.models import Users, Project, PostCategory, TaskCategory

db.create_all()

admin = Users(username='******',
              email='*****@*****.**',
              superuser=True,
              active=True)
admin.set_password('a')

cat1 = PostCategory(name='main')
cat2 = PostCategory(name='personal')
cat3 = PostCategory(name='development')

proj1 = Project(name='Blog',
                description='Realizacja dalszych pomysłów co do owego bloga.')

proj2 = Project(name='Koło', description='Sieciowa gra w koło fortuny.')

taskcat = TaskCategory(name='todo')
taskcat1 = TaskCategory(name='in_progress')
taskcat2 = TaskCategory(name='finished')

db.session.add_all(
    [admin, cat1, cat2, cat3, proj1, proj2, taskcat, taskcat1, taskcat2])
db.session.commit()
Exemplo n.º 17
0
    def test_other_database_pages(self):
        # contact page
        auth_1 = Author(name='Kidkaidf', email='*****@*****.**', password='******')
        db.session.add(auth_1)

        db.session.commit()

        response = self.client.get('/contact', follow_redirects=True)
        self.assertEqual(response.status_code, 200)

        auth_1 = Author.query.filter_by(name='Kidkaidf').first()
        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                r = c.get('/contact')
                template, context = templates[0]
                self.assertEqual(context['authors'], [auth_1])





        #
        # Testing the Admin Page
        #
        w_cat = WorksheetCategory(name='dundk')
        db.session.add(w_cat)

        p_cat = PostCategory(name='froots')

        learner = Learner(name='KJsa', email='*****@*****.**', screenname='kod'
                        , password='******')

        learner_1 = Learner(name='Ksa', email='*****@*****.**', screenname='kod_1'
                        , password='******')

        learner_2 = Learner(name='KoJsa', email='*****@*****.**', screenname='kod2'
                        , password='******')

        learner_3 = Learner(name='KJdsa', email='*****@*****.**', screenname='kod3'
                        , password='******')

        db.session.add(learner)
        db.session.add(learner_1)
        db.session.add(learner_2)
        db.session.add(learner_3)
        db.session.commit()

        db.session.add(p_cat)
        db.session.commit()

        worksheet = Worksheet(pdf_url='tudoloos.pdf', name='tudoloo', author_id=1, author=auth_1, category_id=1, category=w_cat)
        worksheet_1 = Worksheet(pdf_url='tudoloo.pdf', name='tudolos', author_id=1, author=auth_1, category_id=1, category=w_cat)
        worksheet_2 = Worksheet(pdf_url='tudolos.pdf', name='tudooos', author_id=1, author=auth_1, category_id=1, category=w_cat)
        worksheet_3 = Worksheet(pdf_url='tudolos.pdf', name='tudloos', author_id=1, author=auth_1, category_id=1, category=w_cat)

        learner_1.favourites.append(worksheet)

        learner_2.favourites.append(worksheet)

        learner_2.favourites.append(worksheet_2)

        learner_3.favourites.append(worksheet_2)

        db.session.commit()

        response = self.client.get('/admin', follow_redirects=True)
        self.assertEqual(response.status_code, 200)

        with self.app.test_client() as c:
            with captured_templates(self.app) as templates:
                login(c, os.getenv('LOGIN_USERNAME'), os.getenv('LOGIN_PASSWORD'))
                r = c.get('/admin', follow_redirects=False)
                self.assertEqual(r.status_code, 200)
                template, context = templates[1]
                self.assertEqual(context['post_categories'], [p_cat])
                self.assertEqual(context['worksheet_categories'], [w_cat])
                self.assertEqual(context['learners'], [learner, learner_1, learner_2, learner_3])
                logout(c)