<commit_before>_           = require 'underscore'
hat         = require 'hat'
async       = require 'async'
Bongo       = require 'bongo'
Cookie      = require 'tough-cookie'
request     = require 'request'
querystring = require 'querystring'

KONFIG      = require 'koding-config-manager'
mongo       = KONFIG.mongoReplSet or "mongodb://#{KONFIG.mongo}"
{ expect }  = require 'chai'


checkBongoConnectivity = (callback) ->

  bongo = new Bongo
    root   : __dirname
    mongo  : mongo
    models : ''

  bongo.once 'dbClientReady', ->
    callback()


# returns 20 characters by default
generateRandomString = (length = 20) -> hat().slice(32 - length)


generateRandomEmail = (domain = 'koding.com') ->

  return "kodingtestuser+#{generateRandomString()}@#{domain}"


generateRandomInvitationsWithEmailRole = (domain = 'koding.com') ->

  return "kodingtestuser+#{generateRandomString()}@#{domain},,,member"


generateRandomUsername = -> generateRandomString()


generateUrl = (opts = {}) ->

  getRoute = (route) ->
    if    route
    then  "/#{route}"
    else  ''

  getSubdomain = (subdomain) ->
    if    subdomain
    then  "#{subdomain}."
    else  ''

  urlParts =
    hostname  : KONFIG.domains.base
    port      : ':8090'
    route     : ''
    protocol  : 'http://'
    subdomain : ''

  urlParts = _.extend urlParts, opts

  url =
    urlParts.protocol +
    getSubdomain(urlParts.subdomain) +
    urlParts.hostname +
    urlParts.port +
    getRoute(urlParts.route)

  return url


generateDefaultHeadersObject = (opts = {}) ->

  userAgent =<commit_msg>Get public port from KONFIG object<commit_after>_           = require 'underscore'
hat         = require 'hat'
async       = require 'async'
Bongo       = require 'bongo'
Cookie      = require 'tough-cookie'
request     = require 'request'
querystring = require 'querystring'

KONFIG      = require 'koding-config-manager'
mongo       = KONFIG.mongoReplSet or "mongodb://#{KONFIG.mongo}"
{ expect }  = require 'chai'


checkBongoConnectivity = (callback) ->

  bongo = new Bongo
    root   : __dirname
    mongo  : mongo
    models : ''

  bongo.once 'dbClientReady', ->
    callback()


# returns 20 characters by default
generateRandomString = (length = 20) -> hat().slice(32 - length)


generateRandomEmail = (domain = 'koding.com') ->

  return "kodingtestuser+#{generateRandomString()}@#{domain}"


generateRandomInvitationsWithEmailRole = (domain = 'koding.com') ->

  return "kodingtestuser+#{generateRandomString()}@#{domain},,,member"


generateRandomUsername = -> generateRandomString()


generateUrl = (opts = {}) ->

  getRoute = (route) ->
    if    route
    then  "/#{route}"
    else  ''

  getSubdomain = (subdomain) ->
    if    subdomain
    then  "#{subdomain}."
    else  ''

  urlParts =
    hostname  : KONFIG.domains.base
    port      : ":#{KONFIG.publicPort}"
    route     : ''
    protocol  : 'http://'
    subdomain : ''

  urlParts = _.extend urlParts, opts

  url =
    urlParts.protocol +
    getSubdomain(urlParts.subdomain) +
    urlParts.hostname +
    urlParts.port +
    getRoute(urlParts.route)

  return url


generateDefaultHeadersObject = (opts = {}) ->

  userAgent =
{'fraction_non_alphanumeric': 0.13203395158755107, 'fraction_numerical': 0.005029864822382898, 'mean_word_length': 2.9042944785276075, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6792113', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1017, 'n_words': 217}