Beispiel #1
0
class CommentsModelTest(unittest.TestCase):
    def setUp(self):
        self.user_Logan = User(username='******',
                               password='******',
                               email='*****@*****.**')
        self.new_pitch = Pitch(title='test',
                               body='testing pitch creation',
                               user_id=1,
                               category='promotion')
        self.new_comment = Comments(id=1,
                                    comment='Comment test',
                                    user_id=1,
                                    pitch=self.new_pitch)

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

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.id, 1)

        self.assertEquals(self.new_comment.comment, 'Comment test')

        self.assertEquals(self.new_comment.user_id, 1)

    def test_save_comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all()) > 0)

    def test_get_comment_by_id(self):
        self.new_comment.save_comment()
        got_comments = Comments.get_comments(1)
        self.assertTrue(len(got_comments) == 1)
Beispiel #2
0
def lookup_report(request, id):
    if request.method == "POST":
        form = CommentsForm(request.POST)
        if form.is_valid():
            complaint = Complaints.objects.get(id=id)
            print "form is valid"
            user_id = request.user.id
            complaint_id = complaint.id
            comments = form.cleaned_data['comments']
            ThisComment = Comments(user_id=user_id, comments=comments, complaints_id=complaint_id)
    #                ThisComment = Comments(user=request.user, complaints=complaint, comments=comments)
            ThisComment.save()
        complaint = Complaints.objects.get(id=id)
        form = CommentsForm()
        data = {
            'complaint': complaint,
            'form': form,
        }
        return render(request, "lookup.html", data)
    else:
        currentUrl = request.get_full_path()
        request.session['currentUrl'] = currentUrl
        print request.session['currentUrl']
        complaint = Complaints.objects.get(id=id)
        form = CommentsForm()
        data = {
            'complaint': complaint,
            'form': form,
        }
        return render(request, "lookup.html", data)
Beispiel #3
0
class TestComments(unittest.TestCase):
    def setUp(self):
        self.user_dean = Users(username='******',
                               password='******',
                               email='*****@*****.**')
        self.new_comment = Comments(email="*****@*****.**",
                                    username="******",
                                    comment="dope",
                                    blog_id=20)

    def tearDown(self):
        Comments.query.delete()
        Users.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.email, "*****@*****.**")
        self.assertEquals(self.new_comment.username, "user")
        self.assertEquals(self.new_comment.comment, "dope")
        self.assertEquals(self.new_comment.blog_id, 20)

    def test_save_comment(self):
        self.new_comment.save_comments()
        self.assertTrue(len(Comments.query.all()) > 0)

    def test_get_comment_by_id(self):
        self.new_comment.save_comments()
        got_comments = Comments.get_comments(20)
        self.assertTrue(len(got_comments) == 1)
Beispiel #4
0
class TestComments(unittest.TestCase):
    def setUp(self):
        self.user_James = User(username='******',
                               password='******',
                               email='*****@*****.**')
        self.new_comment = Comments(post_id=12345,
                                    opinion='Review for movies',
                                    user_id=1,
                                    user=self.user_James)

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

    def test_instance(self):
        self.assertTrue(isinstance(self.new_comment, Comments))

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.post_id, 12345)
        self.assertEquals(self.new_comment.opinion, 'Review for movies')
        self.assertEquals(self.new_comment.user_id, 1)
        self.assertEquals(self.new_review.user, self.user_James)

    def test_save_comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all()) > 0)

    def test_get_comment_by_id(self):

        self.new_comment.save_comment()
        got_comments = Comments.get_comments(12345)
        self.assertTrue(len(got_comments) == 1)
