<commit_before># coding: utf-8
import unittest
from google.appengine.ext import ndb, testbed
from werkzeug.security import generate_password_hash
from flask import session, request
from datetime import date

from edaemon.ndbmodels import User, Change, _format_date_ISO8601
import app as Edaemon

class AdminChangesTestcase(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()

        self.app = Edaemon.app.test_client()

        self.user = User(
            email='<EMAIL>', passwd=generate_password_hash('<PASSWORD>'))
        self.user.put()

    def tearDown(self):
        self.testbed.deactivate()

    def login(self, c):
        rv = c.get('/a/login', follow_redirects=True)
        if not '<EMAIL>' in rv.data:
            rv = c.post('/a/login', follow_redirects=True, data=dict(
                email='<EMAIL>', passwd='<PASSWORD>', _xsrf=session['xsrf']))
            assert '<EMAIL>' in rv.data

    def create_change(self, c, data=None):
        today = _format_date_ISO8601(date.today())
        _data = dict()
        if data is None:
            _data = dict(className='0.a', date=today)
        else:
            _data = data
        rv = c.post('/a/changes/new', follow_redirects=True, data=_data)
        return (rv, request.view_args['change_id'])

    def test_admin_change_create(self):
        today = _format_date_ISO8601(date.today())
        with self.app as c:
            self.login(c)
            rv, change_id = self.create_change(c, dict(
                className='99.z', date=today,
                subject_0='-', subject_1='Test Subject 1', subject_2='-',
                subject_3='Test Subject 3', subject_6='Test Subject 6',
                subject_9='Test Subject 9', subject_none='Test Subject None'))
            assert '99.z' in rv.data
            assert today in rv.data
            assert 'Test Subject 1' in rv.data
            assert 'Test Subject 3' in rv.data
            assert 'Test Subject 6' in rv.data
            assert not 'Test Subject 9' in rv.data
            assert not 'Test Subject None' in rv.data
            change = Change.lookup(request.view_args['change_id'])
            subjects = json.loads(change['changes'])
            assert subjects.length == 9

    def test_admin_change_delete(self):
        with self.app as c:
            self.login(c)
            rv, change_id = self.create_change(c)
            rv = c.post('/a/changes/delete/{0}'.format(change_id),
                follow_redirects=True)
            assert 'Neatradu!' in rv.data

    def test_admin_changes_list(self):
        today = _format_date_ISO8601(date.today())
        with self.app as c:
            self.login(c)<commit_msg>tests: fix admin_changes not running<commit_after># coding: utf-8
import unittest
from google.appengine.ext import ndb, testbed
from werkzeug.security import generate_password_hash
from flask import session, request
from datetime import date
import json

from edaemon.ndbmodels import User, Change, _format_date_ISO8601
import app as Edaemon

class AdminChangesTestcase(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()

        self.app = Edaemon.app.test_client()

        self.user = User(
            email='<EMAIL>', passwd=generate_password_hash('<PASSWORD>'))
        self.user.put()

    def tearDown(self):
        self.testbed.deactivate()

    def login(self, c):
        rv = c.get('/a/login', follow_redirects=True)
        if not '<EMAIL>' in rv.data:
            rv = c.post('/a/login', follow_redirects=True, data=dict(
                email='<EMAIL>', passwd='<PASSWORD>', _xsrf=session['xsrf']))
            assert '<EMAIL>' in rv.data

    def create_change(self, c, data=None):
        today = _format_date_ISO8601(date.today())
        _data = dict()
        if data is None:
            _data = dict(className='0.a', date=today)
        else:
            _data = data
        rv = c.post('/a/changes/new', follow_redirects=True, data=_data)
        return (rv, request.view_args['change_id'])

    def test_admin_change_create(self):
        today = _format_date_ISO8601(date.today())
        with self.app as c:
            self.login(c)
            rv, change_id = self.create_change(c, dict(
                className='99.z', date=today,
                subject_0='-', subject_1='Test Subject 1', subject_2='-',
                subject_3='Test Subject 3', subject_6='Test Subject 6',
                subject_9='Test Subject 9', subject_none='Test Subject None'))
            assert '99.z' in rv.data
            assert today in rv.data
            assert 'Test Subject 1' in rv.data
            assert 'Test Subject 3' in rv.data
            assert 'Test Subject 6' in rv.data
            assert not 'Test Subject 9' in rv.data
            assert not 'Test Subject None' in rv.data
            change = Change.lookup(request.view_args['change_id'])
            subjects = json.loads(change.changes)
            assert len(subjects) == 9

    def test_admin_change_delete(self):
        with self.app as c:
            self.login(c)
            rv, change_id = self.create_change(c)
            rv = c.post('/a/changes/delete/{0}'.format(change_id),
                follow_redirects=True)
            assert 'Neatradu!' in rv.data

    def test_admin_changes_list(self):
        today = _format_date_ISO8601(date.today())
        with self.app as c:
            self.login(c)
{'fraction_non_alphanumeric': 0.11387343532684284, 'fraction_numerical': 0.013560500695410291, 'mean_word_length': 2.3044227455485355, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4982891', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1733, 'n_words': 415}