<commit_before>import model
from app import app
import unittest
import tempfile
import hashlib
from StringIO import StringIO
import os

class UploadTestCase(unittest.TestCase):
    def setUp(self):
        app.config['DATABASE'] = 'sqlite:///:memory:'
        with app.app_context():
            model.database.connect()
            model.syncdb()

        app.config['UPLOAD_PATH'] = tempfile.mkdtemp()
        self.app = app.test_client()
        self.app.post('/index', data={'body': '', 'message': ''})

    def test_empty_upload(self):
      self.app.post('/index/attach', data={
        'file': (StringIO(''), 'empty.txt')
      })
      sha = hashlib.sha256()
      sha.update('')
      emptySha = sha.hexdigest()
      uploadedFile = os.path.join(app.config['UPLOAD_PATH'],
        model.Attachment.hashPath(emptySha, 'empty.txt'))

      self.assertTrue(os.path.exists(uploadedFile))
      self.assertEqual(self.app.get('/index/file/empty_txt').data, '')

    def test_simple_upload(self):
      self.app.post('/index/attach', data={
        'file': (StringIO('FOOBAR'), 'foo.bar')
      })
      sha = hashlib.sha256()
      sha.update('FOOBAR')
      emptySha = sha.hexdigest()
      uploadedFile = os.path.join(app.config['UPLOAD_PATH'],
        model.Attachment.hashPath(emptySha, 'foo.bar'))

      self.assertTrue(os.path.exists(uploadedFile))
      self.assertEqual(self.app.get('/index/file/foo_bar').data, 'FOOBAR')
<commit_msg>Also test response status code for uploads<commit_after>import model
from app import app
import unittest
import tempfile
import hashlib
from StringIO import StringIO
import os

class UploadTestCase(unittest.TestCase):
    def setUp(self):
        app.config['DATABASE'] = 'sqlite:///:memory:'
        with app.app_context():
            model.database.connect()
            model.syncdb()

        app.config['UPLOAD_PATH'] = tempfile.mkdtemp()
        self.app = app.test_client()
        self.app.post('/index', data={'body': '', 'message': ''})

    def test_empty_upload(self):
      self.app.post('/index/attach', data={
        'file': (StringIO(''), 'empty.txt')
      })
      sha = hashlib.sha256()
      sha.update('')
      emptySha = sha.hexdigest()
      uploadedFile = os.path.join(app.config['UPLOAD_PATH'],
        model.Attachment.hashPath(emptySha, 'empty.txt'))

      self.assertTrue(os.path.exists(uploadedFile))
      resp = self.app.get('/index/file/empty_txt')
      self.assertEqual(resp.status, 200)
      self.assertEqual(resp.data, '')

    def test_simple_upload(self):
      self.app.post('/index/attach', data={
        'file': (StringIO('FOOBAR'), 'foo.bar')
      })
      sha = hashlib.sha256()
      sha.update('FOOBAR')
      emptySha = sha.hexdigest()
      uploadedFile = os.path.join(app.config['UPLOAD_PATH'],
        model.Attachment.hashPath(emptySha, 'foo.bar'))

      self.assertTrue(os.path.exists(uploadedFile))
      resp = self.app.get('/index/file/foo_bar')
      self.assertEqual(resp.status, 200)
      self.assertEqual(resp.data, 'FOOBAR')

{'fraction_non_alphanumeric': 0.15992102665350444, 'fraction_numerical': 0.005923000987166831, 'mean_word_length': 2.973856209150327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3264173', 'n_tokens_mistral': 991, 'n_tokens_neox': 987, 'n_words': 158}