'When a source creates an account, test that a new entry appears
in the journalist interface'

def test_submit_file(self):

    test_file_contents = 'This    is    a    test    file.'
    test_filename = 'test.txt'
    with self.source_app as source_app:
        resp = source_app.get('/generate')
        resp = source_app.post('/create', follow_redirects=True)
        sid = g.sid
        resp = self.source_app.post('/submit', data=dict(msg='', fh=(StringIO(test_file_contents), test_filename)), follow_redirects=True)
        self.assertEqual(resp.status_code, 200)
        source_app.get('/logout')
    resp = self.journalist_app.get('/')
    self.assertEqual(resp.status_code, 200)
    self.assertIn('Sources', resp.data)
    soup = BeautifulSoup(resp.data, 'html.parser')
    col = soup.select('ul#cols    >    li')[0]
    unread_span = col.select('span.unread    a')[0]
    self.assertIn('1    unread', unread_span.get_text())
    col_url = soup.select('ul#cols    >    li    a')[0]['href']
    resp = self.journalist_app.get(col_url)
    self.assertEqual(resp.status_code, 200)
    soup = BeautifulSoup(resp.data, 'html.parser')
    submission_url = soup.select('ul#submissions    li    a')[0]['href']
    self.assertIn('-doc', submission_url)
    span = soup.select('ul#submissions    li    span.info    span')[0]
    self.assertRegexpMatches(span['title'], '\\d+    bytes')
    resp = self.journalist_app.get(submission_url)
    self.assertEqual(resp.status_code, 200)
    decrypted_data = self.gpg.decrypt(resp.data)
    self.assertTrue(decrypted_data.ok)
    sio = StringIO(decrypted_data.data)
    with gzip.GzipFile(mode='rb', fileobj=sio) as gzip_file:
        unzipped_decrypted_data = gzip_file.read()
    self.assertEqual(unzipped_decrypted_data, test_file_contents)
    resp = self.journalist_app.get(col_url)
    self.assertEqual(resp.status_code, 200)
    soup = BeautifulSoup(resp.data, 'html.parser')
    doc_name = soup.select('ul    >    li    >    input[name="doc_names_selected"]')[0]['value']
    resp = self.journalist_app.post('/bulk', data=dict(action='confirm_delete', sid=sid, doc_names_selected=doc_name))
    self.assertEqual(resp.status_code, 200)
    soup = BeautifulSoup(resp.data, 'html.parser')
    self.assertIn('The    following    file    has    been    selected    for', resp.data)
    doc_name = soup.select
    doc_name = soup.select('ul    >    li    >    input[name="doc_names_selected"]')[0]['value']
    resp = self.journalist_app.post('/bulk', data=dict(action='delete', sid=sid, doc_names_selected=doc_name), follow_redirects=True)
    self.assertEqual(resp.status_code, 200)
    soup = BeautifulSoup(resp.data, 'html.parser')
    self.assertIn('Submission    deleted.', resp.data)
    resp = self.journalist_app.get(col_url)
    self.assertEqual(resp.status_code, 200)
    self.assertIn('No    documents    to    display.', resp.data)
    utils.async.wait_for_assertion((lambda : self.assertFalse(os.path.exists(store.path(sid, doc_name)))))
