# 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
class RuleWithSampleRulesTests(TestCase):
    def setUp(self):
        self.rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        self.rule2 = models.Rule.objects.create(url_pattern='2', action='A')

    def test_default_order_is_by_rank(self):
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '1')
        self.assertEqual(rules[1].url_pattern, '2')

    def test_move_up(self):
        self.rule2.move_up()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '2')
        self.assertEqual(rules[1].url_pattern, '1')

    def test_move_up_first_rule_does_nothing(self):
        self.rule1.move_up()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '1')
        self.assertEqual(rules[1].url_pattern, '2')

    def test_move_down(self):
        self.rule1.move_down()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '2')
        self.assertEqual(rules[1].url_pattern, '1')

    def test_move_down_below_default_rule(self):
        self.rule1.move_down()

# 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

class RuleWithSampleRulesTests(TestCase):
    def setUp(self):
        self.rule1 = models.Rule.objects.create(url_pattern='1', action='A')
        self.rule2 = models.Rule.objects.create(url_pattern='2', action='A')

    def test_default_order_is_by_rank(self):
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '1')
        self.assertEqual(rules[1].url_pattern, '2')

    def test_move_up(self):
        self.rule2.move_up()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '2')
        self.assertEqual(rules[1].url_pattern, '1')

    def test_move_up_first_rule_does_nothing(self):
        self.rule1.move_up()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '1')
        self.assertEqual(rules[1].url_pattern, '2')

    def test_move_down(self):
        self.rule1.move_down()
        rules = models.Rule.objects.all()
        self.assertEqual(rules[0].url_pattern, '2')
        self.assertEqual(rules[1].url_pattern, '1')

    def test_move_down_below_default_rule(self):
        self.rule1.move_down()

        self.rule1.move_down()