-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,108 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
A management command that takes in a string and sends it as an error. | ||
""" | ||
import logging | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('error', type=str) | ||
|
||
def handle(self, error, *args, **options): | ||
logger = logging.getLogger('error_emailer') | ||
logger.error(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
""" | ||
""" | ||
import datetime | ||
import json | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
from opal.core import subrecords | ||
from opal import models | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def count_created_last_week(self, model): | ||
last_week = datetime.datetime.now() - datetime.timedelta(7) | ||
return model.objects.filter(created__gte=last_week).count() | ||
|
||
def handle(self, *args, **options): | ||
# we want to catch the output, so lets not output info level logging | ||
root_logger = logging.getLogger('') | ||
root_logger.setLevel(logging.ERROR) | ||
result = dict( | ||
all_time=dict( | ||
Episode=models.Episode.objects.count() | ||
), | ||
last_week=dict( | ||
Episode=self.count_created_last_week(models.Episode) | ||
) | ||
) | ||
|
||
for subrecord in subrecords.subrecords(): | ||
count_all_time = subrecord.objects.count() | ||
count_last_week = self.count_created_last_week(subrecord) | ||
|
||
result["all_time"][subrecord.get_display_name()] = count_all_time | ||
result["last_week"][subrecord.get_display_name()] = count_last_week | ||
self.stdout.write(json.dumps(result, indent=4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from opal.core.test import OpalTestCase | ||
from elcid.management.commands import error_emailer | ||
import mock | ||
|
||
|
||
class ErrorEmailerTestCase(OpalTestCase): | ||
|
||
@mock.patch('elcid.management.commands.error_emailer.logging') | ||
def test_error_emailer(self, logging): | ||
command = error_emailer.Command() | ||
command.handle("Some error") | ||
logging.getLogger.assert_called_once_with("error_emailer") | ||
logging.getLogger().error.assert_called_once_with("Some error") | ||
|
||
def test_add_arguments(self): | ||
command = error_emailer.Command() | ||
parser = mock.MagicMock() | ||
command.add_arguments(parser) | ||
parser.add_argument.assert_called_once_with("error", type=str) |
Oops, something went wrong.