Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Implement event check-in handler #93

Merged
merged 5 commits into from
Feb 26, 2016

Conversation

phiNumber
Copy link
Collaborator

@phiNumber phiNumber commented Feb 25, 2016

Implements #72

orm_session = req.orm_session
reg_id = int(id)
reg_data = api.get_event_registration_by_id(orm_session, reg_id)
visit = EventParticipant(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this.

orm_session = req.orm_session
reg_id = int(id)
reg_data = api.get_event_registration_by_id(orm_session, reg_id)
reg_data.visited = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will end in exception if reg_data is None. Please move the check above this line.

reg_id = int(id)
reg_data = api.get_event_registration_by_id(orm_session, reg_id)
if not reg_data:
raise HTTPError(400, "Something wrong with registration")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more clear in error message:

'There is no registration record for id={id}'.format(id=reg_id)

@webknjaz
Copy link
Member

This PR looks working, but now we need to prove this with tests.
Plz implement some in https://github.com/GDG-Ukraine/gdg.org.ua/blob/master/src/tests/test_rest_controller.py file.
You may replace and drop lots of its contents, since it doesn't contain any real tests.

Add new data into DB inside of populate_db() function. It instantiates models, adds those to session and then commits data into DB.

Please check asserts available at http://docs.cherrypy.org/en/latest/pkg/cherrypy.test.html#cherrypy.test.webtest.WebCase
there's getPage() available for HTTP queries
You may check https://bitbucket.org/webknjaz/blueberrypy-wk/src/cb2753de29c4ec0f1be00baf2e828b35e0939b47/src/blueberrypy/tests/test_tools.py?at=default&fileviewer=file-view-default#test_tools.py-104 for some web test examples

P.S. You'll need to enable test_rest_controller test in tox.ini at line 18.

reg_id = int(id)
reg_data = api.get_event_registration_by_id(orm_session, reg_id)
if not reg_data:
raise HTTPError(400,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 400?
As I got the code right, reg_data will be None only in case we have no requested registration in database.
It will be a little bit more comprehensive if we return 404 Not Found error code in this case, won't it?

P.S. I do not insist on changing error code. I just want to understand why 400 Bad request?

P.P.S. @phiNumber I'm glad you joined this project ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't really know if situation with 'Not Found' registration could possibly exist. If I am not mistaken, reg_id should be valid and inherited from layer above. Thus the ways reg_data is not valid are:

  1. someone changed/deleted DB record for this participant between time when 'register' button appeared and pressed (which, as I understand, will be the source of id in request)
  2. code exception
  3. [non-realistic] someone put his own self-created id into request
    Please, correct me if I'm wrong.
    P.S. @anxolerd me too;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually (3) is realistic is case of hacking attempts.
Still, I agree w/ @anxolerd, 404 is more verbose. On the other hand, I wouldn't expose the reason of bad request. Let's consider changing this in other dev iteration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive reg_id from url. Thus someone (with sufficient privileges) can easily misspell id in the URL (like 1111 instead of 111) and get a Bad request error. However the actual reason is Not found.

@webknjaz webknjaz mentioned this pull request Feb 26, 2016
2 tasks
webknjaz added a commit that referenced this pull request Feb 26, 2016
Implement event check-in handler. Close #72
@webknjaz webknjaz merged commit c8edc16 into GDG-Ukraine:master Feb 26, 2016
@webknjaz
Copy link
Member

I'm merging this. Tests to be written later as a part of #94

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants