Exemplo n.º 1
0
    def test_migration_course(self, mock_method):
        args = Namespace()
        self.setup_test('course')
        database = self.create_database('course')
        args.environments = ['course']
        args.choose_course = None
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = dict()
        args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [database]
            main.handle_migration(args)
        self.assertTrue(mock_class.called)
        self.assertEqual(1, mock_class.call_count)
        self.assertTrue(({
            'dbname': 'submitty_f19_csci1100'
        }, 'course'), mock_class.call_args[0])
        self.assertTrue(mock_method.called)
        self.assertEqual(1, mock_method.call_count)
        self.assertEqual(database, mock_method.call_args[0][0])
        self.assertEqual('course', mock_method.call_args[0][1])
        # Test that mutation did not happen
        self.assertEqual(args.config.database, dict())
        self.assertNotIn('semester', args)
        self.assertNotIn('course', args)
        args.config.database = {'dbname': 'submitty_f19_csci1100'}
        args.semester = 'f19'
        args.course = 'csci1100'
        self.assertEqual(args, mock_method.call_args[0][2])
        self.assertEqual(args.semester, 'f19')
        self.assertEqual(args.course, 'csci1100')
        self.assertFalse(database.open)
Exemplo n.º 2
0
 def test_no_course_dir(self):
     args = Namespace()
     args.environments = ['course']
     args.config = SimpleNamespace()
     args.config.database = dict()
     args.config.submitty = {'submitty_data_dir': self.dir}
     main.handle_migration(args)
     self.assertEqual(
         "Could not find courses directory: {}\n".format(
             str(Path(self.dir, 'courses'))), sys.stdout.getvalue())
Exemplo n.º 3
0
    def test_migration_no_db_system(self):
        args = Namespace()
        args.environments = ['system']
        args.config = SimpleNamespace()
        args.config.database = dict()

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None, None)
            main.handle_migration(args)
        self.assertEqual("Database does not exist for system\n",
                         sys.stdout.getvalue())
Exemplo n.º 4
0
    def test_no_course_dir(self):
        args = Namespace()
        args.environments = ['course']
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = {'submitty_data_dir': self.dir}

        with self.assertRaises(SystemExit) as context:
            main.handle_migration(args)
        self.assertEqual(
            "Migrator Error:  Could not find courses directory: {}".format(
                str(Path(self.dir, 'courses'))), str(context.exception))
Exemplo n.º 5
0
    def test_migration_no_db_system(self):
        args = Namespace()
        args.environments = ['system']
        args.config = SimpleNamespace()
        args.config.database = dict()

        with self.assertRaises(SystemExit) as context, \
                patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None, None)
            main.handle_migration(args)
        self.assertEqual(
            "Submitty Database Migration Error:  Database does not exist for system",
            str(context.exception))
Exemplo n.º 6
0
    def test_migration_no_db_master(self):
        args = Namespace()
        args.environments = ['master']
        args.config = SimpleNamespace()
        args.config.database = dict()

        with self.assertRaises(SystemExit) as context, \
                patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None,
                                                      "No Database")
            main.handle_migration(args)
        self.assertEqual(
            "Submitty Database Migration Error for master:\n  (builtins.str) No Database",
            str(context.exception))
Exemplo n.º 7
0
    def test_status_system(self, mock_method):
        self.setup_test('system')
        self.args.environments = ['system']
        self.args.config = SimpleNamespace()
        self.args.config.database = dict()

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [self.databases['system']]
            main.handle_migration(self.args)
        self.assertTrue(mock_class.called)
        self.assertTrue(mock_method.called)
        self.assertEqual(self.databases['system'], mock_method.call_args[0][0])
        self.assertEqual('system', mock_method.call_args[0][1])
        self.assertEqual(self.args, mock_method.call_args[0][2])
        self.assertFalse(self.databases['system'].open)
Exemplo n.º 8
0
    def test_migration_no_db_course(self):
        args = Namespace()
        args.environments = ['course']
        args.choose_course = None
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = dict()
        args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None, None)
            main.handle_migration(args)
        self.assertEqual(
            "Submitty Database Migration Warning:  Database does not exist for semester=f19 course=csci1100\n",
            sys.stdout.getvalue())
Exemplo n.º 9
0
    def test_status_no_db_all(self):
        self.args.environments = ['course', 'master', 'system']
        self.args.choose_course = None
        self.args.config = SimpleNamespace()
        self.args.config.database = dict()
        self.args.config.submitty = dict()
        self.args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None, None)
            main.handle_migration(self.args)
        expected = """Database does not exist for master
Database does not exist for system
Submitty Database Migration Warning:  Database does not exist for semester=f19 course=csci1100
"""
        self.assertEqual(expected, sys.stdout.getvalue())
Exemplo n.º 10
0
    def test_migration_no_db_all(self):
        args = Namespace()
        args.environments = ['course', 'master', 'system']
        args.choose_course = None
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = dict()
        args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)

        with self.assertRaises(SystemExit) as context, \
                patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = OperationalError('test', None, None)
            main.handle_migration(args)

        self.assertEqual(
            "Submitty Database Migration Error:  Database does not exist for master",
            str(context.exception))
