# Path: mongonaut/sites.py
# class BaseMongoAdmin(object):
#     """Base model class for replication django.site.ModelAdmin class.
#     """
# 
#     search_fields = []
# 
#     # Show the fields to be displayed as columns
#     # TODO: Confirm that this is what the Django admin uses
#     list_fields = []
# 
#     #This shows up on the DocumentListView of the Posts
#     list_actions = []
# 
#     # This shows up in the DocumentDetailView of the Posts.
#     document_actions = []
# 
#     # shows up on a particular field
#     field_actions = {}
# 
#     fields = None
#     exclude = None
#     fieldsets = None
#     form = forms.ModelForm
#     filter_vertical = ()
#     filter_horizontal = ()
#     radio_fields = {}
#     prepopulated_fields = {}
#     formfield_overrides = {}
#     readonly_fields = ()
#     ordering = None
# 
#     def has_view_permission(self, request):
#         """
#         Returns True if the given HttpRequest has permission to view
#         *at least one* page in the mongonaut site.
#         """
#         return request.user.is_authenticated and request.user.is_active
# 
#     def has_edit_permission(self, request):
#         """ Can edit this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_staff
# 
#     def has_add_permission(self, request):
#         """ Can add this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_staff
# 
#     def has_delete_permission(self, request):
#         """ Can delete this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_superuser


import unittest
from django.test import RequestFactory
from mongonaut.sites import BaseMongoAdmin
from common.utils import DummyUser
        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))

        self.req.user = DummyUser(is_active=False)
        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))
        
        self.req.user = DummyUser(is_authenticated=False)
        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))

    
    def testHasAddPerms(self):
        self.req.user = DummyUser(is_authenticated=True, is_active=True,
                                  is_staff=True)
        
        self.assertTrue(BaseMongoAdmin().has_add_permission(self.req))

    def testHasAddPermsInvalid(self):
        self.req.user = DummyUser(is_staff=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))

        self.req.user = DummyUser(is_active=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))
        
        self.req.user = DummyUser(is_authenticated=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))


    def testHasDeletPerms(self):
        self.req.user = DummyUser(is_authenticated=True, is_active=True,
                                  is_superuser=True)
        

# Path: mongonaut/sites.py
# class BaseMongoAdmin(object):
#     """Base model class for replication django.site.ModelAdmin class.
#     """
# 
#     search_fields = []
# 
#     # Show the fields to be displayed as columns
#     # TODO: Confirm that this is what the Django admin uses
#     list_fields = []
# 
#     #This shows up on the DocumentListView of the Posts
#     list_actions = []
# 
#     # This shows up in the DocumentDetailView of the Posts.
#     document_actions = []
# 
#     # shows up on a particular field
#     field_actions = {}
# 
#     fields = None
#     exclude = None
#     fieldsets = None
#     form = forms.ModelForm
#     filter_vertical = ()
#     filter_horizontal = ()
#     radio_fields = {}
#     prepopulated_fields = {}
#     formfield_overrides = {}
#     readonly_fields = ()
#     ordering = None
# 
#     def has_view_permission(self, request):
#         """
#         Returns True if the given HttpRequest has permission to view
#         *at least one* page in the mongonaut site.
#         """
#         return request.user.is_authenticated and request.user.is_active
# 
#     def has_edit_permission(self, request):
#         """ Can edit this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_staff
# 
#     def has_add_permission(self, request):
#         """ Can add this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_staff
# 
#     def has_delete_permission(self, request):
#         """ Can delete this object """
#         return request.user.is_authenticated and request.user.is_active and request.user.is_superuser


# Path: tests/sites_tests.py
import unittest
from django.test import RequestFactory
from mongonaut.sites import BaseMongoAdmin
from common.utils import DummyUser

        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))

        self.req.user = DummyUser(is_active=False)
        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))
        
        self.req.user = DummyUser(is_authenticated=False)
        self.assertFalse(BaseMongoAdmin().has_edit_permission(self.req))

    
    def testHasAddPerms(self):
        self.req.user = DummyUser(is_authenticated=True, is_active=True,
                                  is_staff=True)
        
        self.assertTrue(BaseMongoAdmin().has_add_permission(self.req))

    def testHasAddPermsInvalid(self):
        self.req.user = DummyUser(is_staff=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))

        self.req.user = DummyUser(is_active=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))
        
        self.req.user = DummyUser(is_authenticated=False)
        self.assertFalse(BaseMongoAdmin().has_add_permission(self.req))


    def testHasDeletPerms(self):
        self.req.user = DummyUser(is_authenticated=True, is_active=True,
                                  is_superuser=True)
        

        self.assertTrue(BaseMongoAdmin().has_delete_permission(self.req))