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 all 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
22 changes: 21 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,26 @@ 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.assertEqual(api_project.features, [])
self.assertFalse(api_project.ad_free)
self.assertTrue(api_project.show_advertising)

project_data['features'] = ['test-feature']
project_data['show_advertising'] = False
api_project = APIProject(**project_data)
self.assertEqual(api_project.features, ['test-feature'])
self.assertTrue(api_project.ad_free)
self.assertFalse(api_project.show_advertising)


class APIImportTests(TestCase):

Expand Down