def test_decode_invalid(self):
     self.assertRaises(ValueError, decode_iso_datetime,
                       IsoDateTime('1970-02-31T04:06:08Z'))
     self.assertRaises(ValueError, decode_iso_datetime,
                       IsoDateTime('1970-02-03T04:06:08.666Z'))
     # Datetime without a zone
     self.assertRaises(ValueError, decode_iso_datetime,
                       IsoDateTime('1970-02-03T04:06:08'))
Beispiel #2
0
 def get_domain_by_handle(self, handle):
     print("{}.get_domain_by_handle({})".format(self.__class__.__name__,
                                                handle))
     if handle == 'kochanski.cz':
         raise OBJECT_NOT_FOUND()
     return Domain(handle, 'LISTER', [], None, None, 'REGGIE', [],
                   IsoDateTime('1970-01-01T00:00:00Z'), None, None,
                   IsoDate('2030-01-01'),
                   IsoDateTime('2030-01-01T00:00:00Z'), None, None, None,
                   None)
Beispiel #3
0
 def _get_nsset(self, fqdn1='a.ns.nic.cz', fqdn2='b.ns.nic.cz'):
     ip1 = IPAddress(address='194.0.12.1', version=IPv4)
     ip2 = IPAddress(address='194.0.13.1', version=IPv4)
     return NSSet(handle='NSSET-1',
                  nservers=[
                      NameServer(fqdn=fqdn1, ip_addresses=[ip1]),
                      NameServer(fqdn=fqdn2, ip_addresses=[ip2]),
                  ],
                  tech_contact_handles=['KONTAKT'],
                  registrar_handle='REG-FRED_A',
                  created=IsoDateTime('2015-12-09T16:16:30Z'),
                  changed=IsoDateTime('2015-12-10T17:17:31Z'),
                  last_transfer=IsoDateTime('2015-12-11T18:18:32Z'),
                  statuses=[STATUS_LINKED])
Beispiel #4
0
 def _get_keyset(self):
     return KeySet(
         handle='KEYSID-1',
         dns_keys=[
             DNSKey(
                 flags=257,
                 protocol=3,
                 alg=5,
                 public_key=
                 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8')
         ],
         tech_contact_handles=['KONTAKT'],
         registrar_handle='REG-FRED_A',
         created=IsoDateTime('2015-12-09T16:16:30Z'),
         changed=IsoDateTime('2015-12-10T17:17:31Z'),
         last_transfer=IsoDateTime('2015-12-11T18:18:32Z'),
         statuses=[STATUS_LINKED])
 def test_encode(self):
     self.assertEqual(
         encode_iso_datetime(
             datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc)),
         IsoDateTime('1970-02-01T12:14:16+00:00'))
     self.assertEqual(
         encode_iso_datetime(
             datetime(1970, 2, 1, 12, 14, 16, 123456, tzinfo=pytz.utc)),
         IsoDateTime('1970-02-01T12:14:16.123456+00:00'))
     self.assertEqual(
         encode_iso_datetime(
             datetime(1970,
                      2,
                      1,
                      12,
                      14,
                      16,
                      123456,
                      tzinfo=pytz.FixedOffset(90))),
         IsoDateTime('1970-02-01T12:14:16.123456+01:30'))
Beispiel #6
0
 def _get_domain(self, **kwargs):
     obj = Domain(handle='fred.cz',
                  registrant_handle='KONTAKT',
                  admin_contact_handles=['KONTAKT'],
                  nsset_handle='NSSET-1',
                  keyset_handle='KEYSID-1',
                  registrar_handle='REG-FRED_A',
                  statuses=[],
                  registered=IsoDateTime('2015-12-09T16:16:30Z'),
                  changed=IsoDateTime('2015-12-10T17:17:31Z'),
                  last_transfer=IsoDateTime('2015-12-11T18:18:32Z'),
                  expire=IsoDate('2018-12-09'),
                  expire_time_estimate=IsoDate('2018-12-09'),
                  expire_time_actual=None,
                  validated_to=None,
                  validated_to_time_estimate=None,
                  validated_to_time_actual=None)
     field_names = obj.__dict__.keys()
     for key, value in kwargs.items():
         assert key in field_names, "Unknown arg '%s' in _get_domain." % key
         setattr(obj, key, value)
     return obj
