Beispiel #1
0
    def test_constructor(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)
        self.assertEqual(poll.title, "TestTitle")
        self.assertEqual(poll.id, 13)

        self.assertEqual(poll.get_winners(), ["1", "2", "3"])
Beispiel #2
0
    def test_serialize(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)

        self.assertEqual(
            poll.serialize(), {
                "id": poll.id,
                "title": poll.title,
                "options": poll.options,
                "winners": ["1", "2", "3"]
            })
Beispiel #3
0
    def test_votes_delete(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)
        poll.vote("Wilma", "1")
        poll.vote("Fred", "2")
        poll.delete_voted_options("Fred")

        self.assertEqual(poll.get_winners(), ["1"])
Beispiel #4
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    json = request.get_json()
    _POLLNUMBER += 1
    _ACTIVEPOLLS[str(_POLLNUMBER)] = (Poll(_POLLNUMBER, json['title'],
                                           json['options']))
    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #5
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER

    request_data = request.get_json()
    title = request_data['title']
    options = request_data['options']


    if not type(options) is list:
        #invalid data structure as options.
        abort(400)

    if not type(title) is str:
        #invalid data structure as title
        abort(400)
    #everything alright, then go ahead and actually create the poll!

    #now take the options and form an 'options dictionary'
    options_dictionary = {}
    empty_list = []

    for option in options:
        options_dictionary[option] = empty_list

    _POLLNUMBER += 1
    new_poll = Poll(_POLLNUMBER, title, options_dictionary)

    #now add the newly created object to the list of polls
    #the ID is the cur_poll_number. We'll need to number to retrieve the poll later on
    _ACTIVEPOLLS[_POLLNUMBER] = new_poll

    #finally, increment the poll number, but return the previous one

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #6
0
def create_doodle(data):
    global _ACTIVEPOLLS, _POLLNUMBER
    #create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.
    _POLLNUMBER += 1
    _ACTIVEPOLLS.update(
        {_POLLNUMBER: Poll(_POLLNUMBER, data["title"], data["options"])})
    return jsonify(pollnumber=_POLLNUMBER)
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    #TODO: create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.
    json = request.get_json()
    _POLLNUMBER += 1
    _ACTIVEPOLLS[_POLLNUMBER] = Poll(_POLLNUMBER, json['title'],
                                     json['options'])

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #8
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER

    json_data = request.get_json()  ## FLAG
    _POLLNUMBER = _POLLNUMBER + 1
    _ACTIVEPOLLS[str(_POLLNUMBER)] = Poll(_POLLNUMBER, json_data['title'],
                                          json_data['options'])

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #9
0
def create_doodle(request):
    #TODO: completed, create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.
    global _ACTIVEPOLLS, _POLLNUMBER
    pool_request = request.get_json()
    title = pool_request['title']
    options = pool_request['options']
    _POLLNUMBER += 1
    p = Poll(_POLLNUMBER, title, options)
    _ACTIVEPOLLS[p.id] = p
    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #10
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER

    json = request.get_json()
    title = json['title']
    options = json['options']
    _POLLNUMBER += 1
    tmp = Poll(_POLLNUMBER, title, options)
    _ACTIVEPOLLS[_POLLNUMBER] = tmp
    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #11
0
def create_doodle(request):

    global _ACTIVEPOLLS, _POLLNUMBER

    json_data = request.get_json()
    title = json_data['title']
    options = json_data['options']
    _POLLNUMBER += 1
    _ACTIVEPOLLS[str(_POLLNUMBER)] = Poll(_POLLNUMBER, title, options)

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #12
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    #TODO: create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.

    _POLLNUMBER += 1
    json_data = request.get_json()
    title = json_data['title']
    options = json_data['options']
    newdoodle = Poll(_POLLNUMBER, title, options)
    _ACTIVEPOLLS[_POLLNUMBER] = newdoodle
    return jsonify({'pollnumber': _POLLNUMBER})
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER

    data = request.get_json()

    _POLLNUMBER += 1

    newPoll = Poll(_POLLNUMBER, data['title'], data['options'])

    _ACTIVEPOLLS[_POLLNUMBER] = newPoll

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #14
0
def create_doodle(
    request
):  #create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.
    global _ACTIVEPOLLS, _POLLNUMBER
    print(request.get_json())
    jsonRequest = request.get_json()
    if 'title' in jsonRequest and 'options' in jsonRequest:
        _POLLNUMBER += 1
        _ACTIVEPOLLS[str(_POLLNUMBER)] = Poll(_POLLNUMBER,
                                              jsonRequest['title'],
                                              jsonRequest['options'])
        return jsonify({'pollnumber': _POLLNUMBER})

    return abort(400)  # Bad Request
Beispiel #15
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER

    data_dict = json.loads(request.data)
    try:
        title = data_dict['title']
        options = data_dict['options']

    except KeyError:
        abort_bad_request()

    _POLLNUMBER += 1
    _ACTIVEPOLLS[str(_POLLNUMBER)] = Poll(_POLLNUMBER, title, options)

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #16
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    #Increment the _POLLNUMBER identifier
    _POLLNUMBER = _POLLNUMBER + 1

    # Extract title and options fields from the JSON request
    title = request.json['title']  # poll's title
    options = request.json['options']

    # Definition of a new Poll, the parameters are the id,title and options
    poll = Poll(_POLLNUMBER, title, options)

    # Updating the list of the polls
    _ACTIVEPOLLS[_POLLNUMBER] = poll

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #17
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    #TODO: create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.

    data = request.get_json()

    # Create a new Poll with input data
    poll = Poll(_POLLNUMBER + 1, data['title'], data['options'])

    # Add the poll to the list of active polls
    _ACTIVEPOLLS[_POLLNUMBER + 1] = poll

    # Increase the number of polls
    _POLLNUMBER += 1

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #18
0
def create_doodle(request):
    global _ACTIVEPOLLS, _POLLNUMBER
    #TODO: create a new poll in _ACTIVEPOLLS based on the input JSON. Update _POLLNUMBER by incrementing it.
    jreq = request.get_json(silent=True)
    if (jreq == None):
        abort(400)
        return

    try:
        _POLLNUMBER += 1
        title: str = jreq['title']
        opts: dict = jreq['options']
        id: str = str(_POLLNUMBER)

        poll: Poll = Poll(id, title, opts)
        _ACTIVEPOLLS[id] = poll

    except:
        return abort(400)

    return jsonify({'pollnumber': _POLLNUMBER})
Beispiel #19
0
    def test_single_vote(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)
        poll.vote("Wilma", "1")

        self.assertEqual(poll.get_winners(), ["1"])
Beispiel #20
0
    def test_already_voted(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)
        poll.vote("Wilma", "1")

        self.assertRaises(UserAlreadyVotedException, poll.vote, "Wilma", "1")
Beispiel #21
0
    def test_not_existing_option(self):
        options = ["1", "2", "3"]
        poll = Poll(13, "TestTitle", options)

        self.assertRaises(NonExistingOptionException, poll.vote, "Wilma", "5")