from __future__ import absolute_import

from django.core.urlresolvers import reverse

from sentry.testutils import TestCase, PermissionTestCase


class OrganizationStatsPermissionTest(PermissionTestCase):
    def setUp(self):
        super(OrganizationStatsPermissionTest, self).setUp()
        self.path = reverse('sentry-organization-stats', args=[self.organization.slug])

    def test_teamless_admin_cannot_load(self):
        self.assert_teamless_admin_cannot_access(self.path)

    def test_org_member_cannot_load(self):
        self.assert_org_member_cannot_access(self.path)

    def test_org_admin_can_load(self):
        self.assert_org_admin_can_access(self.path)


class OrganizationStatsTest(TestCase):
    def test_renders_with_context(self):
        organization = self.create_organization(name='foo', owner=self.user)
        team_1 = self.create_team(name='foo', organization=organization)
        team_2 = self.create_team(name='bar', organization=organization)

        path = reverse('sentry-organization-stats', args=[organization.slug])

        self.login_as(self.user)

        resp = self.client.get(path)

        assert resp.status_code == 200

        self.assertTemplateUsed(resp, 'sentry/organization-stats.html')

        assert resp.context['organization'] == organization
