Skip to content

Make Build models default to triggered #8031

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

Merged
merged 8 commits into from
Jan 30, 2023
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
32 changes: 32 additions & 0 deletions readthedocs/builds/migrations/0047_build_default_triggered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.16 on 2023-01-26 23:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("builds", "0046_identifier_null"),
]

operations = [
migrations.AlterField(
model_name="build",
name="state",
field=models.CharField(
choices=[
("triggered", "Triggered"),
("cloning", "Cloning"),
("installing", "Installing"),
("building", "Building"),
("uploading", "Uploading"),
("finished", "Finished"),
("cancelled", "Cancelled"),
],
db_index=True,
default="triggered",
max_length=55,
verbose_name="State",
),
),
]
6 changes: 4 additions & 2 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ def config(self):
.only('_config')
.first()
)
return last_build.config
if last_build:
return last_build.config
return None

@property
def commit_name(self):
Expand Down Expand Up @@ -630,7 +632,7 @@ class Build(models.Model):
_('State'),
max_length=55,
choices=BUILD_STATE,
default='finished',
default=BUILD_STATE_TRIGGERED,
db_index=True,
)

Expand Down
5 changes: 4 additions & 1 deletion readthedocs/builds/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def test_cancel_build_from_another_project(self, app):
another_user = get(User)
another_project = self._get_project(owners=[another_user])
another_build = get(
Build, project=another_project, version=another_project.versions.first()
Build,
project=another_project,
version=another_project.versions.first(),
state=BUILD_STATE_INSTALLING,
)

