<commit_before>"""Functional tests for model.py"""

# Some Notes:
#
# * We don't really have any agreed-upon requirements about what __repr__
# should print, but I'm fairly certain I hit an argument mistmatch at
# some point, which is definitely wrong. The test_repr methods are there just
# to make sure it isn't throwing an exception.

from haas.model import *

# There's probably a better way to do this
from haas.test_common import newDB, releaseDB


class InsertTest:
    """Superclass for tests doing basic database insertions of one object."""

    def insert(self, obj):
        db = newDB()
        db.add(obj)
        db.commit()
        releaseDB(db)


class TestUsers(InsertTest):
    """Test user-related functionality"""

    def test_user_create_verify(self):
        db = newDB()
        user = User('bob', '<PASSWORD>')
        assert user.verify_password('<PASSWORD>')
        releaseDB(db)

    def test_user_insert(self):
        self.insert(User('bob', 'secret'))

    def test_repr(self):
        print(User('bob', 'secret'))


class TestGroup(InsertTest):

    def test_insert(self):
        self.insert(Group('moc-hackers'))

    def test_repr(self):
        print(Group('moc-hackers'))


class TestNic(InsertTest):
<commit_msg>Started abstracting common model tests.<commit_after>"""Functional tests for model.py"""

# Some Notes:
#
# * We don't really have any agreed-upon requirements about what __repr__
# should print, but I'm fairly certain I hit an argument mistmatch at
# some point, which is definitely wrong. The test_repr methods are there just
# to make sure it isn't throwing an exception.

from haas.model import *

# There's probably a better way to do this
from haas.test_common import newDB, releaseDB

class ModelTest:
    """Superclass with tests common to all models."""

    def test_repr(self):
        print(self.sample_obj())

    def test_insert(self):
        db = newDB()
        db.add(self.sample_obj())
        db.commit()
        releaseDB(db)

class TestUsers(ModelTest):
    """Test user-related functionality"""

    def sample_obj(self):
        return User('bob', 'secret')

    def test_user_create_verify(self):
        db = newDB()
        user = User('bob', 'secret')
        assert user.verify_password('<PASSWORD>')
        releaseDB(db)


class TestGroup(InsertTest):

    def test_insert(self):
        self.insert(Group('moc-hackers'))

    def test_repr(self):
        print(Group('moc-hackers'))


class TestNic(InsertTest):

{'fraction_non_alphanumeric': 0.11137820512820513, 'fraction_numerical': 0.0, 'mean_word_length': 3.312607944732297, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6158950', 'n_tokens_mistral': 770, 'n_tokens_neox': 733, 'n_words': 234}