<commit_before>import json
import os
import random
import sys
import time
import pymongo
import requests
from selenium import webdriver
from flask import Flask, jsonify, redirect, request
app = Flask(__name__)
app.debug = True

db = pymongo.Connection(os.getenv('MONGOLAB_URI')).get_default_database()

__email_chars = 'abcdefghijklmnopqrstuvwxyz1234567890'


def __random():
    res = ''
    while len(res) < 10:
        res += random.choice(__email_chars)
    return res


def __webdriver():
    if '--firefox' in sys.argv:
        return webdriver.Firefox()
    elif '--macphantom' in sys.argv:
        return webdriver.PhantomJS('phantomjs/bin/phantomjs')
    else:
        return webdriver.PhantomJS('phantomjs-1.9.7-linux-x86_64/bin/phantomjs')

    # helps avoid element visibility errors by setting a realistic size
    driver.set_window_size(1028, 768)


def signup(driver, url, params):
    driver.get('https://events.developerforce.com/signup')
    time.sleep(1)
    for k, v in vals.items():
        f = driver.find_element_by_id(k)
        if f and f.is_displayed() and f.is_enabled():
            f.send_keys(v)

    country_field = driver.find_element_by_id('country')
    for o in country_field.find_elements_by_tag_name('option'):
        if o.get_attribute('value').lower() == 'us':
            o.click()
            break
    driver.find_element_by_id('eula').click()
    driver.find_element_by_id('submit_btn').click()

    # TODO assert that we see the thanks page with status code 200


@app.route("/")  # TODO set to post
def hello():
    request_time = time.time()
    rand = __random()
    driver = __webdriver()
    vals = {
        'email': '<EMAIL>',
        'username': <EMAIL>' % rand,
        'first_name': 'developer',
        'last_name': 'developer',
        'company': 'developer',
        'postal_code': '02144',
    }
    try:
        signup(driver, 'https://events.developerforce.com/signup', vals)
    except Exception as e:
        vals.update({'exception': repr(e)})

    vals.update({'headers': dict(request.headers.items())})
    vals.update({'id': rand})
    vals.update({'request_time': request_time})
    db['account'].save(vals)

    driver.quit()

    return redirect('/account/%s' % rand)


@app.route('/callback', methods=['POST'])
def callback():
    print request.headers
    print request.data
    db['email'].save(json.loads(request.data))
    return jsonify({'status': 'ok'})


@app.route('/account/<id>')
def finish(id):
    result = {
        'id': id,
        'status': 'awaiting_activation_email',
        'details': db['account'].find_one({'id': id})
    }
    # can't url json mongo id
    del result['details']['_id']

    return jsonify(result)




if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0')<commit_msg>mandrill tests are blank post body<commit_after>import json
import os
import random
import sys
import time
import pymongo
import requests
from selenium import webdriver
from flask import Flask, jsonify, redirect, request
app = Flask(__name__)
app.debug = True

db = pymongo.Connection(os.getenv('MONGOLAB_URI')).get_default_database()

__email_chars = 'abcdefghijklmnopqrstuvwxyz1234567890'


def __random():
    res = ''
    while len(res) < 10:
        res += random.choice(__email_chars)
    return res


def __webdriver():
    if '--firefox' in sys.argv:
        return webdriver.Firefox()
    elif '--macphantom' in sys.argv:
        return webdriver.PhantomJS('phantomjs/bin/phantomjs')
    else:
        return webdriver.PhantomJS('phantomjs-1.9.7-linux-x86_64/bin/phantomjs')

    # helps avoid element visibility errors by setting a realistic size
    driver.set_window_size(1028, 768)


def signup(driver, url, params):
    driver.get('https://events.developerforce.com/signup')
    time.sleep(1)
    for k, v in vals.items():
        f = driver.find_element_by_id(k)
        if f and f.is_displayed() and f.is_enabled():
            f.send_keys(v)

    country_field = driver.find_element_by_id('country')
    for o in country_field.find_elements_by_tag_name('option'):
        if o.get_attribute('value').lower() == 'us':
            o.click()
            break
    driver.find_element_by_id('eula').click()
    driver.find_element_by_id('submit_btn').click()

    # TODO assert that we see the thanks page with status code 200


@app.route("/")  # TODO set to post
def hello():
    request_time = time.time()
    rand = __random()
    driver = __webdriver()
    vals = {
        'email': '<EMAIL>',
        'username': <EMAIL>' % rand,
        'first_name': 'developer',
        'last_name': 'developer',
        'company': 'developer',
        'postal_code': '02144',
    }
    try:
        signup(driver, 'https://events.developerforce.com/signup', vals)
    except Exception as e:
        vals.update({'exception': repr(e)})

    vals.update({'headers': dict(request.headers.items())})
    vals.update({'id': rand})
    vals.update({'request_time': request_time})
    db['account'].save(vals)

    driver.quit()

    return redirect('/account/%s' % rand)


@app.route('/callback', methods=['POST'])
def callback():
    if request.data:
        db['email'].save(json.loads(request.data))
    return jsonify({'status': 'ok'})


@app.route('/account/<id>')
def finish(id):
    result = {
        'id': id,
        'status': 'awaiting_activation_email',
        'details': db['account'].find_one({'id': id})
    }
    # can't url json mongo id
    del result['details']['_id']

    return jsonify(result)




if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0')
{'fraction_non_alphanumeric': 0.14703245472476242, 'fraction_numerical': 0.013986013986013986, 'mean_word_length': 3.165795369678865, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1278748', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1813, 'n_words': 406}