Skip to content

Commit

Permalink
Allow manual publishing feature flagged
Browse files Browse the repository at this point in the history
  • Loading branch information
richtier committed Mar 8, 2019
1 parent f1a3fb4 commit 774fe37
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
1 change: 0 additions & 1 deletion company/serializers.py
Expand Up @@ -145,7 +145,6 @@ class Meta:
'export_status': {'required': False},
'has_exported_before': {'required': False},
'modified': {'read_only': True},
'is_published': {'read_only': True},
'slug': {'read_only': True},

}
Expand Down
2 changes: 2 additions & 0 deletions company/signals.py
Expand Up @@ -19,6 +19,8 @@ def send_first_verification_letter(sender, instance, *args, **kwargs):


def publish_companies_that_meet_criteria(sender, instance, *args, **kwargs):
if not settings.FEATURE_MANUAL_PUBLISH_ENABLED:
return
if not instance.is_published:
has_contact = bool(instance.email_address)
has_synopsis = bool(instance.description or instance.summary)
Expand Down
75 changes: 52 additions & 23 deletions company/tests/test_signals.py
Expand Up @@ -118,32 +118,35 @@ def test_unknown_address_not_send_letters(mock_send_letter, settings):
mock_send_letter.send_letter.assert_not_called()


test_publish_params = [
# has_contact
['', '', '', False, False],
['', '', 'a@e.com', False, False],
# has_synopsis
['d', '', '', False, False],
['d', '', 'a@e.com', False, False],
['d', 's', '', False, False],
['', 's', '', False, False],
['d', 's', 'a@e.com', False, False],
['', 's', 'a@e.com', False, False],
# is_verified
['', '', '', True, False],
['', '', 'a@e.com', True, False],
['d', '', '', True, False],
['d', '', 'a@e.com', True, True],
['d', 's', '', True, False],
['', 's', '', True, False],
['d', 's', 'a@e.com', True, True],
['', 's', 'a@e.com', True, True],
]


@pytest.mark.django_db
@pytest.mark.parametrize(
'desciption,summary,email,is_verified,expected',
[
# has_contact
['', '', '', False, False],
['', '', 'a@e.com', False, False],
# has_synopsis
['d', '', '', False, False],
['d', '', 'a@e.com', False, False],
['d', 's', '', False, False],
['', 's', '', False, False],
['d', 's', 'a@e.com', False, False],
['', 's', 'a@e.com', False, False],
# is_verified
['', '', '', True, False],
['', '', 'a@e.com', True, False],
['d', '', '', True, False],
['d', '', 'a@e.com', True, True],
['d', 's', '', True, False],
['', 's', '', True, False],
['d', 's', 'a@e.com', True, True],
['', 's', 'a@e.com', True, True],
]
'desciption,summary,email,is_verified,expected', test_publish_params
)
def test_publish(desciption, summary, email, is_verified, expected):
def test_publish(desciption, summary, email, is_verified, expected, settings):
settings.FEATURE_MANUAL_PUBLISH_ENABLED = False
fields = {
'description': desciption,
'summary': summary,
Expand All @@ -162,6 +165,32 @@ def test_publish(desciption, summary, email, is_verified, expected):
assert company.is_published is expected


@pytest.mark.django_db
@pytest.mark.parametrize(
'desciption,summary,email,is_verified,expected', test_publish_params
)
def test_publish_feature_flagged(
desciption, summary, email, is_verified, expected, settings
):
settings.FEATURE_MANUAL_PUBLISH_ENABLED = True
fields = {
'description': desciption,
'summary': summary,
'email_address': email
}
mock_verifed = mock.PropertyMock(return_value=is_verified)
with mock.patch('company.models.Company.is_verified', mock_verifed):
company = factories.CompanyFactory(**fields)
# create
assert company.is_published is False
# update
for field, value in fields.items():
setattr(company, field, value)
company.save()
company.refresh_from_db()
assert company.is_published is False


@pytest.mark.django_db
@pytest.mark.parametrize(
'desciption,summary,email,is_verified', [
Expand Down
3 changes: 3 additions & 0 deletions conf/settings.py
Expand Up @@ -586,6 +586,9 @@
FEATURE_VERIFICATION_LETTERS_ENABLED = env.bool(
'FEATURE_VERIFICATION_LETTERS_ENABLED', False
)
FEATURE_MANUAL_PUBLISH_ENABLED = env.bool(
'FEATURE_MANUAL_PUBLISH_ENABLED', False
)

# directory-signature-auth
SIGNATURE_SECRET = env.str('SIGNATURE_SECRET')
Expand Down

0 comments on commit 774fe37

Please sign in to comment.