<commit_before>import pytest
try:
    from unittest import mock
except ImportError:
    import mock

from k2catalogue import models


@pytest.fixture
def proposal():
    return models.Proposal(proposal_id='abc', pi='pi', title='title',
                           pdf_url='pdf_url')


def test_proposal_printing(proposal):
    assert repr(proposal) == '<Proposal: abc>'


def test_proposal():
    proposals = models.Proposal.create(['abc', 'def'],
                                       campaign=mock.MagicMock(),
                                       proposal_mapping=mock.MagicMock())
    assert (proposals[0].proposal_id == 'abc' and
            proposals[1].proposal_id == 'def')


@pytest.mark.parametrize('input,expected', [
    ('GO2069_LC', True),
    ('G', False),
    ('LC_2007JJ43_TILE', False),
])
def test_valid_proposal(input, expected):
    assert models.Proposal.valid_proposal(input) == expected<commit_msg>Add more tests around the proposal model behaviour<commit_after>import pytest
try:
    from unittest import mock
except ImportError:
    import mock

from k2catalogue import models


@pytest.fixture
def proposal():
    return models.Proposal(proposal_id='abc', pi='pi', title='title',
                           pdf_url='pdf_url')


def test_proposal_printing(proposal):
    assert repr(proposal) == '<Proposal: abc>'


def test_proposal():
    proposals = models.Proposal.create(['abc', 'def'],
                                       campaign=mock.MagicMock(),
                                       proposal_mapping=mock.MagicMock())
    assert (proposals[0].proposal_id == 'abc' and
            proposals[1].proposal_id == 'def')


def test_open_proposals_page(proposal):
    with mock.patch.object(proposal, 'campaign') as campaign:
        proposal.open_proposals_page()
        campaign.open_proposals_page.assert_called_once_with()


def test_open_proposal(proposal):
    with mock.patch('k2catalogue.models.webbrowser.open') as mock_open:
        proposal.open_proposal()
        mock_open.assert_called_once_with('pdf_url')


def test_open_proposal_without_url(proposal):
    proposal.pdf_url = None
    with mock.patch('k2catalogue.models.webbrowser.open') as mock_open:
        proposal.open_proposal()
        assert not mock_open.called


def test_create_with_no_mapping(capsys):
    proposal_mapping = {}
    campaign = mock.Mock()
    proposal_ids = ['abc', ]
    models.Proposal.create(proposal_ids, campaign, proposal_mapping)
    out, err = capsys.readouterr()
    assert err == 'No proposal metadata for abc\n'


@pytest.mark.parametrize('input,expected', [
    ('GO2069_LC', True),
    ('G', False),
    ('LC_2007JJ43_TILE', False),
])
def test_valid_proposal(input, expected):
    assert models.Proposal.valid_proposal(input) == expected
{'fraction_non_alphanumeric': 0.11790079079798706, 'fraction_numerical': 0.010064701653486701, 'mean_word_length': 3.20392749244713, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340793', 'n_tokens_mistral': 883, 'n_tokens_neox': 870, 'n_words': 165}