Beispiel #5
0
class TestComments(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_comment = Comments(the_comment="This is a test comment")

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

        self.assertTrue( isinstance( self.new_comment, Comments) )

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

        self.new_comment.save_comment()

        self.assertTrue( len(Comments.query.all()) > 0)
Beispiel #6
0
 def setUp(self):
     self.user_Collo = User(username="******",
                            password="******",
                            email="*****@*****.**")
     self.new_comment = Comments(pitch_id=10,
                                 pitch_title="Pitch",
                                 comments="Great")
Beispiel #7
0
class PostTest(unittest.TestCase):
    def setUp(self):
        """
        Set up method that will run before every Test
        """
        self.post = Post(category='Product', content='Yes we can!')
        self.user_Derrick = User(username='******',
                                 password='******',
                                 email='*****@*****.**')
        self.new_comment = Comments(text='This is good',
                                    user=self.user_Derrick)

    def tearDown(self):
        Comments.query.delete()
        Post.query.delete()
        User.query.delete()

    def test_instance(self):
        self.assertTrue(isinstance(self.post, Post))

    def test_check_instance_variables(self):
        self.assertEquals(self.post.category, 'Product')
        self.assertEquals(self.post.content, 'Yes we can!')
        self.assertEquals(self.new_comment.text, 'This is good')
        self.assertEquals(self.new_comment.user, self.user_Derrick)

    def test_save_comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all()) > 0)
Beispiel #8
0
class CommentTest(unittest.TestCase):
    def setUp(self):
        self.user_Collo = User(username="******",
                               password="******",
                               email="*****@*****.**")
        self.new_comment = Comments(pitch_id=10,
                                    pitch_title="Drone",
                                    comments="Nice app")

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

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.pitch_id, 10)
        self.assertEquals(self.new_comment.pitch_title, "Drone")
        self.assertEquals(self.new_comment.comments, "Nice app")

    def test_save_comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all()) > 0)

    def test_get_comment_by_id(self):
        self.new_comment.save_comment()
        got_comments = Comments.get_comments(10)
        self.assertTrue(len(got_comments) == 1)
Beispiel #9
0
 def setUp(self):
     self.user_Collo = User(username="******",
                            password="******",
                            email="*****@*****.**")
     self.new_comment = Comments(pitch_id=10,
                                 pitch_title="Drone",
                                 comments="Nice app")
Beispiel #10
0
 def setUp(self):
     self.user_dean = Users(username='******',
                            password='******',
                            email='*****@*****.**')
     self.new_comment = Comments(email="*****@*****.**",
                                 username="******",
                                 comment="dope",
                                 blog_id=20)
Beispiel #11
0
 def setUp(self):
     self.user_James = User(username='******',
                            password='******',
                            email='*****@*****.**')
     self.new_comment = Comments(post_id=12345,
                                 opinion='Review for movies',
                                 user_id=1,
                                 user=self.user_James)
Beispiel #12
0
 def test_func_save(self):
     comment = Comments(text='text',
                        client_id=1,
                        business_id=1,
                        client_name='client_name',
                        star=1)
     comment.save()
     self.assertEqual(comment, Comments.query.get(comment.id))
Beispiel #13
0
def comment(blog_id):
    if request.method == 'POST':
        comment = request.form.get('comment')
        blog = Blog.query.filter_by(id=blog_id).first()
        comment = Comments(comment=comment, blog_id=blog.id)
        comment.save()
        return redirect(url_for('main.home', blog=blog))
    return render_template('index.html')
Beispiel #14
0
def projectView(username, project):
    form = EditProjectForm()
    allUsers = User.query.filter(User.username != "admin").all()
    currentRole = User.query.filter_by(
        username=current_user.username).first_or_404()
    user = User.query.filter_by(username=username).first_or_404()
    proj = Projects.query.filter_by(id=project).first_or_404()
    comments = Comments(comment_id=proj.id).query.filter_by(
        comment_id=project).all()
    comment = Comments(comment_id=proj.id)
    if form.validate_on_submit():
        proj.description = form.description.data
        proj.company = form.company.data
        if form.priority.data == "":
            form.priority.data = "9999"
        proj.priority = form.priority.data
        proj.priority_dept = form.priority_dept.data
        proj.requester = form.requester.data
        proj.status = form.status.data
        proj.department = form.department.data
        proj.ticket = form.ticket.data
        proj.hours = form.hours.data
        comment.comment = form.comment.data
        if comment.comment != "":
            db.session.add(comment)
        db.session.commit()
        flash('Project Updated!')
        return redirect(
            url_for('projectView',
                    username=username,
                    comment=comments,
                    project=project))
    elif request.method == 'GET':
        form.description.data = proj.description
        form.company.data = proj.company
        if proj.priority == "9999":
            proj.priority = ""
        if proj.priority_dept == "9999":
            proj.priority_dept = ""
        form.priority.data = proj.priority
        form.priority_dept.data = proj.priority_dept
        form.requester.data = proj.requester
        form.status.data = proj.status
        form.department.data = proj.department
        form.ticket.data = proj.ticket
        form.hours.data = proj.hours

    return render_template('editprojects.1.html',
                           title='Edit Project',
                           user=user,
                           form=form,
                           comment=comments,
                           project=proj,
                           allUsers=allUsers,
                           currentRole=currentRole,
                           jfilesize=jfilesize,
                           cfilesize=cfilesize,
                           dev=username)