Exemplo n.º 11
0
    def test_migration_multiple_courses_missing_migration(self, mock_method):
        args = Namespace()
        self.setup_test('course')
        database_1 = self.create_database('course')
        database_2 = self.create_database('course')
        database_3 = self.create_database('course')
        args.environments = ['course']
        args.choose_course = None
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = dict()
        args.config.submitty['submitty_data_dir'] = Path(self.dir)

        Path(self.dir, 'courses', 'f18', 'csci1100').mkdir(parents=True)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)
        Path(self.dir, 'courses', 'f19', 'csci1200').mkdir(parents=True)

        missing_migration = Path(self.dir, 'test.txt')
        missing_migration.touch()
        mock_method.side_effect = lambda *args: args[-1].add(missing_migration)
        self.assertTrue(missing_migration.exists())

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [database_1, database_2, database_3]
            main.handle_migration(args)
        self.assertFalse(missing_migration.exists())
        self.assertTrue(mock_class.called)
        self.assertEqual(3, mock_class.call_count)
        self.assertTrue(
            ({'dbname': 'submitty_f18_csci1100'}, 'course'),
            mock_class.call_args_list[0][0]
        )
        self.assertTrue(
            ({'dbname': 'submitty_f19_csci1100'}, 'course'),
            mock_class.call_args_list[1][0]
        )
        self.assertTrue(
            ({'dbname': 'submitty_f19_csci1200'}, 'course'),
            mock_class.call_args_list[2][0]
        )
        self.assertTrue(mock_method.called)
        self.assertEqual(3, mock_method.call_count)
Exemplo n.º 12
0
    def test_migration_system(self, mock_method):
        args = Namespace()
        self.setup_test('system')
        database = self.create_database('system')
        args.environments = ['system']
        args.config = SimpleNamespace()
        args.config.database = dict()

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [database]
            main.handle_migration(args)
        self.assertTrue(mock_class.called)
        self.assertEqual(1, mock_class.call_count)
        self.assertTrue(({'dbname': 'submitty'}, 'system'), mock_class.call_args[0])
        self.assertTrue(mock_method.called)
        self.assertEqual(1, mock_method.call_count)
        self.assertEqual(database, mock_method.call_args[0][0])
        self.assertEqual('system', mock_method.call_args[0][1])
        self.assertEqual(args, mock_method.call_args[0][2])
        self.assertFalse(database.open)
Exemplo n.º 13
0
    def test_status_course(self, mock_method):
        self.setup_test('course')
        self.args.environments = ['course']
        self.args.choose_course = None
        self.args.config = SimpleNamespace()
        self.args.config.database = dict()
        self.args.config.submitty = dict()
        self.args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)

        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [self.databases['course']]
            main.handle_migration(self.args)
        self.assertTrue(mock_class.called)
        self.assertTrue(mock_method.called)
        self.assertEqual(self.databases['course'], mock_method.call_args[0][0])
        self.assertEqual('course', mock_method.call_args[0][1])
        self.assertEqual(self.args, mock_method.call_args[0][2])
        self.assertEqual(self.args.semester, 'f19')
        self.assertEqual(self.args.course, 'csci1100')
        self.assertFalse(self.databases['course'].open)
Exemplo n.º 14
0
    def test_migration_choose_courses(self, mock_method):
        args = Namespace()
        self.setup_test('course')
        database_1 = self.create_database('course')
        args.environments = ['course']
        args.choose_course = ['f19', 'csci1100']
        args.config = SimpleNamespace()
        args.config.database = dict()
        args.config.submitty = dict()
        args.config.submitty['submitty_data_dir'] = Path(self.dir)
        Path(self.dir, 'courses', 'f18', 'csci1100').mkdir(parents=True)
        Path(self.dir, 'courses', 'f19', 'csci1100').mkdir(parents=True)
        Path(self.dir, 'courses', 'f19', 'csci1200').mkdir(parents=True)
        with patch.object(migrator.db, 'Database') as mock_class:
            mock_class.side_effect = [database_1]
            main.handle_migration(args)
        self.assertTrue(mock_class.called)
        self.assertEqual(1, mock_class.call_count)
        self.assertTrue(
            ({'dbname': 'submitty_f19_csci1100'}, 'course'),
            mock_class.call_args_list[0][0]
        )
        self.assertTrue(mock_method.called)
        self.assertEqual(1, mock_method.call_count)

        mock_args = mock_method.call_args_list[0][0]
        expected_args = deepcopy(args)
        self.assertEqual(database_1, mock_args[0])
        self.assertEqual('course', mock_args[1])
        self.assertEqual(expected_args.config.database, dict())
        self.assertNotIn('semester', expected_args)
        self.assertNotIn('course', expected_args)
        expected_args.config.database = {'dbname': 'submitty_f19_csci1100'}
        expected_args.semester = 'f19'
        expected_args.course = 'csci1100'
        self.assertEqual(expected_args, mock_args[2])
        self.assertEqual(expected_args.semester, 'f19')
        self.assertEqual(expected_args.course, 'csci1100')
        self.assertFalse(database_1.open)