Exemplo n.º 1
0
 def testCompare(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     m.compare()
     t1, t2 = m.getTableNames()
     with connection.cursor() as cursor:
         cursor.execute('SELECT * FROM %s;' % t1)
         self.assertEqual(len(cursor.fetchall()), 0)
         cursor.execute('SELECT * FROM %s;' % t2)
         self.assertEqual(len(cursor.fetchall()), 0)
Exemplo n.º 2
0
 def testGetTableNames(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     n = m.getTableNames()
     c = tuple([
         settings.GENERATED_TABLE_PREFIX + '_TASK_1_LF',
         settings.GENERATED_TABLE_PREFIX + '_TASK_1_RT'
     ])
     self.assertEqual(
         n[0][:len(settings.GENERATED_TABLE_PREFIX + '_TASK_')],
         c[0][:len(settings.GENERATED_TABLE_PREFIX + '_TASK_')])
     self.assertEqual(n[0][-3:], c[0][-3:])
Exemplo n.º 3
0
    def test_setupWriters(self):

        m = TaskManager(self.taskModel, self.rds1, self.rds2)
        w1, w2 = m._setUpWriters()
        w1.writeAll([('w_row1', 'w_r1data'), ('w_row1', 'w_r1data')])
        w2.writeAll([('w_row1', 'w_r1data'), ('w_row1', 'w_r1data')])
        t1, t2 = m.getTableNames()
        with connection.cursor() as cursor:
            cursor.execute('SELECT * FROM %s;' % t1)
            self.assertEqual(len(cursor.fetchall()), 2)
            cursor.execute('SELECT * FROM %s;' % t2)
            self.assertEqual(len(cursor.fetchall()), 2)
Exemplo n.º 4
0
    def handle(self, *args, **options):

        # validate the input options
        v = Validator(options.get('summary', None), options.get('rds1', None),
                      options.get('rds2', None), options.get('sql1', None),
                      options.get('sql2', None), options.get('ignore1', None),
                      options.get('ignore2', None), options.get('wds1', None),
                      options.get('wds2', None))
        errs = v.validate()
        if len(errs) > 0:
            raise CommandError(', '.join(errs))

        # init the model
        model = Task.objects.create(
            summary=options.get('summary', None),
            left_source=getMaskedSourceFromString(options.get('rds1', None)),
            left_query_sql=options.get('sql1', None),
            left_ignore_fields=options.get('ignore1', None),
            right_source=getMaskedSourceFromString(options.get('rds2', None)),
            right_query_sql=options.get('sql2', None),
            right_ignore_fields=options.get('ignore2', None),
        )
        # call manager and compare
        try:
            manager = TaskManager(model, options.get('rds1', None),
                                  options.get('rds2', None),
                                  options.get('wds1', None),
                                  options.get('wds2', None))
            manager.compare()
        except Exception as e:
            model.result = Task.STATUS_OF_TASK_ERROR
            model.result_detail = str(e)

        # display basic information
        self.stdout.write('Comparing between\n -: %s\n +: %s' %
                          (manager.reader1, manager.reader2))
        self.stdout.write(model.result)
        if model.result_detail:
            self.stdout.write(
                model.result_detail.replace(settings.RESULT_SPLITTING_TOKEN,
                                            '\n'))
Exemplo n.º 5
0
def compareCommand(
        taskId, rds1, rds2,
        wds1=None, wds2=None):
    '''this is an async wrapper for taskManager'''

    # get the model
    model = Task.objects.get(id=taskId)
    # call manager and compare
    manager = None
    try:
        manager = TaskManager(
            model,
            rds1,
            rds2,
            wds1,
            wds2)
        manager.compare()
    except Exception as e:
        model.status = Task.STATUS_OF_TASK_ERROR
        model.result = 'Errors happened'
        model.result_detail = str(e)
        if hasattr(e, 'errors'):
            model.result_detail = str(e) + ':' + ' '.join(map(str, e.errors))
        model.save()
    finally:
        if manager is not None:
            manager.cleanUp()
Exemplo n.º 6
0
 def test_setupReaders(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     r1, r2 = m._setUpReaders()
     self.assertEqual(len(r1.getRowsList()), 10)
     self.assertEqual(len(r2.getRowsList()), 10)
Exemplo n.º 7
0
 def test_changeStatus1(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     m._changeStatus('XX')
     self.assertEqual(self.taskModel.status, 'PN')
Exemplo n.º 8
0
 def test_changeStatusWithValidStatus(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     m._changeStatus('CM')
     self.assertEqual(self.taskModel.status, 'CM')
Exemplo n.º 9
0
 def test_getCreateSql(self):
     m = TaskManager(self.taskModel, self.rds1, self.rds2)
     self.assertEqual(
         m._getCreateSql(['col1', 'col2'], 'test_table'),
         ('CREATE TABLE test_table (col1 VARCHAR(%s), col2 VARCHAR(%s));' %
          (settings.DEFAULT_DATA_LENGTH, settings.DEFAULT_DATA_LENGTH)))