Skip to content

Commit 9cc3c36

Browse files
ericholscherhumitosstsewd
authored
Make Build models default to triggered (#8031)
* Make Build models default to `triggered` I'm not sure why we were defaulting them to Finished, but this should help not confuse the badge code, and just be more correct in general. --------- Co-authored-by: Manuel Kaufmann <[email protected]> Co-authored-by: Santos Gallegos <[email protected]>
1 parent 12695bf commit 9cc3c36

File tree

6 files changed

+120
-30
lines changed

6 files changed

+120
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 3.2.16 on 2023-01-26 23:46
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("builds", "0046_identifier_null"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="build",
15+
name="state",
16+
field=models.CharField(
17+
choices=[
18+
("triggered", "Triggered"),
19+
("cloning", "Cloning"),
20+
("installing", "Installing"),
21+
("building", "Building"),
22+
("uploading", "Uploading"),
23+
("finished", "Finished"),
24+
("cancelled", "Cancelled"),
25+
],
26+
db_index=True,
27+
default="triggered",
28+
max_length=55,
29+
verbose_name="State",
30+
),
31+
),
32+
]

readthedocs/builds/models.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ def config(self):
290290
.only('_config')
291291
.first()
292292
)
293-
return last_build.config
293+
if last_build:
294+
return last_build.config
295+
return None
294296

295297
@property
296298
def commit_name(self):
@@ -630,7 +632,7 @@ class Build(models.Model):
630632
_('State'),
631633
max_length=55,
632634
choices=BUILD_STATE,
633-
default='finished',
635+
default=BUILD_STATE_TRIGGERED,
634636
db_index=True,
635637
)
636638

readthedocs/builds/tests/test_views.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def test_cancel_build_from_another_project(self, app):
6868
another_user = get(User)
6969
another_project = self._get_project(owners=[another_user])
7070
another_build = get(
71-
Build, project=another_project, version=another_project.versions.first()
71+
Build,
72+
project=another_project,
73+
version=another_project.versions.first(),
74+
state=BUILD_STATE_INSTALLING,
7275
)
7376

7477
self.client.force_login(another_user)

