Behat can be initialised with Oracle
authorFrederic Massart <fmcell@gmail.com>
Tue, 21 Oct 2014 18:27:12 +0000 (02:27 +0800)
committerFrederic Massart <fmcell@gmail.com>
Tue, 21 Oct 2014 18:27:12 +0000 (02:27 +0800)
mdk/commands/behat.py
mdk/moodle.py

index 8bf8c9f..b24f54c 100644 (file)
@@ -29,7 +29,7 @@ import logging
 import gzip
 from time import sleep
 from ..command import Command
-from ..tools import process, ProcessInThread, downloadProcessHook
+from ..tools import process, ProcessInThread, downloadProcessHook, question
 
 
 class BehatCommand(Command):
@@ -192,8 +192,17 @@ class BehatCommand(Command):
 
         # Run cli
         try:
+
+            # If Oracle, ask the user for a Behat prefix, if not set.
+            prefix = M.get('behat_prefix')
+            if M.get('dbtype') == 'oci' and (not prefix or len(prefix) > 2):
+                while not prefix or len(prefix) > 2:
+                    prefix = question('What prefix would you like to use? (Oracle, max 2 chars)')
+            else:
+                prefix = None
+
             logging.info('Initialising Behat, please be patient!')
-            M.initBehat(switchcompletely=args.switchcompletely)
+            M.initBehat(switchcompletely=args.switchcompletely, prefix=prefix)
             logging.info('Behat ready!')
 
             # Preparing Behat command
index b3a7a1d..45fa793 100644 (file)
@@ -314,7 +314,7 @@ class Moodle(object):
             else:
                 raise exception
 
-    def initBehat(self, switchcompletely=False):
+    def initBehat(self, switchcompletely=False, prefix=None):
         """Initialise the Behat environment"""
 
         if self.branch_compare(25, '<'):
@@ -330,8 +330,15 @@ class Moodle(object):
         self.updateConfig('behat_dataroot', behat_dataroot)
 
         # Set Behat DB prefix
-        behat_prefix = 'zbehat_'
-        self.updateConfig('behat_prefix', behat_prefix)
+        currentPrefix = self.get('behat_prefix')
+        behat_prefix = prefix or 'zbehat_'
+
+        if not currentPrefix:
+            self.updateConfig('behat_prefix', behat_prefix)
+        elif currentPrefix != behat_prefix and self.get('dbtype') != 'oci':
+            # Warn that a prefix is already set and we did not change it.
+            # No warning for Oracle as we need to set it to something else.
+            logging.warning('Behat prefix not changed, already set to \'%s\', expected \'%s\'.' % (currentPrefix, behat_prefix))
 
         # Switch completely?
         if self.branch_compare(26, '<'):