Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a proxy model bug related to ad-free #4390

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,20 @@ def __init__(self, *args, **kwargs):
pass
super(APIProject, self).__init__(*args, **kwargs)

# Overwrite the database property with the value from the API
self.ad_free = (not kwargs.pop('show_advertising', True))

def save(self, *args, **kwargs):
return 0

def has_feature(self, feature_id):
return feature_id in self.features

@property
def show_advertising(self):
"""Whether this project is ad-free (don't access the database)"""
return not self.ad_free


@python_2_unicode_compatible
class ImportedFile(models.Model):
Expand Down
20 changes: 19 additions & 1 deletion readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from readthedocs.builds.models import Build, BuildCommandResult, Version
from readthedocs.integrations.models import Integration
from readthedocs.oauth.models import RemoteOrganization, RemoteRepository
from readthedocs.projects.models import Feature, Project
from readthedocs.projects.models import Feature, Project, APIProject
from readthedocs.restapi.views.integrations import GitHubWebhookView
from readthedocs.restapi.views.task_views import get_status_data

Expand Down Expand Up @@ -564,6 +564,24 @@ def test_remote_organization_pagination(self):
self.assertEqual(len(resp.data['results']), 25) # page_size
self.assertIn('?page=2', resp.data['next'])

def test_init_api_project(self):
project_data = {
'name': 'Test Project',
'slug': 'test-project',
'show_advertising': True,
}

api_project = APIProject(**project_data)
self.assertEqual(api_project.slug, 'test-project')
self.assertEquals(api_project.features, [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to uses assertEquals and not assertEqual?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like assertEqual is preferred. I never gave it much thought but I think I use the plural with lists/sets/tuples. I'll switch to singular.

self.assertEqual(api_project.ad_free, False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think it's better to use assertFalse and assertTrue for this cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, you're right. I don't know why I did that.


project_data['features'] = ['test-feature']
project_data['show_advertising'] = False
api_project = APIProject(**project_data)
self.assertEquals(api_project.features, ['test-feature'])
self.assertEqual(api_project.ad_free, True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding an assert for the show_advertising here is good to check that our overriden method does work.



class APIImportTests(TestCase):

Expand Down