Beispiel #1
0
 def test_with_None_parameter_name(self):
     """
     Check passed parameter is empty or not.
     """
     parameter_name = None
     settings_dir_name = 'testproject'
     result = save_to_settings(False, parameter_name, settings_dir_name)
     self.assertEqual(result, False)
Beispiel #2
0
 def test_with_correct_parameter_name(self):
     """
     Check passed parameter is successfully update or not.
     """
     parameter_name = 'DEBUG'
     settings_dir_name = 'testproject'
     result = save_to_settings(True, parameter_name,
                               settings_dir_name)
     self.assertEqual(result, True)
Beispiel #3
0
 def test_with_parameter_value_with_defaults(self):
     """
     Check value has been updated or not.
     """
     parameter_value = f"'{generate_secret_key()}'"
     parameter_name = 'SECRET_KEY'
     settings_dir_name = 'testproject'
     result = save_to_settings(parameter_value, parameter_name,
                               settings_dir_name)
     self.assertEqual(result, True)
Beispiel #4
0
 def test_with_none_settings_dir_name(self):
     """
     Check passed settings dir name is empty or not.
     """
     parameter_value = f"'{generate_secret_key()}'"
     parameter_name = 'SECRET_KEY'
     settings_dir_name = 'testproject'
     result = save_to_settings(parameter_value, parameter_name,
                               settings_dir_name)
     self.assertEqual(result, True)
Beispiel #5
0
 def test_with_none_parameter_value(self):
     """
     Check None value has been updated or not.
     """
     parameter_value = None
     parameter_name = 'SECRET_KEY'
     settings_dir_name = 'testproject'
     result = save_to_settings(parameter_value, parameter_name,
                               settings_dir_name)
     self.assertEqual(result, True)
     self.test_with_parameter_value_with_defaults()
    def handle(self, *args, **kwargs):
        parameter_name = 'SECRET_KEY'
        new_key = generate_secret_key()
        parameter_value = new_key

        if kwargs['save']:
            settings_dir_name = kwargs['settings_dir_name']
            try:
                save_to_settings(f"'{parameter_value}'", parameter_name,
                                 settings_dir_name)
                self.stdout.write(self.style.SUCCESS(
                    f'{parameter_name} updated successfully.'))
                if kwargs['print']:
                    self.stdout.write('{} {}'.format(
                        self.style.SUCCESS(f'{parameter_name} set to:'),
                        parameter_value))
                self._print_tips()
            except (FileNotFoundError, NameError) as e:
                self.stdout.write(self.style.ERROR(e.__str__()))
        else:
            self.stdout.write('{} {}'.format(
                self.style.SUCCESS(f'{parameter_name}:'), parameter_value))
            self._print_tips()