Skip to content

Commit feecb35

Browse files
committed
wip
1 parent 676bc22 commit feecb35

6 files changed

Lines changed: 23 additions & 33 deletions

File tree

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.core.management.base import BaseCommand, CommandError
1+
from django.core.management.base import BaseCommand
22

33
from elasticsearch_metrics.registry import djelme_registry
44
from elasticsearch_metrics.management.color import color_style
@@ -14,18 +14,13 @@ def add_arguments(self, parser):
1414

1515
def handle(self, *args, **options):
1616
style = color_style()
17-
if options["app_label"]:
18-
if options["app_label"] not in djelme_registry.each_app_label():
19-
raise CommandError(
20-
"No recordtypes found for app '{}'".format(options["app_label"])
21-
)
22-
app_labels = [options["app_label"]]
23-
else:
24-
app_labels = list(djelme_registry.each_app_label())
25-
for app_label in app_labels:
26-
self.stdout.write(
27-
"Recordtypes for '{}':".format(app_label), style.MIGRATE_HEADING
28-
)
17+
_app_labels = (
18+
[options["app_label"]]
19+
if options["app_label"]
20+
else list(djelme_registry.each_app_label())
21+
)
22+
for app_label in _app_labels:
23+
self.stdout.write(f"Recordtypes for {app_label!r}", style.MIGRATE_HEADING)
2924
for _recordtype in djelme_registry.each_recordtype(app_label=app_label):
3025
_recordtype_name = style.TYPENAME(_recordtype.__name__)
3126
self.stdout.write(f"{app_label}.{_recordtype_name}")

elasticsearch_metrics/tests/test_management_commands/test_djelme_check.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ def test_exits_with_success(self):
4444
+ self.mock8_simple_check_djelme_setup.call_count
4545
)
4646
assert _call_count == len(list(registry.each_recordtype()))
47+
48+
def test_with_invalid_app(self):
49+
with self.assertRaises(LookupError):
50+
self.run_mgmt_command(djelme_backend_check, "notanapp")

elasticsearch_metrics/tests/test_management_commands/test_djelme_indexes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ def test_delete_expired_really(self):
9898
mock.call(index="dummy8app_happen_2016.4."),
9999
],
100100
)
101+
102+
def test_with_invalid_app(self):
103+
with self.assertRaises(LookupError):
104+
self.run_mgmt_command(djelme_indexes, "notanapp")

elasticsearch_metrics/tests/test_management_commands/test_djelme_setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import unittest
22

3-
from django.core.management import CommandError
4-
53
from elasticsearch_metrics.imps import elastic8
64
from elasticsearch_metrics.management.commands import djelme_backend_setup
75
from elasticsearch_metrics.registry import djelme_registry
@@ -32,9 +30,8 @@ def test_without_args(self):
3230
assert "Synchronized recordtypes." in out
3331

3432
def test_with_invalid_app(self):
35-
with self.assertRaises(CommandError) as _raises:
33+
with self.assertRaises(LookupError):
3634
self.run_mgmt_command(djelme_backend_setup, "notanapp")
37-
assert "No recordtypes found for app 'notanapp'" in str(_raises.exception)
3835

3936
def test_with_app_label(self):
4037
class DummyMetric2(elastic8.SimpleRecord):

elasticsearch_metrics/tests/test_management_commands/test_djelme_types.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33

44

55
class TestDjelmeTypesCommand(SimpleDjelmeTestCase):
6-
def test_without_args_by_name(self):
6+
def test_without_args(self):
77
out, err = self.run_mgmt_command(djelme_backend_types)
88
assert "Dummy8Event" in out
99
assert "Monthly8Event" in out
1010
assert "ThingHappened" in out
1111
assert "ThingHappeningsReport" in out
1212
assert "SimpleKV" in out
1313

14-
def test_without_args_by_command(self):
15-
out, err = self.run_mgmt_command("djelme_backend_types")
16-
assert "Dummy8Event" in out
17-
assert "Monthly8Event" in out
18-
assert "ThingHappened" in out
19-
assert "ThingHappeningsReport" in out
20-
assert "SimpleKV" in out
14+
def test_with_invalid_app(self):
15+
with self.assertRaises(LookupError):
16+
self.run_mgmt_command(djelme_backend_types, "notanapp")

elasticsearch_metrics/tests/test_registry.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def test_get_recordtype(self):
3131

3232
with self.assertRaises(LookupError) as excinfo:
3333
djelme_registry.get_recordtype("notanapp", "Dummy8Event")
34-
assert (
35-
"No recordtypes found in app with label 'notanapp'."
36-
in excinfo.exception.args[0]
37-
)
34+
assert "'notanapp'" in excinfo.exception.args[0]
3835

3936
def test_get_recordtypes(self):
4037
class AnotherRecord(elastic8.TimeseriesRecord):
@@ -50,10 +47,7 @@ class Meta:
5047

5148
with self.assertRaises(LookupError) as excinfo:
5249
list(djelme_registry.each_recordtype(app_label="notanapp"))
53-
assert (
54-
"No recordtypes found in app with label 'notanapp'."
55-
in excinfo.exception.args[0]
56-
)
50+
assert "'notanapp'" in excinfo.exception.args[0]
5751

5852
def test_get_recordtypes_excludes_abstract_recordtypes(self):
5953
class AbstractRecord(elastic8.TimeseriesRecord):

0 commit comments

Comments
 (0)