<commit_before>#!/usr/bin/env python
from flask.ext.login import AnonymousUserMixin

from tests.prepare import AppInitialized
from sipa.model.sqlalchemy import db
from sipa.model.hss.schema import Account, Access, IP
from sipa.model.hss.user import User


class HssPgTestBase(AppInitialized):
    def create_app(self):
        test_app = super().create_app(additional_config={
            'WU_CONNECTION_STRING': "sqlite:///",
            'HSS_CONNECTION_STRING': "postgresql://sipa:password@postgres:5432/",
            'DB_HELIOS_IP_MASK': "10.10.7.%",
        })
        return test_app

    def setUp(self):
        db.drop_all(bind='hss')
        db.create_all(bind='hss')
        self.session = db.session


class HSSPgEmptyTestCase(HssPgTestBase):
    def test_no_accounts_existent(self):
        self.assertFalse(self.session.query(Account).all())


class FixtureLoaderMixin:
    """A Mixin that creates `self.fixtures` on setUp.

    It expects the class to have the attributes `fixtures` and
    `session`.
    """
    def setUp(self):
        super().setUp()
        for objs in self.fixtures.values():
            for obj in objs:
                self.session.add(obj)
        self.session.commit()


class HSSOneAccountFixture(FixtureLoaderMixin):
    @property
    def fixtures(self):
        return {
            Account: [
                Account(
                    account='sipatinator',
                    name="<NAME>",
                    traffic_balance=67206545441,
                    access_id=1,
                ),
            ],
            Access: [
                Access(
                    id=1,
                    building="HSS46",
                    floor="0",
                    flat="1",
                    room="b",
                )
            ],
            IP: [
                IP(ip="172.16.58.3", account="sipatinator"),
                IP(ip="172.16.17.32"),
                IP(ip="192.168.3.11", account="sipatinator"),
            ],
        }


class HSSPgOneAccountTestCase(HSSOneAccountFixture, HssPgTestBase):
    def setUp(self):
        super().setUp()
        self.received_accounts = self.session.query(Account).all()
        self.received_account = self.received_accounts[0]

    def test_number_of_accounts(self):<commit_msg>Use an `OrderedDict` for `fixtures`<commit_after>#!/usr/bin/env python
from collections import OrderedDict

from flask.ext.login import AnonymousUserMixin

from tests.prepare import AppInitialized
from sipa.model.sqlalchemy import db
from sipa.model.hss.schema import Account, Access, IP
from sipa.model.hss.user import User


class HssPgTestBase(AppInitialized):
    def create_app(self):
        test_app = super().create_app(additional_config={
            'WU_CONNECTION_STRING': "sqlite:///",
            'HSS_CONNECTION_STRING': "postgresql://sipa:password@postgres:5432/",
            'DB_HELIOS_IP_MASK': "10.10.7.%",
        })
        return test_app

    def setUp(self):
        db.drop_all(bind='hss')
        db.create_all(bind='hss')
        self.session = db.session


class HSSPgEmptyTestCase(HssPgTestBase):
    def test_no_accounts_existent(self):
        self.assertFalse(self.session.query(Account).all())


class FixtureLoaderMixin:
    """A Mixin that creates `self.fixtures` on setUp.

    It expects the class to have the attributes `fixtures` and
    `session`.
    """
    def setUp(self):
        super().setUp()
        for objs in self.fixtures.values():
            for obj in objs:
                self.session.add(obj)
        self.session.commit()


class HSSOneAccountFixture(FixtureLoaderMixin):
    @property
    def fixtures(self):
        return OrderedDict([
            (Account, [
                Account(
                    account='sipatinator',
                    name="<NAME>",
                    traffic_balance=67206545441,
                    access_id=1,
                ),
            ]),
            (Access, [
                Access(
                    id=1,
                    building="HSS46",
                    floor="0",
                    flat="1",
                    room="b",
                )
            ]),
            (IP, [
                IP(ip="172.16.58.3", account="sipatinator"),
                IP(ip="172.16.17.32"),
                IP(ip="192.168.3.11", account="sipatinator"),
            ]),
        ])


class HSSPgOneAccountTestCase(HSSOneAccountFixture, HssPgTestBase):
    def setUp(self):
        super().setUp()
        self.received_accounts = self.session.query(Account).all()
        self.received_account = self.received_accounts[0]

    def test_number_of_accounts(self):
{'fraction_non_alphanumeric': 0.11559948431456811, 'fraction_numerical': 0.022776106574989255, 'mean_word_length': 1.8841387856257745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '1443635', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1379, 'n_words': 246}