Closed Carla802 closed 1 year ago
Hi @Carla802
So there is no make test command you need to run.
What you need to run to start skyportal in testing mode is:
make db_clear && make db_init && make run_testing
(its the make run that changes as you can see`
Then, after monitoring the logs with a make log to see that the app started correctly, you can open another terminal, connect to your virtualenv and run pytest path_to_your_test
You might need to install pytest. For that, try adding it in the virtualenv first, but if you get any issue still, consider installing it outside of the virtualenv as well.
Keep me posted!
Hey @Theodlz ! 😄
As you asked, I followed your updated version of the tutorial. I created all the files that needed to be created, and added every line in the different existing files.
When I'm running the app, the front-end part of the comment section is displayed on the http://localhost:5000/test_comments page. However, when I try to submit a new comment, this error appears (both in the app and in my logs) :
[22:50:06 basehandler] Error response returned by [/api/test_comments]: [HTTP 405: Method Not Allowed]
(this is the line from the logs)
I think I understand that there is an issue coming from the skyportal/handlers/api/test_comment.py file, even though it is exactly like yours.
from baselayer.app.access import auth_or_token
from ..base import BaseHandler
from ...models import TestComment
class TestCommentHandler(BaseHandler):
@auth_or_token
def get(self):
# If we wanted to do any query filtering, this is where that would happen
with self.Session() as session:
comments = session.scalars(
TestComment.select(session.user_or_token)
).all()
return self.success(data=comments)
@auth_or_token
def post(self):
data = self.get_json()
comment_text = data.get("commentText")
if comment_text is None or comment_text == "":
return self.error("`commentText` must be provided as a non-empty string")
with self.Session() as session:
comment = TestComment(
text=comment_text,
author_id=session.user_or_token.id,
)
session.add(comment)
session.commit()
self.push_all(action='skyportal/FETCH_TEST_COMMENTS')
return self.success(data=comment)
Is there a problem in the file itself, or did I do something wrong maybe in another file ?
When I tried to run the app after all the changes in the code, I only did a make run
(and make log
). Do I also need to run a make db_init
or something like that before running the app with the changes ?
Thank you for your help 🚀
Hi @Carla802, you need to change the author_id
to user_id
. My apologizes I made that error. It had already corrected it, but naturally only on the PR not on the ZIP file I already posted. However, you can notice that it is an error quite easily. As you can see, there is no author_id
column in the TestComment model in skyportal\models\test_comments.py
Please always try to have a look at the different arguments you pass to classes. Small errors like this one happen easily.
When you add a new table, its a good thing to restart the app with a make db_init and make run to ensure that the new table is created.
Thank you for your explanations @Theodlz ! I corrected this line in /api/test_comment and I also checked if the rest of the code was the same as yours (directly from your pull request). It seems to be correct but when I run the app the same error still appears... I also get a "Invalid API endpoint" when opening the test_comments page. I thought it was an error in the app_server file, where the API endpoints are defined, but the lines I added are the right ones and I think I also put them at the right location... I compared my code with @lydie10's to be sure, she did the same, and her code works ! I put the handler's path at the top of the skyportal_handlers list.
Sorry to bother you with another error, I must have done something wrong but can't seem to find my mistake. I hope I will get better at understanding my errors by myself !
Hi @Carla802 .
I suggest you ask @lydie10 to open a pull request (of for example her branch of the tutorial, to the main branch of her fork).
That way you can FOR SURE compared your code with hers without missing anything.
Best even, from your tutorial branch you open a PR to HER tutorial branch, which will highlight the differences between the 2.
If it cant find the api route when you try to.use the page on the frontend, its either an error in the ducks or the app_server.py.
Hi @Theodlz ,
It was in fact an /api/test_comment wrote as /api/test_commentS in the ducks file... Thank you for your help, my comment section finally works ! 😄
I will now implement the test file and it should be good.
Hi @Theodlz 😄
Even though I opened an issue concerning SkyPortal installation, I can still update you on the Adding new features tutorial.
Before having trouble reinstalling SkyPortal, I was testing my implemented code to add a Comment section on SkyPortal, and an error occurred with the
make test
command. Apparently there was something wrong on the skyportal/tests/frontend/test_comments.py file.I will come back to this issue with more details when I can run SkyPortal again !
Thank you again 🚀