Beispiel #15
0
def new_comment(id):
    form = CommentForm()
    if form.validate_on_submit():
        new_comment = Comments(comment_name=form.comment_name.data,
                               user=current_user,
                               blog_id=id)
        new_comment.save_comment()
        return redirect(url_for('.index'))
    return render_template('new_comment.html', form=form)
Beispiel #16
0
 def test_func_get_star(self):
     comment = Comments(text='text',
                        client_id=1,
                        business_id=1,
                        client_name='client_name',
                        star=1)
     db.session.add(comment)
     db.session.commit()
     self.assertEqual(comment.star, Comments.get_star(comment.id))
Beispiel #17
0
 def setUp(self):
     """
     Set up method that will run before every Test
     """
     self.post = Post(category='Product', content='Yes we can!')
     self.user_Derrick = User(username='******',
                              password='******',
                              email='*****@*****.**')
     self.new_comment = Comments(text='This is good',
                                 user=self.user_Derrick)
Beispiel #18
0
class CommentTest(unittest.TestCase):

    def setUp(self):
        self.new_comment = Comments(comment="Great Idea")

    def test_instance(self):
        self.assertTrue(isinstance(self.new_comment,Comments))

    def test_save_comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all())>0)
Beispiel #19
0
def post_comments():
    form = PostCommentsForm()
    if form.validate_on_submit():
        comments = Comments()
        comments.body = form.body.data
        comments.user_id = current_user.id
        comments.news_id = request.args.get('nid')
        db.session.add(comments)
        db.session.commit()
        return redirect(url_for('.news', nid=comments.news_id))
    return render_template('main/post_comments.html', form=form)
Beispiel #20
0
def your_comment(pitch_id):
    form2 = CommentForm()
    comments = Comments.query.filter_by(pitch_id=pitch_id).all()
    if form2.validate_on_submit():
        pitch_id = pitch_id
        user_id = current_user._get_current_object().id
        comments = Comments(comments=form2.comments.data,
                            user_id=user_id,
                            pitch_id=pitch_id)
        comments.save_comment()
        return redirect(url_for('main.index'))
    return render_template('comment.html', form2=form2, comments=comments)
Beispiel #21
0
 def setUp(self):
     self.user_her = User(username='******',
                          password='******',
                          email='*****@*****.**')
     self.new_pitch = Pitch(title='test',
                            content='hire me',
                            user_id=1,
                            category='interview')
     self.new_comment = Comments(id=1,
                                 comment='test',
                                 user_id=1,
                                 pitch=self.new_pitch)
Beispiel #22
0
 def setUp(self):
     self.user_Logan = User(username='******',
                            password='******',
                            email='*****@*****.**')
     self.new_pitch = Pitch(title='test',
                            body='testing pitch creation',
                            user_id=1,
                            category='promotion')
     self.new_comment = Comments(id=1,
                                 comment='Comment test',
                                 user_id=1,
                                 pitch=self.new_pitch)
Beispiel #23
0
    def setUp(self):
        self.new_user = User(1,
                             'derrick',
                             '*****@*****.**',
                             datetime.now(),
                             'derrick',
                             'white',
                             password='******',
                             access=1)

        self.new_post = Post(1, 'title', 'body', datetime.now())

        self.new_comment = Comments(1, 'just awesome', 1, datetime.now(), 1)