Beispiel #7
0
 def get_contact_by_handle(self, handle):
     print("{}.get_contact_by_handle({})".format(self.__class__.__name__,
                                                 handle))
     if handle == 'KOCHANSKI':
         raise OBJECT_NOT_FOUND()
     nothing = DisclosableString('', False)
     no_address = DisclosablePlaceAddress(
         PlaceAddress('', '', '', '', '', '', ''), False)
     no_ident = DisclosableContactIdentification(
         ContactIdentification('OP', ''), False)
     return Contact(handle, nothing, nothing, no_address, nothing, nothing,
                    nothing, nothing, nothing, no_ident, 'REGGIE', 'REGGIE',
                    IsoDateTime('1970-01-01T00:00:00Z'), None, None, [])
Beispiel #8
0
 def _get_contact(self, **kwargs):
     disclose = kwargs.pop("disclose", True)
     address = PlaceAddress(street1='Street 756/48',
                            street2='',
                            street3='',
                            city='Prague',
                            stateorprovince='',
                            postalcode='12300',
                            country_code='CZ')
     obj = Contact(
         handle='KONTAKT',
         organization=DisclosableString(value='Company L.t.d.',
                                        disclose=disclose),
         name=DisclosableString(value='Arnold Rimmer', disclose=disclose),
         address=DisclosablePlaceAddress(value=address, disclose=disclose),
         phone=DisclosableString(value='+420.728012345', disclose=disclose),
         fax=DisclosableString(value='+420.728023456', disclose=disclose),
         email=DisclosableString(value='*****@*****.**', disclose=disclose),
         notify_email=DisclosableString(value='*****@*****.**',
                                        disclose=disclose),
         vat_number=DisclosableString(value='CZ456123789',
                                      disclose=disclose),
         identification=DisclosableContactIdentification(
             value=ContactIdentification(identification_type='OP',
                                         identification_data='333777000'),
             disclose=disclose,
         ),
         creating_registrar_handle='REG-FRED_A',
         sponsoring_registrar_handle='REG-FRED_A',
         created=IsoDateTime('2015-12-15T07:56:24Z'),
         changed=IsoDateTime('2015-12-16T08:32:12Z'),
         last_transfer=IsoDateTime('2015-12-17T09:48:25Z'),
         statuses=[STATUS_LINKED])
     field_names = obj.__dict__.keys()
     for key, value in kwargs.items():
         assert key in field_names, "Unknown arg '%s' in _get_contact." % key
         setattr(obj, key, value)
     return obj
Beispiel #9
0
 def get_contact(self):
     address = PlaceAddress('', '', '', '', '', '', '')
     ident = ContactIdentification('OP', '')
     return Contact(
         'kryten',
         DisclosableString('', True),
         DisclosableString('', True),
         DisclosablePlaceAddress(address, True),
         DisclosableString('', True),
         DisclosableString('', True),
         DisclosableString('', True),
         DisclosableString('', True),
         DisclosableString('', True),
         DisclosableContactIdentification(ident, True),
         '',
         '',
         IsoDateTime('1988-09-06T20:00:00Z'),
         None,
         None,
         [])
Beispiel #10
0
def make_keyset(statuses=None):
    """Return a key set object."""
    return KeySet(handle=sentinel.handle, dns_keys=[], tech_contact_handles=[], registrar_handle=sentinel.registrar,
                  created=IsoDateTime('1970-01-01T00:00:00Z'), changed=None, last_transfer=None,
                  statuses=(statuses or []))
Beispiel #11
0
 def get_keyset_by_handle(self, handle):
     print("{}.get_keyset_by_handle({})".format(self.__class__.__name__,
                                                handle))
     return KeySet(handle, [], [], 'REGGIE',
                   IsoDateTime('1970-01-01T00:00:00Z'), None, None, [])
Beispiel #12
0
 def test_decode_isodatetime_naive(self):
     recoder = RdapCorbaRecoder()
     with self.settings(USE_TZ=False, TIME_ZONE='Europe/Prague'):
         self.assertEqual(
             recoder.decode(IsoDateTime('2001-02-03T12:13:14Z')),
             datetime(2001, 2, 3, 13, 13, 14))
Beispiel #13
0
 def test_decode_isodatetime_aware(self):
     recoder = RdapCorbaRecoder()
     with self.settings(USE_TZ=True):
         self.assertEqual(
             recoder.decode(IsoDateTime('2001-02-03T12:13:14Z')),
             datetime(2001, 2, 3, 12, 13, 14, tzinfo=timezone.utc))
Beispiel #14
0
def encode_iso_datetime(value):
    """Encode aware datetime object into IsoDateTime struct."""
    if value.tzinfo is None:
        raise ValueError("Only aware datetime objects can be encoded.")
    return IsoDateTime(value.isoformat())