readthedocs/rtd_tests/tests/test_api.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from readthedocs.api.v2.views.task_views import get_status_data
4242
from readthedocs.builds.constants import (
4343
BUILD_STATE_CLONING,
44+
BUILD_STATE_FINISHED,
4445
BUILD_STATE_TRIGGERED,
4546
EXTERNAL,
4647
EXTERNAL_VERSION_STATE_CLOSED,
@@ -510,17 +511,23 @@ def test_make_build_commands(self):
510511
def test_get_raw_log_success(self):
511512
project = Project.objects.get(pk=1)
512513
version = project.versions.first()
513-
build = get(Build, project=project, version=version, builder='foo')
514+
build = get(
515+
Build,
516+
project=project,
517+
version=version,
518+
builder="foo",
519+
state=BUILD_STATE_FINISHED,
520+
)
514521
get(
515522
BuildCommandResult,
516523
build=build,
517-
command='python setup.py install',
518-
output='Installing dependencies...',
524+
command="python setup.py install",
525+
output="Installing dependencies...",
519526
)
520527
get(
521528
BuildCommandResult,
522529
build=build,
523-
command='git checkout master',
530+
command="git checkout master",
524531
output='Switched to branch "master"',
525532
)
526533
client = APIClient()
@@ -598,14 +605,19 @@ def test_get_raw_log_failure(self):
598605
project = Project.objects.get(pk=1)
599606
version = project.versions.first()
600607
build = get(
601-
Build, project=project, version=version,
602-
builder='foo', success=False, exit_code=1,
608+
Build,
609+
project=project,
610+
version=version,
611+
builder="foo",
612+
success=False,
613+
exit_code=1,
614+
state=BUILD_STATE_FINISHED,
603615
)
604616
get(
605617
BuildCommandResult,
606618
build=build,
607-
command='python setup.py install',
608-
output='Installing dependencies...',
619+
command="python setup.py install",
620+
output="Installing dependencies...",
609621
exit_code=1,
610622
)
611623
get(

readthedocs/rtd_tests/tests/test_project_views.py

+51-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.views.generic.base import ContextMixin
99
from django_dynamic_fixture import get, new
1010

11-
from readthedocs.builds.constants import EXTERNAL
11+
from readthedocs.builds.constants import BUILD_STATE_FINISHED, EXTERNAL
1212
from readthedocs.builds.models import Build, Version
1313
from readthedocs.integrations.models import GenericAPIWebhook, GitHubWebhook
1414
from readthedocs.oauth.models import RemoteRepository, RemoteRepositoryRelation
@@ -517,28 +517,56 @@ def test_badge_caching(self):
517517
self.assertTrue('no-cache' in res['Cache-Control'])
518518

519519
def test_passing_badge(self):
520-
get(Build, project=self.project, version=self.version, success=True)
521-
res = self.client.get(self.badge_url, {'version': self.version.slug})
522-
self.assertContains(res, 'passing')
523-
self.assertEqual(res['Content-Type'], 'image/svg+xml')
520+
get(
521+
Build,
522+
project=self.project,
523+
version=self.version,
524+
success=True,
525+
state=BUILD_STATE_FINISHED,
526+
)
527+
res = self.client.get(self.badge_url, {"version": self.version.slug})
528+
self.assertContains(res, "passing")
529+
self.assertEqual(res["Content-Type"], "image/svg+xml")
524530

525531
def test_failing_badge(self):
526-
get(Build, project=self.project, version=self.version, success=False)
527-
res = self.client.get(self.badge_url, {'version': self.version.slug})
528-
self.assertContains(res, 'failing')
532+
get(
533+
Build,
534+
project=self.project,
535+
version=self.version,
536+
success=False,
537+
state=BUILD_STATE_FINISHED,
538+
)
539+
res = self.client.get(self.badge_url, {"version": self.version.slug})
540+
self.assertContains(res, "failing")
529541

530542
def test_plastic_failing_badge(self):
531-
get(Build, project=self.project, version=self.version, success=False)
532-
res = self.client.get(self.badge_url, {'version': self.version.slug, 'style': 'plastic'})
533-
self.assertContains(res, 'failing')
543+
get(
544+
Build,
545+
project=self.project,
546+
version=self.version,
547+
success=False,
548+
state=BUILD_STATE_FINISHED,
549+
)
550+
res = self.client.get(
551+
self.badge_url, {"version": self.version.slug, "style": "plastic"}
552+
)
553+
self.assertContains(res, "failing")
534554

535555
# The plastic badge has slightly more rounding
536556
self.assertContains(res, 'rx="4"')
537557

538558
def test_social_passing_badge(self):
539-
get(Build, project=self.project, version=self.version, success=True)
540-
res = self.client.get(self.badge_url, {'version': self.version.slug, 'style': 'social'})
541-
self.assertContains(res, 'passing')
559+
get(
560+
Build,
561+
project=self.project,
562+
version=self.version,
563+
success=True,
564+
state=BUILD_STATE_FINISHED,
565+
)
566+
res = self.client.get(
567+
self.badge_url, {"version": self.version.slug, "style": "social"}
568+
)
569+
self.assertContains(res, "passing")
542570

543571
# The social badge (but not the other badges) has this element
544572
self.assertContains(res, 'rlink')
@@ -556,9 +584,15 @@ def test_private_version(self):
556584
self.version.save()
557585

558586
# Without a token, badge is unknown
559-
get(Build, project=self.project, version=self.version, success=True)
560-
res = self.client.get(self.badge_url, {'version': self.version.slug})
561-
self.assertContains(res, 'unknown')
587+
get(
588+
Build,
589+
project=self.project,
590+
version=self.version,
591+
success=True,
592+
state=BUILD_STATE_FINISHED,
593+
)
594+
res = self.client.get(self.badge_url, {"version": self.version.slug})
595+
self.assertContains(res, "unknown")
562596

563597
# With an invalid token, the badge is unknown
564598
res = self.client.get(

readthedocs/rtd_tests/tests/test_version_config.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.test import TestCase
22
from django_dynamic_fixture import get
33

4+
from readthedocs.builds.constants import BUILD_STATE_BUILDING, BUILD_STATE_FINISHED
45
from readthedocs.builds.models import Build, Version
56
from readthedocs.projects.models import Project
67

@@ -16,23 +17,26 @@ def test_get_correct_config(self):
1617
project=self.project,
1718
version=self.version,
1819
_config={'version': 1},
20+
state=BUILD_STATE_FINISHED,
1921
)
2022
build_new = Build.objects.create(
2123
project=self.project,
2224
version=self.version,
2325
_config={'version': 2},
26+
state=BUILD_STATE_FINISHED,
2427
)
2528
build_new_error = Build.objects.create(
2629
project=self.project,
2730
version=self.version,
2831
_config={'version': 3},
2932
success=False,
33+
state=BUILD_STATE_FINISHED,
3034
)
3135
build_new_unfinish = Build.objects.create(
3236
project=self.project,
3337
version=self.version,
3438
_config={'version': 4},
35-
state='building',
39+
state=BUILD_STATE_BUILDING,
3640
)
3741
self.assertEqual(self.version.config, {'version': 2})
3842

@@ -42,6 +46,7 @@ def test_get_correct_config_when_same_config(self):
4246
project=self.project,
4347
version=self.version,
4448
_config={},
49+
state=BUILD_STATE_FINISHED,
4550
)
4651
build_old.config = {'version': 1}
4752
build_old.save()
@@ -51,6 +56,7 @@ def test_get_correct_config_when_same_config(self):
5156
project=self.project,
5257
version=self.version,
5358
_config={},
59+
state=BUILD_STATE_FINISHED,
5460
)
5561
build_new.config = {'version': 1}
5662
build_new.save()
@@ -61,6 +67,7 @@ def test_get_correct_config_when_same_config(self):
6167
version=self.version,
6268
_config={},
6369
success=False,
70+
state=BUILD_STATE_FINISHED,
6471
)
6572
build_new_error.config = {'version': 3}
6673
build_new_error.save()
@@ -70,7 +77,7 @@ def test_get_correct_config_when_same_config(self):
7077
project=self.project,
7178
version=self.version,
7279
_config={},
73-
state='building',
80+
state=BUILD_STATE_BUILDING,
7481
)
7582
build_new_unfinish.config = {'version': 1}
7683
build_new_unfinish.save()

0 commit comments

Comments
 (0)