Example #1
0
 def setUp(self):
     super(OrganizationsAdminTestCase, self).setUp()
     self.org_admin = OrganizationAdmin(Organization, AdminSite())
     self.request = RequestFactory().get('/admin')
     self.admin_user = UserFactory(is_staff=True)
     self.request.session = 'session'
     self.request.user = self.admin_user
     self.request._messages = FallbackStorage(self.request)  # pylint: disable=protected-access
Example #2
0
class OrganizationsAdminTestCase(utils.OrganizationsTestCaseBase):
    """
    Test Case module for Organizations Admin
    """
    def setUp(self):
        super(OrganizationsAdminTestCase, self).setUp()
        self.org_admin = OrganizationAdmin(Organization, AdminSite())
        self.request = RequestFactory().get('/admin')
        self.admin_user = UserFactory(is_staff=True)
        self.request.session = 'session'
        self.request.user = self.admin_user
        self.request._messages = FallbackStorage(self.request)  # pylint: disable=protected-access

    def test_default_fields(self):
        """
        Test: organization default fields should be name, description and active.
        """
        self.assertEqual(
            list(self.org_admin.get_form(self.request).base_fields),
            ['name', 'short_name', 'description', 'logo', 'active'])

    def test_organization_actions(self):
        """
        Test: organization should have its custom actions.
        """
        actions = self.org_admin.get_actions(self.request)
        self.assertIn('activate_selected', actions.keys())
        self.assertIn('deactivate_selected', actions.keys())
        self.assertNotIn('delete_selected', actions.keys())

    def test_deactivate_selected_should_deactivate_active_organizations(self):
        """
        Test: action deactivate_selected should deactivate an activated organization.
        """
        create_organization(1, active=True)
        queryset = Organization.objects.filter(pk=1)
        self.org_admin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)

    def test_deactivate_selected_should_deactivate_multiple_active_organizations(
            self):
        """
        Test: action deactivate_selected should deactivate the multiple activated organization.
        """
        for i in range(2):
            create_organization(i, active=True)
        queryset = Organization.objects.all()
        self.org_admin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)
        self.assertFalse(Organization.objects.get(pk=2).active)

    def test_activate_selected_should_activate_deactivated_organizations(self):
        """
        Test: action activate_selected should activate an deactivated organization.
        """
        create_organization(1, active=False)
        queryset = Organization.objects.filter(pk=1)
        self.org_admin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)

    def test_activate_selected_should_activate_multiple_deactivated_organizations(
            self):
        """
        Test: action activate_selected should activate the multiple deactivated organization.
        """
        for i in range(2):
            create_organization(i, active=True)
        queryset = Organization.objects.all()
        self.org_admin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)
        self.assertTrue(Organization.objects.get(pk=2).active)
Example #3
0
 def setUp(self):
     self.request = HttpRequest()
     self.orgAdmin = OrganizationAdmin(Organization, AdminSite())
     setattr(self.request, 'session', 'session')
     messages = FallbackStorage(self.request)
     setattr(self.request, '_messages', messages)
