<commit_before>'use strict'
#
# FastChat
# 2015
#

should = require('chai').should()
AWS = require '../../lib/model/aws'
sinon = require 'sinon'

describe 'AWS', ->

  it 'should exist', ->
    should.exist AWS

  it 'should not create knox with no keys', ->
    aws = new AWS()
    should.not.exist aws.knox

  it 'should create knox with aws info', ->
    aws = new AWS('bucket', 'key', 'secret')
    should.exist aws.knox

  it 'should return an error without knox', ->
    aws = new AWS('bucket')
    aws.upload 'stream', 'name', {}, (err)->
      err.message.should.equal 'AWS_KEY or AWS_SECRET was not available! S3 access is disabled!'

  it 'fail to get without aws info', ->
    aws = new AWS('bucket')
    aws.on 'error', (err)->
      err.message.should.equal 'AWS_KEY or AWS_SECRET was not available! S3 access is disabled!'

    aws.get('name')<commit_msg>Added tests for upload and get.<commit_after>'use strict'
#
# FastChat
# 2015
#

should = require('chai').should()
AWS = require '../../lib/model/aws'
sinon = require 'sinon'
EventEmitter = require('events').EventEmitter

describe 'AWS', ->

  it 'should exist', ->
    should.exist AWS

  it 'should not create knox with no keys', ->
    aws = new AWS()
    should.not.exist aws.knox

  it 'should create knox with aws info', ->
    aws = new AWS('bucket', 'key', 'secret')
    should.exist aws.knox

  it 'should return an error without knox', ->
    aws = new AWS('bucket')
    aws.upload 'stream', 'name', {}, (err)->
      err.message.should.equal 'AWS_KEY or AWS_SECRET was not available! S3 access is disabled!'

  it 'fail to get without aws info', ->
    aws = new AWS('bucket')
    aws.on 'error', (err)->
      err.message.should.equal 'AWS_KEY or AWS_SECRET was not available! S3 access is disabled!'
    aws.get('name')

  it 'should upload with knox', (done)->
    process.env['AWS_KEY'] = 'test_key'
    process.env['AWS_SECRET'] = 'test_secret'
    aws = new AWS('bucket')
    stub = sinon.stub(aws.knox, 'putStream')
    aws.upload 'stream', 'name', {}, (err, res)->
      res.should.equal 'stream'
      process.env['AWS_KEY'] = undefined
      process.env['AWS_SECRET'] = undefined
      stub.restore()
      done()
    stub.yield(null, 'stream')

  it 'should fetch with knox', ->
    process.env['AWS_KEY'] = 'test_key'
    process.env['AWS_SECRET'] = 'test_secret'
    aws = new AWS('bucket')
    returned = new EventEmitter()
    stub = sinon.stub(aws.knox, 'get').returns(returned)
    aws.get('name').on 'response', (res)->
      res.should.equal 'rrr'
    returned.emit('response', 'rrr')
{'fraction_non_alphanumeric': 0.1602787456445993, 'fraction_numerical': 0.004645760743321719, 'mean_word_length': 3.1146496815286624, 'pattern_counts': {'":': 0, '<': 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': '6233986', 'n_tokens_mistral': 880, 'n_tokens_neox': 876, 'n_words': 254}