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

[BUGFIX] Fixes to unit tests to avoid signal errors #216

Merged
merged 1 commit into from
Dec 12, 2019
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
File renamed without changes.
4 changes: 0 additions & 4 deletions promgen/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
# These sources are released under the terms of the MIT license: see LICENSE


from promgen import models, views
from promgen.tests import PromgenTest

from django.test import override_settings
from django.urls import reverse

from promgen import models, views

from promgen.tests import PromgenTest

TEST_SETTINGS = PromgenTest.data_yaml('examples', 'promgen.yml')
Expand Down
12 changes: 8 additions & 4 deletions promgen/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Copyright (c) 2019 LINE Corporation
# These sources are released under the terms of the MIT license: see LICENSE

from promgen import models
from promgen.tests import PromgenTest
from unittest import mock

from django.core import management
from django.core.management.base import CommandError

from promgen import models
from promgen.tests import PromgenTest


class CLITests(PromgenTest):
def test_register_job(self):
@mock.patch("django.dispatch.dispatcher.Signal.send")
def test_register_job(self, mock_signal):
# Assert when project doesn't exist
with self.assertRaises(CommandError):
management.call_command("register-job", "missing-project", "example", 1234)
Expand All @@ -31,7 +34,8 @@ def test_register_job(self):
management.call_command("register-job", "TestProject", "example", 4321)
self.assertCount(models.Exporter, 2)

def test_register_host(self):
@mock.patch("django.dispatch.dispatcher.Signal.send")
def test_register_host(self, mock_signal):
# Assert when project doesn't exist
with self.assertRaises(CommandError):
management.call_command("register-host", "missing-project", "example.com")
Expand Down
1 change: 0 additions & 1 deletion promgen/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from promgen.notification.email import NotificationEmail
from promgen.tests import PromgenTest


TEST_SETTINGS = PromgenTest.data_yaml('examples', 'promgen.yml')
TEST_ALERT = PromgenTest.data('examples', 'alertmanager.json')

Expand Down
9 changes: 5 additions & 4 deletions promgen/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import requests

from promgen import models, views
from promgen.tests import PromgenTest

from django.test import override_settings
from django.urls import reverse

from promgen import models, views
from promgen.tests import PromgenTest

TEST_SETTINGS = PromgenTest.data_yaml('examples', 'promgen.yml')
TEST_ALERT = PromgenTest.data('examples', 'alertmanager.json')
TEST_IMPORT = PromgenTest.data('examples', 'import.json')
Expand All @@ -19,7 +19,8 @@
class RouteTests(PromgenTest):
longMessage = True

def setUp(self):
@mock.patch('django.dispatch.dispatcher.Signal.send')
def setUp(self, mock_signal):
self.user = self.add_force_login(id=999, username="Foo")

@override_settings(PROMGEN=TEST_SETTINGS)
Expand Down
3 changes: 2 additions & 1 deletion promgen/tests/test_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@


class SilenceTest(PromgenTest):
def setUp(self):
@mock.patch("django.dispatch.dispatcher.Signal.send")
def setUp(self, mock_signal):
self.user = self.add_force_login(id=999, username="Foo")

@override_settings(PROMGEN=TEST_SETTINGS)
Expand Down
6 changes: 3 additions & 3 deletions promgen/tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from unittest import mock

from django.test import override_settings
from django.urls import reverse

from promgen import models, views
from promgen.notification.webhook import NotificationWebhook
from promgen.tests import PromgenTest

from django.test import override_settings
from django.urls import reverse

TEST_SETTINGS = PromgenTest.data_yaml("examples", "promgen.yml")
TEST_ALERT = PromgenTest.data("examples", "alertmanager.json")

Expand Down