<commit_before># coding=utf-8
"""
"""
from __future__ import absolute_import

from pathlib import Path
import imghdr
from flask import url_for, request

from abilian.testing import BaseTestCase
from abilian.core.models.subjects import User
from abilian.web.preferences.user import UserPreferencesForm


AVATAR_COLORMAP = Path(__file__).parent / u'avatar-colormap.png'


class TestUserPreferences(BaseTestCase):

  def setUp(self):
    BaseTestCase.setUp(self)
    self.user = User(
      email=u'<EMAIL>',
      first_name=u'John', last_name=u'Doe', can_login=True)
    self.session.add(self.user)
    self.session.commit()

  def test_form_photo(self):
    url = url_for('preferences.user')
    photo = (AVATAR_COLORMAP.open('rb'), u'avatar.png', 'image/png')
    kwargs = dict(
        method='POST',
        data={'photo': photo,},
      )
    with self.app.test_request_context(url, **kwargs):
      form = UserPreferencesForm(request.form)
      form.validate()
      assert form.photo.data is not None
      img_type = imghdr.what('ignored', form.photo.data)
      assert img_type == 'jpeg'<commit_msg>fix test with new upload model<commit_after># coding=utf-8
"""
"""
from __future__ import absolute_import

from pathlib import Path
import imghdr
from flask import url_for, request

from abilian.testing import BaseTestCase
from abilian.core.models.subjects import User
from abilian.web.preferences.user import UserPreferencesForm


AVATAR_COLORMAP = Path(__file__).parent / u'avatar-colormap.png'


class TestUserPreferences(BaseTestCase):

  def setUp(self):
    BaseTestCase.setUp(self)
    self.user = User(
      email=u'<EMAIL>',
      first_name=u'John', last_name=u'Doe', can_login=True)
    self.session.add(self.user)
    self.session.commit()

  def test_form_photo(self):
    url = url_for('preferences.user')
    uploads = self.app.extensions['uploads']
    with AVATAR_COLORMAP.open('rb') as f:
      handle = uploads.add_file(self.user, f,
                                filename=u'avatar.png',
                                mimetype='image/png')

    kwargs = dict(
        method='POST',
        data={'photo': handle,},
      )

    with self.app.test_request_context(url, **kwargs):
      self.login(self.user)
      form = UserPreferencesForm(request.form)
      form.validate()
      assert form.photo.data is not None
      img_type = imghdr.what('ignored', form.photo.data)
      assert img_type == 'jpeg'
{'fraction_non_alphanumeric': 0.11853978671041837, 'fraction_numerical': 0.0008203445447087777, 'mean_word_length': 3.3945945945945946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6642803', 'n_tokens_mistral': 797, 'n_tokens_neox': 776, 'n_words': 162}