<s> from __future__ import absolute_import , unicode_literals <EOL> from django . test . client import Client <EOL> from django . test import TestCase <EOL> from django . test . client import RequestFactory <EOL> from django . db import IntegrityError <EOL> from django . core . exceptions import ValidationError <EOL> from . . models import Instance <EOL> from . factory import DatabaseInfraFactory , HostFactory , InstanceFactory <EOL> class InstanceTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . client = Client ( ) <EOL> self . factory = RequestFactory ( ) <EOL> self . databaseinfra = DatabaseInfraFactory ( ) <EOL> self . hostname = HostFactory ( ) <EOL> self . new_instance = InstanceFactory ( address = "<STR_LIT>" , <EOL> port = <NUM_LIT> , <EOL> is_active = True , <EOL> is_arbiter = False , <EOL> databaseinfra = self . databaseinfra ) <EOL> def test_create_instance ( self ) : <EOL> instance = Instance . objects . create ( address = "<STR_LIT>" , <EOL> port = <NUM_LIT> , <EOL> is_active = True , <EOL> is_arbiter = False , <EOL> hostname = self . hostname , <EOL> databaseinfra = self . databaseinfra ) <EOL> self . assertTrue ( instance . id ) <EOL> def test_error_duplicate_instance ( self ) : <EOL> another_instance = self . new_instance <EOL> another_instance . id = None <EOL> self . assertRaises ( IntegrityError , another_instance . save ) <EOL> def test_cleanup_without_engine_raises_exception ( self ) : <EOL> self . new_instance . databaseinfra . engine_id = None <EOL> self . assertRaises ( ValidationError , self . new_instance . clean ) </s>
