def test_delete_meeting_request(app, monkeypatch, database, fake_user): monkeypatch.setattr(meeting_requests, 'get_user', lambda: fake_user) meeting_spec_key = database.specs[0].key.urlsafe() meeting_request = MeetingRequest( meeting_spec=database.specs[0].key, user=fake_user.key ) meeting_request_key = meeting_request.put() meeting_request_key = meeting_request_key.urlsafe() requests = MeetingRequest.query().fetch() assert len(requests) == 1 with app.test_request_context( '/v1/meeting_request/', method='POST', data=json.dumps({ 'meeting_spec_key': meeting_spec_key, 'meeting_request_key': meeting_request_key }), content_type='application/json' ): response = create_delete_meeting_request() assert json.loads(response) == {'key': ''} requests = MeetingRequest.query().fetch() assert len(requests) == 0
def create_delete_meeting_request(): user = get_user() data = request.json meeting_spec_key = data['meeting_spec_key'] meeting_request_key = data['meeting_request_key'] if meeting_request_key == '': meeting_spec = ndb.Key(urlsafe=meeting_spec_key) if not meeting_spec: return 400 meeting_request = query_meeting_request(meeting_spec, user) if not meeting_request: meeting_request = MeetingRequest(meeting_spec=meeting_spec, user=user.key) meeting_request.put() return json.dumps({'key': meeting_request.key.urlsafe()}) else: meeting_request = ndb.Key(urlsafe=meeting_request_key) meeting_request.delete() return json.dumps({'key': ''})
def test_get_meeting_request(app, monkeypatch, database, fake_user): monkeypatch.setattr(meeting_requests, 'get_user', lambda (x): fake_user) meeting_spec_key = database.specs[0].key.urlsafe() meeting_request = MeetingRequest(meeting_spec=database.specs[0].key, user=fake_user.key) meeting_request_key = meeting_request.put() requests = MeetingRequest.query().fetch() assert len(requests) == 1 with app.test_request_context('/v1/meeting_request/' + meeting_spec_key): response = get_meeting_request(meeting_spec_key).json assert response == {'key': meeting_request_key.urlsafe()}