Example #4
0
class OrganizationsAdminTestCase(utils.OrganizationsTestCaseBase):
    """
    Test Case module for Organizations Admin
    """

    def setUp(self):
        self.request = HttpRequest()
        self.orgAdmin = OrganizationAdmin(Organization, AdminSite())
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def test_default_fields(self):
        """
        Test: organization default fields should be name, description and active.
        """
        self.assertEqual(list(self.orgAdmin.get_form(self.request).base_fields),
                         ['name', 'short_name', 'description', 'logo', 'active'])

    def test_organization_actions(self):
        """
        Test: organization should have its custom actions.
        """
        actions = self.orgAdmin.get_actions(self.request)
        self.assertTrue('activate_selected' in actions.keys())
        self.assertTrue('deactivate_selected' in actions.keys())
        self.assertTrue('delete_selected' not in actions.keys())

    def test_deactivate_selected_should_deactivate_active_organizations(self):
        """
        Test: action deactivate_selected should deactivate an activated organization.
        """
        create_organization(active=True)
        queryset = Organization.objects.filter(pk=1)
        self.orgAdmin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)

    def test_deactivate_selected_should_deactivate_multiple_active_organizations(self):
        """
        Test: action deactivate_selected should deactivate the multiple activated organization.
        """
        for __ in xrange(0, 2):
            create_organization(active=True)
        queryset = Organization.objects.all()
        self.orgAdmin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)
        self.assertFalse(Organization.objects.get(pk=2).active)

    def test_activate_selected_should_activate_deactivated_organizations(self):
        """
        Test: action activate_selected should activate an deactivated organization.
        """
        create_organization(active=False)
        queryset = Organization.objects.filter(pk=1)
        self.orgAdmin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)

    def test_activate_selected_should_activate_multiple_deactivated_organizations(self):
        """
        Test: action activate_selected should activate the multiple deactivated organization.
        """
        for __ in xrange(0, 2):
            create_organization(active=True)
        queryset = Organization.objects.all()
        self.orgAdmin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)
        self.assertTrue(Organization.objects.get(pk=2).active)
Example #5
0
 def setUp(self):
     self.request = HttpRequest()
     self.orgAdmin = OrganizationAdmin(Organization, AdminSite())
     setattr(self.request, 'session', 'session')
     messages = FallbackStorage(self.request)
     setattr(self.request, '_messages', messages)
Example #6
0
class OrganizationsAdminTestCase(utils.OrganizationsTestCaseBase):
    """
    Test Case module for Organizations Admin
    """
    def setUp(self):
        self.request = HttpRequest()
        self.orgAdmin = OrganizationAdmin(Organization, AdminSite())
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

    def test_default_fields(self):
        """
        Test: organization default fields should be name, description and active.
        """
        self.assertEqual(
            list(self.orgAdmin.get_form(self.request).base_fields),
            ['name', 'short_name', 'description', 'logo', 'active'])

    def test_organization_actions(self):
        """
        Test: organization should have its custom actions.
        """
        actions = self.orgAdmin.get_actions(self.request)
        self.assertTrue('activate_selected' in actions.keys())
        self.assertTrue('deactivate_selected' in actions.keys())
        self.assertTrue('delete_selected' not in actions.keys())

    def test_deactivate_selected_should_deactivate_active_organizations(self):
        """
        Test: action deactivate_selected should deactivate an activated organization.
        """
        create_organization(active=True)
        queryset = Organization.objects.filter(pk=1)
        self.orgAdmin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)

    def test_deactivate_selected_should_deactivate_multiple_active_organizations(
            self):
        """
        Test: action deactivate_selected should deactivate the multiple activated organization.
        """
        for __ in xrange(0, 2):
            create_organization(active=True)
        queryset = Organization.objects.all()
        self.orgAdmin.deactivate_selected(self.request, queryset)
        self.assertFalse(Organization.objects.get(pk=1).active)
        self.assertFalse(Organization.objects.get(pk=2).active)

    def test_activate_selected_should_activate_deactivated_organizations(self):
        """
        Test: action activate_selected should activate an deactivated organization.
        """
        create_organization(active=False)
        queryset = Organization.objects.filter(pk=1)
        self.orgAdmin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)

    def test_activate_selected_should_activate_multiple_deactivated_organizations(
            self):
        """
        Test: action activate_selected should activate the multiple deactivated organization.
        """
        for __ in xrange(0, 2):
            create_organization(active=True)
        queryset = Organization.objects.all()
        self.orgAdmin.activate_selected(self.request, queryset)
        self.assertTrue(Organization.objects.get(pk=1).active)
        self.assertTrue(Organization.objects.get(pk=2).active)
Example #7
0
 def setUp(self):
     super(OrganizationsAdminTestCase, self).setUp()
     self.request = HttpRequest()
     self.org_admin = OrganizationAdmin(Organization, AdminSite())
     self.request.session = 'session'
     self.request._messages = FallbackStorage(self.request)  # pylint: disable=protected-access