# Path: iprestrict/models.py
# TYPE_LOCATION = 'location'
# TYPE_RANGE = 'range'
#     TYPE_CHOICES = ((TYPE_LOCATION, 'Location based'),
#                     (TYPE_RANGE, 'Range based'))
#     TYPE = None
#     TYPE = TYPE_RANGE
#     TYPE = TYPE_LOCATION
#     ACTION_CHOICES = (
#         ('A', 'ALLOW'),
#         ('D', 'DENY')
#     )
# class IPGroupManager(models.Manager):
# class IPGroup(models.Model):
#     class Meta:
# class RangeBasedIPGroup(IPGroup):
#     class Meta:
# class LocationBasedIPGroup(IPGroup):
#     class Meta:
# class IPRange(models.Model):
#     class Meta:
# class IPLocation(models.Model):
#     class Meta:
# class Rule(models.Model):
#     class Meta:
# class ReloadRulesRequest(models.Model):
#     def get_queryset(self):
#     def __init__(self, *args, **kwargs):
#     def load(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
# def typed_ip_group(ip_group):
#     def load_ranges(self):
#     def ranges(self, ip_type=None):
#     def matches(self, ip):
#     def details_str(self):
#     def load_locations(self):
#     def matches(self, ip):
#     def details_str(self):
#     def start(self):
#     def end(self):
#     def ip_type(self):
#     def __contains__(self, ip):
#     def __str__(self):
#     def __contains__(self, country_code):
#     def __str__(self):
#     def __init__(self, *args, **kwargs):
#     def regex(self):
#     def matches_url(self, url):
#     def matches_ip(self, ip):
#     def is_restricted(self):
#     def is_allowed(self):
#     def action_str(self):
#     def swap_with_rule(self, other):
#     def move_up(self):
#     def move_up_url(self):
#     def move_down_url(self):
#     def move_down(self):
#     def save(self, *args, **kwargs):
#     def request_reload(cls):
#     def last_request():


from django.test import TestCase
from django.http import HttpResponseForbidden
from iprestrict import models
import mock
import iprestrict
        self.assertFalse(rule.is_allowed())
        self.assertTrue(rule.is_restricted())

    def test_matches_url_pattern_regex(self):
        rule = models.Rule(url_pattern='^/pre/[a-d]+[/]?$')
        self.assertTrue(rule.matches_url('/pre/a/'))
        self.assertTrue(rule.matches_url('/pre/a'))
        self.assertFalse(rule.matches_url('/pre/e/'))
        self.assertFalse(rule.matches_url('/pre/a//'))

    def test_rank_is_automatically_assigned_on_creation(self):
        rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        rule2 = models.Rule.objects.create(url_pattern='2', action='A')
        rule10 = models.Rule.objects.create(url_pattern='10', action='A', rank=10)
        rule11 = models.Rule.objects.create(url_pattern='10', action='A')
        self.assertEquals(rule1.rank, 1)
        self.assertEquals(rule2.rank, 2)
        self.assertEquals(rule10.rank, 10)
        self.assertEquals(rule11.rank, 11)

    def test_rank_is_not_changed_on_update(self):
        rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        rule2 = models.Rule.objects.create(url_pattern='2', action='A')
        rule1.action = 'D'
        rule1.save()
        self.assertEquals(rule1.rank, 1)


class RuleWithSampleRulesTests(TestCase):
    def setUp(self):

# Path: iprestrict/models.py
# TYPE_LOCATION = 'location'
# TYPE_RANGE = 'range'
#     TYPE_CHOICES = ((TYPE_LOCATION, 'Location based'),
#                     (TYPE_RANGE, 'Range based'))
#     TYPE = None
#     TYPE = TYPE_RANGE
#     TYPE = TYPE_LOCATION
#     ACTION_CHOICES = (
#         ('A', 'ALLOW'),
#         ('D', 'DENY')
#     )
# class IPGroupManager(models.Manager):
# class IPGroup(models.Model):
#     class Meta:
# class RangeBasedIPGroup(IPGroup):
#     class Meta:
# class LocationBasedIPGroup(IPGroup):
#     class Meta:
# class IPRange(models.Model):
#     class Meta:
# class IPLocation(models.Model):
#     class Meta:
# class Rule(models.Model):
#     class Meta:
# class ReloadRulesRequest(models.Model):
#     def get_queryset(self):
#     def __init__(self, *args, **kwargs):
#     def load(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
# def typed_ip_group(ip_group):
#     def load_ranges(self):
#     def ranges(self, ip_type=None):
#     def matches(self, ip):
#     def details_str(self):
#     def load_locations(self):
#     def matches(self, ip):
#     def details_str(self):
#     def start(self):
#     def end(self):
#     def ip_type(self):
#     def __contains__(self, ip):
#     def __str__(self):
#     def __contains__(self, country_code):
#     def __str__(self):
#     def __init__(self, *args, **kwargs):
#     def regex(self):
#     def matches_url(self, url):
#     def matches_ip(self, ip):
#     def is_restricted(self):
#     def is_allowed(self):
#     def action_str(self):
#     def swap_with_rule(self, other):
#     def move_up(self):
#     def move_up_url(self):
#     def move_down_url(self):
#     def move_down(self):
#     def save(self, *args, **kwargs):
#     def request_reload(cls):
#     def last_request():


# Path: tests/test_models.py
from django.test import TestCase
from django.http import HttpResponseForbidden
from iprestrict import models
import mock
import iprestrict

        self.assertFalse(rule.is_allowed())
        self.assertTrue(rule.is_restricted())

    def test_matches_url_pattern_regex(self):
        rule = models.Rule(url_pattern='^/pre/[a-d]+[/]?$')
        self.assertTrue(rule.matches_url('/pre/a/'))
        self.assertTrue(rule.matches_url('/pre/a'))
        self.assertFalse(rule.matches_url('/pre/e/'))
        self.assertFalse(rule.matches_url('/pre/a//'))

    def test_rank_is_automatically_assigned_on_creation(self):
        rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        rule2 = models.Rule.objects.create(url_pattern='2', action='A')
        rule10 = models.Rule.objects.create(url_pattern='10', action='A', rank=10)
        rule11 = models.Rule.objects.create(url_pattern='10', action='A')
        self.assertEquals(rule1.rank, 1)
        self.assertEquals(rule2.rank, 2)
        self.assertEquals(rule10.rank, 10)
        self.assertEquals(rule11.rank, 11)

    def test_rank_is_not_changed_on_update(self):
        rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        rule2 = models.Rule.objects.create(url_pattern='2', action='A')
        rule1.action = 'D'
        rule1.save()
        self.assertEquals(rule1.rank, 1)


class RuleWithSampleRulesTests(TestCase):
    def setUp(self):

        self.rule1 = models.Rule.objects.create(url_pattern='1', action='A')