Skip to content

Commit

Permalink
fix tests for new DraftRegistration default title and clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Sep 11, 2023
1 parent 8d6eeda commit ffb0d65
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions api_tests/draft_nodes/views/test_draft_node_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_detail_response(self, app, user, user_two):
assert res.status_code == 404

# cannot access draft node after it's been registered (it's now a node!)
draft_reg.title = 'test user generated title.'
draft_reg.register(Auth(user))
url = '/{}draft_nodes/{}/'.format(API_BASE, draft_node._id)
res = app.get(url, auth=user_two.auth, expect_errors=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_detail_view_returns_editable_fields_no_specified_node(self, app, user):
res = app.get(url, auth=user.auth, expect_errors=True)
attributes = res.json['data']['attributes']

assert attributes['title'] == 'Untitled'
assert attributes['title'] == ''
assert attributes['description'] == ''
assert attributes['category'] == ''
assert attributes['node_license'] is None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_draft_registration_attributes_not_copied_from_node(self, app, project_p
res = app.post_json_api(url_draft_registrations, payload, auth=user.auth)
assert res.status_code == 201
attributes = res.json['data']['attributes']
assert attributes['title'] == 'Untitled'
assert attributes['title'] == ''
assert attributes['description'] != project_public.description
assert attributes['category'] != project_public.category
assert set(attributes['tags']) != set([tag.name for tag in project_public.tags.all()])
Expand Down
6 changes: 6 additions & 0 deletions api_tests/registrations/views/test_registration_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,9 @@ def test_need_admin_perms_on_draft(
payload_ver['data']['attributes']['draft_registration_id'] = draft_registration._id
assert draft_registration.branched_from.is_admin_contributor(user) is False
assert draft_registration.has_permission(user, permissions.ADMIN) is True
assert draft_registration.title is ""
draft_registration.title = 'test user generated title required'
draft_registration.save()
res = app.post_json_api(url_registrations_ver, payload_ver, auth=user.auth)
assert res.status_code == 201

Expand All @@ -1578,6 +1581,9 @@ def test_need_admin_perms_on_draft(
assert draft_registration.branched_from.is_admin_contributor(user) is True
assert draft_registration.has_permission(user, permissions.ADMIN) is True
payload_ver['data']['attributes']['draft_registration_id'] = draft_registration._id
assert draft_registration.title is ""
draft_registration.title = 'test user generated title required'
draft_registration.save()
res = app.post_json_api(url_registrations_ver, payload_ver, auth=user.auth)
assert res.status_code == 201

Expand Down
2 changes: 1 addition & 1 deletion osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,7 @@ def copy_editable_fields(self, resource, auth=None, alternative_resource=None, i
TODO, add optional logging parameter
"""
from osf.models.draft_node import DraftNode
if not isinstance(resource, DraftNode): # Force the user to add there own title.
if not isinstance(resource, DraftNode): # Force the user to add there own title.test_create_draft_registration_without_node
self.set_editable_attribute('title', resource, alternative_resource)

self.set_editable_attribute('description', resource, alternative_resource)
Expand Down
5 changes: 3 additions & 2 deletions osf_tests/test_draft_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_default_metaschema,
)
from website.project.signals import after_create_registration
from website import settings

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -123,8 +124,8 @@ def test_create_draft_registration_without_node(self, user):
schema=get_default_metaschema(),
data=data,
)
assert draft.title == 'Untitled'
assert draft.branched_from.title == 'Untitled'
assert draft.title == ''
assert draft.branched_from.title == settings.DEFAULT_DRAFT_NODE_TITLE
assert draft.branched_from.type == 'osf.draftnode'
assert draft.branched_from.creator == user
assert len(draft.logs.all()) == 0
Expand Down
2 changes: 1 addition & 1 deletion osf_tests/test_draft_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_create_from_node_draft_node(self, user):
schema=factories.get_default_metaschema(),
)

assert draft.title == 'Untitled'
assert draft.title == ''
assert draft.description == ''
assert draft.category == ''
assert user in draft.contributors.all()
Expand Down
3 changes: 1 addition & 2 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def parent_dir(path):

# Google Analytics
GOOGLE_ANALYTICS_ID = None
GOOGLE_TAG_MANAGER_ID = None
GOOGLE_SITE_VERIFICATION = None

DEFAULT_HMAC_SECRET = 'changeme'
Expand Down Expand Up @@ -2129,4 +2128,4 @@ def from_node_usage(cls, usage_bytes, private_limit=None, public_limit=None):
PREPRINT_METRICS_START_DATE = datetime.datetime(2019, 1, 1)

WAFFLE_VALUES_YAML = 'osf/features.yaml'
DEFAULT_DRAFT_NODE_TITLE = 'Untitled'
DEFAULT_DRAFT_NODE_TITLE = 'Untitled'

0 comments on commit ffb0d65

Please sign in to comment.