示例#1
0
def test_validate_uuid():
    invalid_uuid = "INVALID"
    res = validate_uuid(invalid_uuid)
    assert res == False

    valid_uuid = "84b9cfd3b8124023b8be4d43720d179a"
    res = validate_uuid(valid_uuid)
    assert res == True
def test_validate_uuid():
    wrong_uuid_string = '12e21e8474feaa930ii112o'
    right_uuid_string = '12e21e8474fe43c3a9909476ac899345'

    valueUUID = UUID(right_uuid_string, version=4)

    exceptionReturnValue = validate_uuid(wrong_uuid_string)
    rightReturnValue = validate_uuid(right_uuid_string)

    assert exceptionReturnValue == False
    assert rightReturnValue == True
    assert valueUUID.hex == right_uuid_string
示例#3
0
    def get_pingouts_occur_specific_date(pingout_uuid):
        if validate_uuid(pingout_uuid):
            pingout = collection.find_one({'uuid': pingout_uuid})
            if pingout:
                date = request.args.get('date')
                try:
                    date = parser.parse(date)
                except TypeError:
                    return Response(status=400)
                try:
                    query = filter_occurrences_ping_specific_date(
                        pingout_uuid, collection, date)
                except KeyError:
                    response = jsonify(
                        error="Pingout without pings received on this date!")
                    response.status_code = 400
                    return response
                filename = '{}.csv'.format(pingout_uuid)
                from_json_to_csv(query, filename)
                url = url_for('download_file',
                              pingout_uuid=pingout_uuid,
                              filename=filename,
                              _external=True)
                response = jsonify(message="File created with success!",
                                   url=url)
                response.status_code = 200

                return response
            else:
                return Response(status=404)
示例#4
0
 def ping(pingout_uuid):
     if validate_uuid(pingout_uuid):
         pingout = collection.find_one({'uuid': pingout_uuid})
         if pingout:
             date = datetime.datetime.today().replace(second=0,
                                                      microsecond=0)
             if len(pingout['pings']) == 0:
                 collection.update_one(
                     {'uuid': pingout_uuid},
                     {'$push': {
                         'pings': {
                             'count': 1,
                             'date': date
                         }
                     }})
             else:
                 count = pingout['pings'][-1]['count']
                 collection.update_one({'uuid': pingout_uuid}, {
                     '$push': {
                         'pings': {
                             'count': count + 1,
                             'date': date
                         }
                     }
                 })
             return Response(status=201)
         else:
             response = jsonify(errors='Pingout not found')
             response.status_code = 404
             return response
     else:
         response = jsonify(errors='Bad format uuid')
         response.status_code = 400
         return response
示例#5
0
    def get_pingouts_occur_range_date(pingout_uuid):
        if validate_uuid(pingout_uuid):
            pingout = collection.find_one({'uuid': pingout_uuid})
            if pingout:
                initial = request.args.get('initial_date')
                final = request.args.get('final_date')
                try:
                    initial = parser.parse(initial)
                    final = parser.parse(final)
                except TypeError:
                    return Response(status=400)
                query = filter_occurrences_ping_range_date(
                    pingout_uuid, collection, initial, final)
                filename = '{}.csv'.format(pingout_uuid)
                from_json_to_csv(query, filename)
                url = url_for('download_file',
                              pingout_uuid=pingout_uuid,
                              filename=filename,
                              _external=True)
                response = jsonify(message="File created with success!",
                                   url=url)
                response.status_code = 200

                return response
            else:
                return Response(status=404)
示例#6
0
    def get_pingout(pingout_uuid):
        if validate_uuid(pingout_uuid):
            pingout = collection.find_one({'uuid': pingout_uuid})
            if pingout:
                pingout.pop('_id')
                response = jsonify(pingout=pingout)
                response.status_code = 200

                return response
            else:
                response = jsonify(errors='Pingout not found')
                response.status_code = 404
                return response
        else:
            response = jsonify(errors='Bad format uuid')
            response.status_code = 400
            return response
示例#7
0
 def get_pingouts_occur_range_date(pingout_uuid):
     if validate_uuid(pingout_uuid):
         pingout = collection.find_one({'uuid': pingout_uuid})
         if pingout:
             initial = request.args.get('initial_date')
             final = request.args.get('final_date')
             try:
                 initial = parser.parse(initial)
                 final = parser.parse(final)
             except TypeError:
                 return Response(status=400)
             query = filter_occurrences_ping_range_date(
                 pingout_uuid, collection, initial, final)
             from_json_to_csv(query, "{}.csv".format(pingout_uuid))
             return redirect('/{}/download'.format(pingout_uuid))
         else:
             return Response(status=404)
示例#8
0
def test_return_valid_uuid4_post_on_create_pingout(client):
    """ Return valid uuid version 4 when post on create_pingout url """
    response = client.post('/create-pingout')
    assert validate_uuid(response.json['uuid'])
示例#9
0
def test_invalid_UUID_is_validated():
    # It's an invalid UUID because it has a 'g', which hexadecimal values can't have
    invalid_uuid = '3106a663a8g642b8bd79dac0469bd739'
    validation = validate_uuid(invalid_uuid)
    assert validation == False
示例#10
0
def test_valid_UUID_is_validated():
    valid_uuid = '3106a663a8f642b8bd79dac0469bd739'
    validation = validate_uuid(valid_uuid)
    assert validation == True