self.client.force_login(another_user)
Expand Down
28 changes: 20 additions & 8 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from readthedocs.api.v2.views.task_views import get_status_data
from readthedocs.builds.constants import (
BUILD_STATE_CLONING,
BUILD_STATE_FINISHED,
BUILD_STATE_TRIGGERED,
EXTERNAL,
EXTERNAL_VERSION_STATE_CLOSED,
Expand Down Expand Up @@ -510,17 +511,23 @@ def test_make_build_commands(self):
def test_get_raw_log_success(self):
project = Project.objects.get(pk=1)
version = project.versions.first()
build = get(Build, project=project, version=version, builder='foo')
build = get(
Build,
project=project,
version=version,
builder="foo",
state=BUILD_STATE_FINISHED,
)
get(
BuildCommandResult,
build=build,
command='python setup.py install',
output='Installing dependencies...',
command="python setup.py install",
output="Installing dependencies...",
)
get(
BuildCommandResult,
build=build,
command='git checkout master',
command="git checkout master",
output='Switched to branch "master"',
)
client = APIClient()
Expand Down Expand Up @@ -598,14 +605,19 @@ def test_get_raw_log_failure(self):
project = Project.objects.get(pk=1)
version = project.versions.first()
build = get(
Build, project=project, version=version,
builder='foo', success=False, exit_code=1,
Build,
project=project,
version=version,
builder="foo",
success=False,
exit_code=1,
state=BUILD_STATE_FINISHED,
)
get(
BuildCommandResult,
build=build,
command='python setup.py install',
output='Installing dependencies...',
command="python setup.py install",
output="Installing dependencies...",
exit_code=1,
)
get(
Expand Down
68 changes: 51 additions & 17 deletions readthedocs/rtd_tests/tests/test_project_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.views.generic.base import ContextMixin
from django_dynamic_fixture import get, new

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

def test_passing_badge(self):
get(Build, project=self.project, version=self.version, success=True)
res = self.client.get(self.badge_url, {'version': self.version.slug})
self.assertContains(res, 'passing')
self.assertEqual(res['Content-Type'], 'image/svg+xml')
get(
Build,
project=self.project,
version=self.version,
success=True,
state=BUILD_STATE_FINISHED,
)
res = self.client.get(self.badge_url, {"version": self.version.slug})
self.assertContains(res, "passing")
self.assertEqual(res["Content-Type"], "image/svg+xml")

def test_failing_badge(self):
get(Build, project=self.project, version=self.version, success=False)
res = self.client.get(self.badge_url, {'version': self.version.slug})
self.assertContains(res, 'failing')
get(
Build,
project=self.project,
version=self.version,
success=False,
state=BUILD_STATE_FINISHED,
)
res = self.client.get(self.badge_url, {"version": self.version.slug})
self.assertContains(res, "failing")

def test_plastic_failing_badge(self):
get(Build, project=self.project, version=self.version, success=False)
res = self.client.get(self.badge_url, {'version': self.version.slug, 'style': 'plastic'})
self.assertContains(res, 'failing')
get(
Build,
project=self.project,
version=self.version,
success=False,
state=BUILD_STATE_FINISHED,
)
res = self.client.get(
self.badge_url, {"version": self.version.slug, "style": "plastic"}
)
self.assertContains(res, "failing")

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

def test_social_passing_badge(self):
get(Build, project=self.project, version=self.version, success=True)
res = self.client.get(self.badge_url, {'version': self.version.slug, 'style': 'social'})
self.assertContains(res, 'passing')
get(
Build,
project=self.project,
version=self.version,
success=True,
state=BUILD_STATE_FINISHED,
)
res = self.client.get(
self.badge_url, {"version": self.version.slug, "style": "social"}
)
self.assertContains(res, "passing")

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

# Without a token, badge is unknown
get(Build, project=self.project, version=self.version, success=True)
res = self.client.get(self.badge_url, {'version': self.version.slug})
self.assertContains(res, 'unknown')
get(
Build,
project=self.project,
version=self.version,
success=True,
state=BUILD_STATE_FINISHED,
)
res = self.client.get(self.badge_url, {"version": self.version.slug})
self.assertContains(res, "unknown")

# With an invalid token, the badge is unknown
res = self.client.get(
Expand Down
11 changes: 9 additions & 2 deletions readthedocs/rtd_tests/tests/test_version_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import TestCase
from django_dynamic_fixture import get

from readthedocs.builds.constants import BUILD_STATE_BUILDING, BUILD_STATE_FINISHED
from readthedocs.builds.models import Build, Version
from readthedocs.projects.models import Project

Expand All @@ -16,23 +17,26 @@ def test_get_correct_config(self):
project=self.project,
version=self.version,
_config={'version': 1},
state=BUILD_STATE_FINISHED,
)
build_new = Build.objects.create(
project=self.project,
version=self.version,
_config={'version': 2},
state=BUILD_STATE_FINISHED,
)
build_new_error = Build.objects.create(
project=self.project,
version=self.version,
_config={'version': 3},
success=False,
state=BUILD_STATE_FINISHED,
)
build_new_unfinish = Build.objects.create(
project=self.project,
version=self.version,
_config={'version': 4},
state='building',
state=BUILD_STATE_BUILDING,
)
self.assertEqual(self.version.config, {'version': 2})

Expand All @@ -42,6 +46,7 @@ def test_get_correct_config_when_same_config(self):
project=self.project,
version=self.version,
_config={},
state=BUILD_STATE_FINISHED,
)
build_old.config = {'version': 1}
build_old.save()
Expand All @@ -51,6 +56,7 @@ def test_get_correct_config_when_same_config(self):
project=self.project,
version=self.version,
_config={},
state=BUILD_STATE_FINISHED,
)
build_new.config = {'version': 1}
build_new.save()
Expand All @@ -61,6 +67,7 @@ def test_get_correct_config_when_same_config(self):
version=self.version,
_config={},
success=False,
state=BUILD_STATE_FINISHED,
)
build_new_error.config = {'version': 3}
build_new_error.save()
Expand All @@ -70,7 +77,7 @@ def test_get_correct_config_when_same_config(self):
project=self.project,
version=self.version,
_config={},
state='building',
state=BUILD_STATE_BUILDING,
)
build_new_unfinish.config = {'version': 1}
build_new_unfinish.save()
Expand Down