Skip to content

Commit 9842783

Browse files
committed
Test: fix tests to check for None first
1 parent 6c6d1b9 commit 9842783

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

readthedocs/api/v2/views/integrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def handle_webhook(self):
431431
(created or deleted),
432432
]):
433433
integration = self.get_integration()
434-
events = integration.provider_data.get('events', [])
434+
events = integration.provider_data.get('events', []) if integration.provider_data else [] # noqa
435435
if any([
436436
GITHUB_CREATE in events,
437437
GITHUB_DELETE in events,

readthedocs/builds/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def config(self):
738738
# probably change this field to be a ForeignKey to avoid repeating the
739739
# config file over and over again and re-use them to save db data as
740740
# well
741-
if self.CONFIG_KEY in self._config:
741+
if self._config and self.CONFIG_KEY in self._config:
742742
return (
743743
Build.objects
744744
.only('_config')
@@ -951,7 +951,9 @@ def external_version_name(self):
951951
return None
952952

953953
def using_latest_config(self):
954-
return int(self.config.get('version', '1')) == LATEST_CONFIGURATION_VERSION
954+
if self.config:
955+
return int(self.config.get('version', '1')) == LATEST_CONFIGURATION_VERSION
956+
return False
955957

956958
def reset(self):
957959
"""

readthedocs/builds/tasks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ def route_for_task(self, task, args, kwargs, **__):
115115
last_builds = version.builds.order_by('-date')[:self.N_LAST_BUILDS]
116116
# Version has used conda in previous builds
117117
for build in last_builds.iterator():
118-
build_tools_python = (
119-
build.config
120-
.get('build', {})
121-
.get('tools', {})
122-
.get('python', {})
123-
.get('version', '')
124-
)
125-
conda = build.config.get('conda', None)
118+
build_tools_python = ''
119+
conda = None
120+
if build.config:
121+
build_tools_python = (
122+
build.config
123+
.get('build', {})
124+
.get('tools', {})
125+
.get('python', {})
126+
.get('version', '')
127+
)
128+
conda = build.config.get('conda', None)
126129

127130
uses_conda = any([
128131
conda,

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_make_build(self):
8989
self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
9090
build = resp.data
9191
self.assertEqual(build['state_display'], 'Cloning')
92-
self.assertEqual(build['config'], {})
92+
self.assertIsNone(build['config'])
9393

9494
resp = client.get('/api/v2/build/%s/' % build['id'])
9595
self.assertEqual(resp.status_code, 200)

0 commit comments

Comments
 (0)