Пример #1
0
    def test_unique_fields(self):
        from django.db.utils import IntegrityError
        svc = RpcService()
        svc.site_id = '666'
        svc.site_name = 'sourcename1'
        svc.hostname = "somesite1.va.gov"
        svc.source_type = RpcService.PRODUCTION
        svc.svc_set_id = 1
        svc.save()

        svc = RpcService()
        svc.site_id = '666'
        svc.site_name = 'sourcename2'
        svc.hostname = "somesite2.va.gov"
        svc.source_type = RpcService.PRODUCTION
        svc.svc_set_id = 1
        try:
            svc.save()
        except IntegrityError as e:
            self.assertEqual('column site_id is not unique', str(e))

        svc = RpcService()
        svc.site_id = '667'
        svc.site_name = 'sourcename1'
        svc.hostname = "somesite3.va.gov"
        svc.source_type = RpcService.PRODUCTION
        svc.svc_set_id = 1
        try:
            svc.save()
        except IntegrityError as e:
            self.assertEqual('column site_name is not unique', str(e))

        svc = RpcService()
        svc.site_id = '668'
        svc.site_name = 'sourcename2'
        svc.hostname = "somesite1.va.gov"
        svc.source_type = RpcService.PRODUCTION
        svc.svc_set_id = 1
        try:
            svc.save()
        except IntegrityError as e:
            self.assertEqual('column hostname is not unique', str(e))
Пример #2
0
    def test_required_fields(self):
        from django.core.exceptions import ValidationError
        svc = RpcService()

        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('site_id is a required field', e.messages[0])

        svc.site_id = '666'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('site_name is a required field', e.messages[0])

        svc.site_name = 'test'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = 'something'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = '127'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = '127.'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = '127.1'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = '127.0.0.'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = 'somesite.'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = 'somesite.va'
        try:
            svc.save()
        except ValidationError as e:
            self.assertEqual('hostname is missing or invalid', e.messages[0])

        svc.hostname = 'somesite.va.gov'
        try:
            svc.save()
        except IntegrityError as e:
            self.assertEqual('evrpc_services.svc_set_id may not be NULL', e.args[0])

        svc.svc_set_id = 1
        try:
            svc.save()
            pass
        except ValidationError:
            self.fail('This should succeed')