This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathtest_signals.py
More file actions
84 lines (63 loc) · 2.52 KB
/
test_signals.py
File metadata and controls
84 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from unittest.mock import call
import pytest
from shared.django_apps.codecov_auth.tests.factories import OwnerFactory
from shared.django_apps.core.tests.factories import CommitFactory, RepositoryFactory
@pytest.mark.django_db
def test_shelter_repo_sync(mocker):
publish = mocker.patch("utils.shelter.ShelterPubsub.publish")
# this triggers the publish via Django signals
repo = RepositoryFactory(
repoid=91728376, author=OwnerFactory(ownerid=555), private=False
)
# triggers publish on create
publish.assert_has_calls(
[
call({"type": "owner", "sync": "one", "id": 555}),
call({"type": "repo", "sync": "one", "id": 91728376}),
]
)
repo.upload_token = "b69cf44c-89d8-48c2-80c9-5508610d3ced"
repo.save()
publish_calls = publish.call_args_list
assert len(publish_calls) == 3
# triggers publish on update
assert publish_calls[2] == call({"type": "repo", "sync": "one", "id": 91728376})
# Does not trigger another publish with untracked field
repo.message = "foo"
repo.save()
publish_calls = publish.call_args_list
assert len(publish_calls) == 3
# Triggers call when owner is changed
repo.author = OwnerFactory(ownerid=888)
repo.save()
publish_calls = publish.call_args_list
# 1 is for the new owner created
assert len(publish_calls) == 5
publish.assert_has_calls([call({"type": "owner", "sync": "one", "id": 888})])
# Triggers call when private is changed
repo.private = True
repo.save()
# publish_calls = publish.call_args_list
assert len(publish_calls) == 6
@pytest.mark.django_db
def test_shelter_commit_sync(mocker):
publish = mocker.patch("utils.shelter.ShelterPubsub.publish")
# this triggers the publish via Django signals - has to have this format
owner = OwnerFactory(ownerid=555)
commit = CommitFactory(
id=167829367,
branch="random:branch",
author=owner,
repository=RepositoryFactory(author=owner),
)
publish_calls = publish.call_args_list
# 3x cause there's a signal triggered when the commit factory requires a Repository and Owner
# which can't be null
assert len(publish_calls) == 3
# triggers publish on update
assert publish_calls[2] == call({"type": "commit", "sync": "one", "id": 167829367})
commit.branch = "normal-incompatible-branch"
commit.save()
publish_calls = publish.call_args_list
# does not trigger another publish since unchanged length
assert len(publish_calls) == 3