Beispiel #24
0
class PitchesModelTest(unittest.TestCase):
    def setUp(self):
        self.user_James = User(username='******', email='*****@*****.**')

        self.new_comment = Comments(comment='This is a comment')

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

    def test_save_pitch(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comments.query.all()) > 0)
Beispiel #25
0
def comment(post_id):
    forms = CommentForm()
    comments = Comments.query.filter_by(post_id=post_id).all()
    if forms.validate_on_submit():
        post_id = post_id
        user_id = current_user._get_current_object().id
        comment = Comments(comment=forms.comment.data,
                           user_id=user_id,
                           post_id=post_id)
        comment.save()
        return redirect(url_for('main.index'))

    return render_template('comments.html', forms=forms, comments=comments)
Beispiel #26
0
def get_comments(num):
    res = []
    count = db.movie.count()
    query = db.movie.find({}, {
        '_id': 1
    }).skip(count / randint(1, 10)).limit(num)
    for i in xrange(num):
        comment = Comments()
        comment.mid = query[i]['_id']
        comment.title = fake.sentence()
        comment.content = '\n'.join(fake.sentences(nb=randint(2, 7)))
        res.append(comment)
    return res
Beispiel #27
0
def _add_comment():
    json = request.get_json(force=True)
    news_id = json['news_id']
    text = json['text']
    comment = Comments()
    comment.comment_text = text
    comment.creation_date = func.current_timestamp()
    comment.news_id = news_id
    db.session.add(comment)
    db.session.flush()
    new_id = comment.comment_id
    db.session.commit()
    return '{"new_id":"' + str(new_id) + '"}'
Beispiel #28
0
def submitComment(request):
    """Allows user to review/commment on user list"""
    if request.method == 'POST':
        commentForm = BoostrapCommentForm(request.POST)
        if commentForm.is_valid():
            comment = commentForm.cleaned_data.get('comment')
            listOwnerId = commentForm.cleaned_data.get('listOwnerId')
            userList = User.objects.get(pk=listOwnerId)
            commentOwner = User.objects.get(pk=request.user.id).username
            newComment = Comments(userList=userList,commentOwner=commentOwner,comments=comment)
            newComment.save() 
             #Generate otherProfileView and return update page 
            return HttpResponseRedirect('/profile/' + userList.username)
Beispiel #29
0
def comment_add(id):
  post = Posts.query.get(id)
  #Add error check here
  if request.method == 'POST':
    comment = Comments(id, request.form['author_name'], request.form['author_email'],
                       0, request.remote_addr, request.form['content'], 0, 0,
                       request.headers['User-Agent'], 0, 0)
    comment_add=comment.add(comment)
    if not comment_add:
      flash("Add was successful")
    else:
      message = comment_add
      flash(message)
    return redirect(url_for('single_post', id=post.id, slug=post.slug))
Beispiel #30
0
def comment(request,team_name_t):
    if logged_in_post(request):
        if read_access_post(request,team_name_t):
            comment_obj = Comments(
                task=Task.objects.get(task_id=request.POST['task_id']),
                user=User.objects.get(uname=request.POST['username']),
                text=request.POST['text']
            )
            comment_obj.save()
            return HttpResponse("<html><h1>Success</h1></html>")
        else:
            return HttpResponse("<html><h1>Access denied</h1></html>")
    else:
        return HttpResponse("<html><h1>Not logged in</h1></html>")
Beispiel #31
0
def comment(request,relatedType,relatedId):
    assert isinstance(request, HttpRequest)
    try:
         relatedType = int(relatedType)
         relatedId = int(relatedId)
    except ValueError:
         raise Http404()
    if request.method == 'POST' and request.is_ajax():
        content = request.POST['content']
        response = HttpResponse()
        comment = Comments(relatedType=relatedType,relatedId = relatedId,publisher=request.user,content=content)
        comment.save()
        response.write(comment.pk)
        return response
Beispiel #32
0
def comment_add(id):
    post = Posts.query.get(id)
    #Add error check here
    if request.method == 'POST':
        comment = Comments(id, request.form['author_name'],
                           request.form['author_email'], 0,
                           request.remote_addr, request.form['content'], 0, 0,
                           request.headers['User-Agent'], 0, 0)
        comment_add = comment.add(comment)
        if not comment_add:
            flash("Add was successful")
        else:
            message = comment_add
            flash(message)
        return redirect(url_for('single_post', id=post.id, slug=post.slug))
