<commit_before>import pytest
from pupa.scrape import Person, Organization, Membership, Post
from pupa.utils import get_pseudo_id
from validictory import ValidationError
import datetime


def test_basic_post():
    post = Post(label='1', role='Representative', organization_id='fake_org')
    assert '1' in str(post)
    post.validate()


def test_basic_invalid_post():
    post = Post(label=1, role='Representative', organization_id='fake_org')
    with pytest.raises(ValueError):
        post.validate()


def test_basic_membership():
    m = Membership(person_id='person', organization_id='org')
    assert 'person' in str(m) and 'org' in str(m)


def test_basic_invalid_membership():
    membership = Membership(person_id=33, organization_id="orga_id")
    with pytest.raises(ValueError):
        membership.validate()


def test_basic_invalid_person():
    bob = Person("<NAME>")
    bob.add_source(url='foo')
    bob.validate()

    bob.name = None

    with pytest.raises(ValidationError):
        bob.validate()


def test_basic_person():
    p = Person('<NAME>')
    p.add_source('http://example.com')
    assert p.name in str(p)
    p.validate()


def test_person_add_membership_org():
    p = Person('<NAME>')
    p.add_source('http://example.com')
    o = Organization('test org', classification='unknown')
    p.add_membership(o, role='member', start_date='2007', end_date=datetime.date(2015, 5, 8))
    assert len(p._related) == 1
    p._related[0].validate()
    assert p._related[0].person_id == p._id
    assert p._related[0].organization_id == o._id
    assert p._related[0].start_date == '2007'
    assert p._related[0].end_date == datetime.date(2015, 5, 8)


def test_basic_organization():
    org = Organization('some org', classification='committee')
    org.add_source('http://example.com')
    assert org.name in str(org)
    org.validate()


def test_no_source_on_party_org():
    org = Organization('Hat', classification='party')
    # no source? no problem because classification = party
    org.validate()


def test_basic_invalid_organization():
    orga = Organization("name")

    # no source
    with pytest.raises(ValidationError):
        orga.validate()


def test_org_add_post():
    """ Test that we can hack posts in on the fly'"""
    orga = Organization("name", classification="committee")
    orga.add_source(url='foo')
    orga.validate()

    orga.add_post("Human Readable Name", "Chef")

    assert orga._related[0].role == "Chef"
    assert orga._related[0].label == "Human Readable Name"


def test_legislator_related_district():
    l = Person('<NAME>', district='1', primary_org='legislature')
    l.pre_save('jurisdiction-id')

    assert len(l._related) == 1
    assert l._related[0].person_id == l._id
    assert get_pseudo_id(l._related[0].organization_id) == {'classification': 'legislature'}
    assert get_pseudo_id(l._related[0].post_id) == {"organization__classification": "legislature",
                                                    "label": "1", "role": "member"}
    assert l._related[0].role == 'member'


def test_legislator_related_chamber_district():
    l = Person('<NAME>', district='1', primary_org='upper')
    l.pre_save('jurisdiction-id')

    assert len(l._related) == 1
    assert l._related[0].person_id == l._id
    assert get_pseudo_id(l._related[0].organization_id) == {'classification': 'upper'}
    assert get_pseudo_id(l._related[0].post_id) == {"organization__classification": "upper",
                                                    "label": "1", "role": "member"}
    assert l._related[0].role == 'member'

<commit_msg>add a new test for different behavior<commit_after>import pytest
from pupa.scrape import Person, Organization, Membership, Post
from pupa.utils import get_pseudo_id
from validictory import ValidationError
import datetime


def test_basic_post():
    post = Post(label='1', role='Representative', organization_id='fake_org')
    assert '1' in str(post)
    post.validate()


def test_basic_invalid_post():
    post = Post(label=1, role='Representative', organization_id='fake_org')
    with pytest.raises(ValueError):
        post.validate()


def test_basic_membership():
    m = Membership(person_id='person', organization_id='org')
    assert 'person' in str(m) and 'org' in str(m)


def test_basic_invalid_membership():
    membership = Membership(person_id=33, organization_id="orga_id")
    with pytest.raises(ValueError):
        membership.validate()


def test_basic_invalid_person():
    bob = Person("<NAME>")
    bob.add_source(url='foo')
    bob.validate()

    bob.name = None

    with pytest.raises(ValidationError):
        bob.validate()


def test_basic_person():
    p = Person('<NAME>')
    p.add_source('http://example.com')
    assert p.name in str(p)
    p.validate()


def test_person_add_membership_org():
    p = Person('<NAME>')
    p.add_source('http://example.com')
    o = Organization('test org', classification='unknown')
    p.add_membership(o, role='member', start_date='2007', end_date=datetime.date(2015, 5, 8))
    assert len(p._related) == 1
    p._related[0].validate()
    assert p._related[0].person_id == p._id
    assert p._related[0].organization_id == o._id
    assert p._related[0].start_date == '2007'
    assert p._related[0].end_date == datetime.date(2015, 5, 8)


def test_basic_organization():
    org = Organization('some org', classification='committee')
    org.add_source('http://example.com')
    assert org.name in str(org)
    org.validate()


def test_no_source_on_party_org():
    org = Organization('Hat', classification='party')
    # no source? no problem because classification = party
    org.validate()


def test_basic_invalid_organization():
    orga = Organization("name")

    # no source
    with pytest.raises(ValidationError):
        orga.validate()


def test_org_add_post():
    """ Test that we can hack posts in on the fly'"""
    orga = Organization("name", classification="committee")
    orga.add_source(url='foo')
    orga.validate()

    orga.add_post("Human Readable Name", "Chef")

    assert orga._related[0].role == "Chef"
    assert orga._related[0].label == "Human Readable Name"


def test_legislator_related_district():
    l = Person('<NAME>', district='1', primary_org='legislature')
    l.pre_save('jurisdiction-id')

    assert len(l._related) == 1
    assert l._related[0].person_id == l._id
    assert get_pseudo_id(l._related[0].organization_id) == {'classification': 'legislature'}
    assert get_pseudo_id(l._related[0].post_id) == {"organization__classification": "legislature",
                                                    "label": "1"}
    #assert l._related[0].role == 'member'


def test_legislator_related_chamber_district():
    l = Person('<NAME>', district='1', primary_org='upper')
    l.pre_save('jurisdiction-id')

    assert len(l._related) == 1
    assert l._related[0].person_id == l._id
    assert get_pseudo_id(l._related[0].organization_id) == {'classification': 'upper'}
    assert get_pseudo_id(l._related[0].post_id) == {"organization__classification": "upper",
                                                    "label": "1"}
    #assert l._related[0].role == 'member'


def test_legislator_related_chamber_district_role():
    l = Person('<NAME>', district='1', primary_org='lower', role='Speaker')
    l.pre_save('jurisdiction-id')

    assert len(l._related) == 1
    assert l._related[0].person_id == l._id
    assert get_pseudo_id(l._related[0].organization_id) == {'classification': 'lower'}
    assert get_pseudo_id(l._related[0].post_id) == {"organization__classification": "lower",
                                                    "label": "1", "role": "Speaker"}
    assert l._related[0].role == 'Speaker'

{'fraction_non_alphanumeric': 0.14460626369377497, 'fraction_numerical': 0.013017141384198995, 'mean_word_length': 3.7374847374847375, 'pattern_counts': {'":': 13, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4881809', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2410, 'n_words': 497}