# -*- coding: utf-8 -*-

from __future__ import absolute_import

from sentry.models import Event, Group, GroupTagValue, TagValue, TagKey
from sentry.runner.commands.cleanup import cleanup
from sentry.testutils import CliTestCase

ALL_MODELS = (Event, Group, GroupTagValue, TagValue, TagKey)


class SentryCleanupTest(CliTestCase):
    fixtures = ['tests/fixtures/cleanup.json']

    def test_simple(self):
        rv = self.runner.invoke(cleanup, ['--days=1'])
        assert rv.exit_code == 0, rv.output

        for model in ALL_MODELS:
            assert model.objects.count() == 0

    def test_project(self):
        orig_counts = {}
        for model in ALL_MODELS:
            orig_counts[model] = model.objects.count()

        rv = self.runner.invoke(cleanup, ['--days=1', '--project=2'])
        assert rv.exit_code == 0, rv.output

        for model in ALL_MODELS:
            assert model.objects.count() == orig_counts[model]

        rv = self.runner.invoke(cleanup, ['--days=1', '--project=1'])
        assert rv.exit_code == 0, rv.output

        for model in ALL_MODELS:
            assert model.objects.count() == 0

@@ -370,16 +370,38 @@
 p.json'%5D
+%0A    command = cleanup
 %0A%0A    de
@@ -443,32 +443,15 @@
 elf.
-runner.invoke(cleanup, %5B
+invoke(
 '--d
@@ -456,17 +456,16 @@
 -days=1'
-%5D
 )%0A      
@@ -747,32 +747,15 @@
 elf.
-runner.invoke(cleanup, %5B
+invoke(
 '--d
@@ -775,17 +775,16 @@
 oject=2'
-%5D
 )%0A      
@@ -941,32 +941,15 @@
 elf.
-runner.invoke(cleanup, %5B
+invoke(
 '--d
@@ -969,17 +969,16 @@
 oject=1'
-%5D
 )%0A      

Update test_cleanup