def handle(self, *args, **options): from django.contrib.auth import get_user_model settings.__setattr__("CELERY_ALWAYS_EAGER", True) # call_command('footprint_init', skip=True, built_form=True) # # buildings = Building.objects.all() # building_types = BuildingType.objects.all() # placetypes = Placetype.objects.all() flat_built_forms = FlatBuiltForm.objects.all() neighborhood_low = Placetype.objects.get(name="Neighborhood Low") neighborhood_low.update_or_create_flat_built_form() # assert that each flat built form can find its source and matches its source's attributes for fbf in flat_built_forms.iterator(): bf_class = getattr(uf_models, fbf.built_form_type) built_form = bf_class.objects.get(key=fbf.key) for attr, val in fbf.__dict__.items(): if attr == "building_sqft_total": assert attr > 0 if attr.startswith("acres_parcel"): pass if attr.startswith("building_sqft"): pass if attr.endswith("density"): pass if attr == 'single_family_small_lot_density': if val > 0: if fbf.built_form_type == 'Placetype': pass pass
def setUp(self): global tool, wrong_response_interlock, wrong_state_interlock, bad_interlock, disabled_interlock # enable interlock functionality settings.__setattr__('INTERLOCKS_ENABLED', True) interlock_card_category = InterlockCardCategory.objects.get( key='web_relay_http') interlock_card = InterlockCard.objects.create( server=server1, port=port1, category=interlock_card_category) interlock_card2 = InterlockCard.objects.create( server=server2, port=port2, category=interlock_card_category) interlock_card3 = InterlockCard.objects.create( server=server2, port=port2, category=interlock_card_category, enabled=False) disabled_interlock = Interlock.objects.create(card=interlock_card3, channel=3) interlock = Interlock.objects.create(card=interlock_card, channel=1) wrong_response_interlock = Interlock.objects.create( card=interlock_card2, channel=2) wrong_state_interlock = Interlock.objects.create(card=interlock_card2, channel=5) bad_interlock = Interlock.objects.create(card=interlock_card2, channel=3) owner = User.objects.create(username='******', first_name='Testy', last_name='McTester') tool = Tool.objects.create(name='test_tool', primary_owner=owner, interlock=interlock)
def apply_settings(cls): try: sts = cls.objects.all() for setting in sts: settings.__setattr__(setting.key, setting.value) except Exception as e: pass
def setUp(self): global tool, wrong_response_interlock, bad_interlock # enable interlock functionality settings.__setattr__('INTERLOCKS_ENABLED', True) even_port = 124 odd_port = 125 interlock_card_category = InterlockCardCategory.objects.get(key='stanford') interlock_card = InterlockCard.objects.create(server=server1, port=port1, number=1, even_port=even_port, odd_port=odd_port, category=interlock_card_category) interlock_card2 = InterlockCard.objects.create(server=server2, port=port2, number=1, even_port=even_port, odd_port=odd_port, category=interlock_card_category) interlock = Interlock.objects.create(card=interlock_card, channel=1) wrong_response_interlock = Interlock.objects.create(card=interlock_card2, channel=2) bad_interlock = Interlock.objects.create(card=interlock_card2, channel=3) owner = User.objects.create(username='******', first_name='Testy', last_name='McTester') tool = Tool.objects.create(name='test_tool', primary_owner=owner, interlock=interlock)
def test_graphviz_with_no_graphviz(self): """ Makes sure the graphviz method returns an appropriate exception if graphviz path is not specified """ _target = settings._target del _target.GRAPHVIZ_DOT_COMMAND settings.__setattr__('_target', _target) c = Client() try: response = c.get('/test_workflow.png') except Exception, instance: self.assertEqual(u"GRAPHVIZ_DOT_COMMAND constant not set in"\ " settings.py (to specify the absolute path to"\ " graphviz's dot command)", instance.args[0])
def directority(needs, dirname=None, dirpath=None, orbita=None, intersec=None): if orbita and intersec is not None or not orbita == intersec: try: settings.__setattr__(dirname, dirpath) except AttributeError: pass try: dirname = next(needs.__iter__()).upper().replace('-', '_') except StopIteration: return orbita = needs.pop(next(needs.__iter__()))["orbita"] dirpath = os.path.dirname( os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) intersec = sorted(list(set(orbita).intersection(set(os.listdir(dirpath))))) directority(needs, dirname, dirpath, orbita, intersec)
def create_test_db(self, verbosity=0, autoclobber=False): kwargs = self.__create_test_kwargs() if not _IS_JYTHON: old_database = kwargs['database'] max_db_name_length = self.connection.ops.max_db_name_length() kwargs['database'] = truncate_name("%s%s" % ( TEST_DBNAME_PREFIX, old_database ), max_db_name_length) kwargsKeys = list(kwargs.keys()) if ( kwargsKeys.__contains__('port') and kwargsKeys.__contains__('host') ): kwargs['dsn'] = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % ( kwargs.get('dbname'), kwargs.get('host'), kwargs.get('port') ) else: kwargs['dsn'] = '' if kwargsKeys.__contains__('port'): del kwargs['port'] if not autoclobber: confirm = input("Wants to create %s as test database. Type yes to create it else type no" % ( kwargs.get('database') )) if autoclobber or confirm == 'yes': try: if verbosity > 1: print("Creating Test Database %s" % ( kwargs.get('database') )) Database.createdb(**kwargs) except Exception as inst: message = repr(inst) if message.find('Not supported:') != -1: if not autoclobber: confirm = input( "Not able to create test database, %s. Type yes to use %s as test database, or no to exit" % ( message.split(":")[1], old_database )) if autoclobber or confirm == 'yes': kwargs['database'] = old_database self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() else: print("Tests cancelled") sys.exit(1) else: sys.stderr.write("Error occurred during creation of test database: %s" % message) index = message.find('SQLCODE') if ( message != '' ) & ( index != -1 ): error_code = message[( index + 8 ): ( index + 13 )] if error_code != '-1005': print("Tests cancelled") sys.exit(1) else: if not autoclobber: confirm = input( "\nTest database: %s already exist. Type yes to recreate it, or no to exit" % ( kwargs.get('database') )) if autoclobber or confirm == 'yes': if verbosity > 1: print("Recreating Test Database %s" % ( kwargs.get('database') )) Database.recreatedb(**kwargs) else: print("Tests cancelled.") sys.exit(1) else: confirm = input( "Wants to use %s as test database, Type yes to use it as test database or no to exit" % ( old_database )) if confirm == 'yes': kwargs['database'] = old_database self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() else: sys.exit(1) else: self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() test_database = kwargs.get('database') if verbosity > 1: print("Preparing Database...") if djangoVersion[0:2] <= ( 1, 1 ): settings.DATABASE_NAME = test_database settings.__setattr__('PCONNECT', False) call_command('syncdb', verbosity=verbosity, interactive=False) else: self.connection.settings_dict['NAME'] = test_database self.connection.settings_dict['PCONNECT'] = False # Confirm the feature set of the test database if (1, 2) < djangoVersion[0:2] < (1, 5): self.connection.features.confirm() command = 'syncdb' if djangoVersion[0:2] < (1, 7) else 'migrate' call_command(command, database=self.connection.alias, verbosity=verbosity, interactive=False, load_initial_data=False) # We need to then do a flush to ensure that any data installed by custom SQL has been removed. call_command('flush', database=self.connection.alias, verbosity=verbosity, interactive=False) return test_database
self.connection._commit() self.connection.close() else: sys.exit(1) else: self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() test_database = kwargs.get("database") if verbosity > 1: print "Preparing Database..." if djangoVersion[0:2] <= (1, 1): settings.DATABASE_NAME = test_database settings.__setattr__("PCONNECT", False) call_command("syncdb", verbosity=verbosity, interactive=False) else: self.connection.settings_dict["NAME"] = test_database self.connection.settings_dict["PCONNECT"] = False # Confirm the feature set of the test database if (1, 2) < djangoVersion[0:2] < (1, 5): self.connection.features.confirm() if djangoVersion[0:2] < (1, 7): call_command( "syncdb", database=self.connection.alias, verbosity=verbosity, interactive=False, load_initial_data=False, )
self.connection._commit() self.connection.close() else: sys.exit( 1 ) else: self.__clean_up( self.connection.cursor() ) self.connection._commit() self.connection.close() test_database = kwargs.get( 'database' ) if verbosity > 1: print "Preparing Database..." if( djangoVersion[0:2] <= ( 1, 1 ) ): settings.DATABASE_NAME = test_database settings.__setattr__( 'PCONNECT', False ) call_command( 'syncdb', verbosity = verbosity, interactive = False ) else: self.connection.settings_dict['NAME'] = test_database self.connection.settings_dict['PCONNECT'] = False # Confirm the feature set of the test database if( ( 1, 2 ) < djangoVersion[0:2] < (1,5) ): self.connection.features.confirm() if (djangoVersion[0:2] < (1, 7)): call_command( 'syncdb', database = self.connection.alias, verbosity = verbosity, interactive = False, load_initial_data = False ) else: call_command( 'migrate', database = self.connection.alias, verbosity = verbosity, interactive = False, load_initial_data = False ) # We need to then do a flush to ensure that any data installed by custom SQL has been removed. call_command('flush', database=self.connection.alias, verbosity = verbosity, interactive=False) return test_database
def create_test_db(self, verbosity=0, autoclobber=False, keepdb=False, serialize=False): kwargs = self.__create_test_kwargs() if not _IS_JYTHON: old_database = kwargs['database'] max_db_name_length = self.connection.ops.max_db_name_length() kwargs['database'] = truncate_name( "%s%s" % (TEST_DBNAME_PREFIX, old_database), max_db_name_length) kwargsKeys = list(kwargs.keys()) if (kwargsKeys.__contains__('port') and kwargsKeys.__contains__('host')): kwargs[ 'dsn'] = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % ( kwargs.get('dbname'), kwargs.get('host'), kwargs.get('port')) else: kwargs['dsn'] = '' if kwargsKeys.__contains__('port'): del kwargs['port'] if not autoclobber: confirm = input( "Wants to create %s as test database. Type yes to create it else type no" % (kwargs.get('database'))) if autoclobber or confirm == 'yes': try: if verbosity > 1: print(("Creating Test Database %s" % (kwargs.get('database')))) Database.createdb(**kwargs) except Exception as inst: message = repr(inst) if (message.find('Not supported:') != -1): if not autoclobber: confirm = input( "Not able to create test database, %s. Type yes to use %s as test database, or no to exit" % (message.split(":")[1], old_database)) else: confirm = input( "Not able to create test database, %s. Type yes to use %s as test database, or no to exit" % (message.split(":")[1], old_database)) if autoclobber or confirm == 'yes': kwargs['database'] = old_database self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() else: print("Tests cancelled") sys.exit(1) else: sys.stderr.write( "Error occurred during creation of test database: %s" % (message)) index = message.find('SQLCODE') if (message != '') & (index != -1): error_code = message[(index + 8):(index + 13)] if (error_code != '-1005'): print("Tests cancelled") sys.exit(1) else: if not autoclobber: confirm = input( "\nTest database: %s already exist. Type yes to recreate it, or no to exit" % (kwargs.get('database'))) else: confirm = input( "\nTest database: %s already exist. Type yes to recreate it, or no to exit" % (kwargs.get('database'))) if autoclobber or confirm == 'yes': if verbosity > 1: print(("Recreating Test Database %s" % (kwargs.get('database')))) Database.recreatedb(**kwargs) else: print("Tests cancelled.") sys.exit(1) else: confirm = input( "Wants to use %s as test database, Type yes to use it as test database or no to exit" % (old_database)) if confirm == 'yes': kwargs['database'] = old_database self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() else: sys.exit(1) else: self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() test_database = kwargs.get('database') if verbosity > 1: print("Preparing Database...") if (djangoVersion[0:2] <= (1, 1)): settings.DATABASE_NAME = test_database settings.__setattr__('PCONNECT', False) call_command('syncdb', verbosity=verbosity, interactive=False) else: self.connection.settings_dict['NAME'] = test_database self.connection.settings_dict['PCONNECT'] = False # Confirm the feature set of the test database if ((1, 2) < djangoVersion[0:2] < (1, 5)): self.connection.features.confirm() if (djangoVersion[0:2] < (1, 7)): call_command('syncdb', database=self.connection.alias, verbosity=verbosity, interactive=False, load_initial_data=False) else: if (djangoVersion[0:2] >= (2, 0)): call_command('migrate', database=self.connection.alias, verbosity=verbosity, interactive=False) if serialize: self.connection._test_serialized_contents = self.serialize_db_to_string( ) else: call_command('migrate', database=self.connection.alias, verbosity=verbosity, interactive=False, load_initial_data=False) # We need to then do a flush to ensure that any data installed by custom SQL has been removed. #call_command('flush', database=self.connection.alias, verbosity = verbosity, interactive=False) return test_database
def apply_settings(cls): sts = cls.objects.all() for setting in sts: settings.__setattr__(setting.key, setting.value)
# Построить пути внутри проекта, как это: os.path.join(BASE_DIR, ...) import os from django.conf import settings from project.conf.paths import paths paths.config() settings.__setattr__("PROJECT_DIR", os.path.join(settings.BASE_DIR, "project")) settings.__setattr__("APPS_DIR", os.path.join(settings.PROJECT_DIR, "apps/"))
self.connection._commit() self.connection.close() else: sys.exit(1) else: self.__clean_up(self.connection.cursor()) self.connection._commit() self.connection.close() test_database = kwargs.get('database') if verbosity > 1: print "Preparing Database..." if (djangoVersion[0:2] <= (1, 1)): settings.DATABASE_NAME = test_database settings.__setattr__('PCONNECT', False) call_command('syncdb', verbosity=verbosity, interactive=False) else: self.connection.settings_dict['NAME'] = test_database self.connection.settings_dict['PCONNECT'] = False # Confirm the feature set of the test database if ((1, 2) < djangoVersion[0:2] < (1, 5)): self.connection.features.confirm() if (djangoVersion[0:2] < (1, 7)): call_command('syncdb', database=self.connection.alias, verbosity=verbosity, interactive=False, load_initial_data=False) else: call_command('migrate',