Beispiel #33
0
def alltask(request, team_name_t):
    if logged_in(request):
        if read_access(request,team_name_t):
            if request.method=='POST':
                if 'task_id' in request.POST and 'accept' in request.POST:
                    task_object = Task.objects.get(task_id=request.POST['task_id'])
                    task_object.accepted=True
                    task_object.accepted_time=timezone.localtime(timezone.now())
                    task_object.save()
                    return HttpResponse("<html><h1>Successfully Accepted</h1></html>")
                elif 'task_id' in request.POST:
                    comment_obj = Comments(
                        task=Task.objects.get(task_id=request.POST['task_id']),
                        user=User.objects.get(uname=request.COOKIES.get("username")),
                        text=request.POST['text']
                    )
                    comment_obj.save()
                elif 'file_id' in request.POST:
                    file_object = File.objects.get(file_id=request.POST['file_id'])
                    file_object.accepted = True
                    file_object.accepted_time=timezone.localtime(timezone.now())
                    file_object.save()
                    return HttpResponse("<html><h1>Successfully Accepted</h1></html>")
            all_tasks = Task.objects.prefetch_related('file_set').prefetch_related('comments_set').filter(
                team=Team.objects.get(team_name=team_name_t)
            ).order_by('-task_id')
            context = {
                "team": team_name_t,
                "tasks": all_tasks,
                "user": User.objects.get(uname=request.COOKIES['username']),
                "round": get_formatted_team_name(team_name_t),
                "is_admin": is_admin(request,team_name_t),
                "download": download_access(request,team_name_t),
            }
            return render(request, 'home/alltask.html', context)
        else:
            raise Http404
    else:
        return redirect("/")
Beispiel #34
0
def feeds(request, team_name_t):
    if logged_in(request):
        if read_access(request,team_name_t):
            if request.method=="POST":
                comment_obj = Comments(
                    task=Task.objects.get(task_id=request.POST['task_id']),
                    user=User.objects.get(uname=request.COOKIES.get("username")),
                    text=request.POST['text']
                )
                comment_obj.save()
            all_tasks = Task.objects.prefetch_related('comments_set').filter(team=Team.objects.get(team_name=team_name_t)).order_by('-last_modified_time')
            context = {
                "tasks": all_tasks,
                "team": team_name_t,
                "isadmin": is_admin(request,team_name_t),
                "round": get_formatted_team_name(team_name_t),
            }
            return render(request, 'home/feed.html', context)
        else:
            raise Http404
    else:
        return redirect("/")
Beispiel #35
0
from .base import ResourceSchema, Schema
from app.utils import Method, Role


class CommentSchema(Schema):
    dateCreated = fields.DateTime()
    lastModified = fields.DateTime()

    class Meta:
        fields = Comments.get_columns(Method.READ, Role.ADMIN)


class CommentResourceSchema(ResourceSchema):
    class Meta:
        type = 'comments'


create_comment_serializer = CommentResourceSchema(
    CommentSchema
)

update_comment_serializer = CommentResourceSchema(
    CommentSchema,
    param={'only': set(Comments.get_columns(Method.UPDATE, Role.USER)) - {'parentId', 'userId', 'articleId'}}
)

read_comment_serializer = CommentResourceSchema(
    CommentSchema,
    param={'only': set(Comments.get_columns(Method.READ, Role.GUEST)) - {'parentId', 'userId', 'articleId'}}
)
def addcomment(request):
    if request.POST:
        comment = Comments()
        comment.fname = request.POST.get('firstname')
        comment.name = request.POST.get('lastname')
        comment.lname = request.POST.get('secondname')
        comment.region_id = int(request.POST.get('region'))
        comment.city_id = int(request.POST.get('city'))
        comment.phone = request.POST.get('phone')
        comment.email = request.POST.get('email')
        comment.comment = request.POST.get('comment')
        comment.save()
        return HttpResponse(json.dumps(""))
    else:
        raise Http404