Skip to content

Commit

Permalink
Merge 79dc79a into 5354143
Browse files Browse the repository at this point in the history
  • Loading branch information
victorhugo21 committed May 4, 2021
2 parents 5354143 + 79dc79a commit b55f240
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/controller/post_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def post(self):
except ValidationError as err:
return make_response(jsonify(err.messages), 400)

@jwt_required()
def get(self):
user = current_user
if not user.is_professor():
ps = post_schema.PostSchema(
many=True, context={'reg_student': user.reg})
else:
ps = post_schema.PostSchema(many=True)
return make_response(ps.jsonify(user.posts), 200)


class PostAgreesList(Resource):
@student_required()
Expand Down
4 changes: 2 additions & 2 deletions app/schemas/post_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Meta:
model = post.Post

id_post = fields.Integer(required=True, validate=validate.Range(min=0))
reg_student = fields.Integer(required=True, validate=validate.Range(min=0))
reg_student = fields.Integer(required=True, validate=validate.Range(min=0), load_only=True)
id_professor = fields.Integer(required=True, validate=validate.Range(min=0))
discipline_code = fields.String(required=True, validate=validate.Length(max=80))
discipline_code = fields.String(required=True, validate=validate.Length(max=80), load_only=True)
content = fields.String(required=True, validate=validate.Length(min=1, max=480))
rating = fields.Float(required=True, validate=validate.Range(min=0, max=10))
is_anonymous = fields.Boolean(required=True)
Expand Down
4 changes: 3 additions & 1 deletion app/services/post_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ def undisagree_post(post_db, student_db):
def disagree_post(post_db, student_db):
post_db.disagrees.append(student_db)
db.session.commit()
return post_db, 200

return post_db, 200

6 changes: 0 additions & 6 deletions app/services/student_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def __validate_student_relationship(student):

return None, 200


def get_student_reg(reg_student):
student = Student.query.filter_by(reg_student=reg_student).first()
return student


def delete_student(student_db):
Student.delete(student_db)
return {'message': "Student successfully deleted!"}, 204
Expand Down
26 changes: 26 additions & 0 deletions tests/tests_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def valid_post_id(self):
"id_post": 1,
}

def get_posts(self, headers=None):
if headers is None:
headers = self.create_student_token()

return self.client.get(url_for('restapi.postlist'), headers = headers)


def register_post(self, post=None, headers=None):
if headers is None:
headers = self.create_student_token()
Expand Down Expand Up @@ -109,6 +116,25 @@ def test_api_must_validate_discipline_relationship_not_found(self):
self.assertEqual(response.status_code, 404)
self.assertEqual(response.json['message'], "Discipline not found!")

class TestGetPostList(TestFlaskBase):

def test_must_get_student_post_found_empty(self):
response = get_posts(self)
status_code_expected = 200

self.assertEqual(response.status_code, status_code_expected)
self.assertEqual(response.json, [])

def test_must_get_student_post_found(self):
register_post(self)
response = get_posts(self)
status_code_expected = 200
self.assertEqual(response.status_code, status_code_expected)





class TestPostAgree(TestFlaskBase):

def test_api_must_agree_post(self):
Expand Down

0 comments on commit b55f240

Please sign in to comment.