'Test that a custom policy can be created with an IP address and
an arbitrary URL.'

def test_custom_policy_all(self):

    url = 'http://1234567.cloudfront.com/test.txt'
    expires = 999999
    valid_after = 111111
    ip_range = '192.168.0.0/24'
    policy = self.dist._custom_policy(url, expires=expires, valid_after=valid_after, ip_address=ip_range)
    policy = json.loads(policy)
    self.assertEqual(1, len(policy.keys()))
    statements = policy['Statement']
    self.assertEqual(1, len(statements))
    statement = statements[0]
    resource = statement['Resource']
    self.assertEqual(url, resource)
    condition = statement['Condition']
    self.assertEqual(3, len(condition.keys()))
    date_less_than = condition['DateLessThan']
    self.assertEqual(1, len(date_less_than.keys()))
    aws_epoch_time = date_less_than['AWS:EpochTime']
    self.assertEqual(expires, aws_epoch_time)
    date_greater_than = condition['DateGreaterThan']
    self.assertEqual(1, len(date_greater_than.keys()))
    aws_epoch_time = date_greater_than['AWS:EpochTime']
    self.assertEqual(valid_after, aws_epoch_time)
    ip_address = condition['IpAddress']
    self.assertEqual(1, len(ip_address.keys()))
    source_ip = ip_address['AWS:SourceIp']
    self.assertEqual(ip_range, source_ip)
