Beispiel #1
0
    def test_slack_import_to_existing_database(
            self, mock_get_slack_api_data: mock.Mock,
            mock_build_avatar_url: mock.Mock, mock_build_avatar: mock.Mock,
            mock_process_uploads: mock.Mock,
            mock_attachment: mock.Mock) -> None:
        test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver", "tests",
                                      "fixtures", "slack_fixtures")
        test_slack_zip_file = os.path.join(test_slack_dir,
                                           "test_slack_importer.zip")
        test_slack_unzipped_file = os.path.join(test_slack_dir,
                                                "test_slack_importer")

        test_realm_subdomain = 'test-slack-import'
        output_dir = os.path.join(settings.DEPLOY_ROOT, "var",
                                  "test-slack-importer-data")
        token = 'valid-token'

        # If the test fails, the 'output_dir' would not be deleted and hence it would give an
        # error when we run the tests next time, as 'do_convert_data' expects an empty 'output_dir'
        # hence we remove it before running 'do_convert_data'
        rm_tree(output_dir)
        # Also the unzipped data file should be removed if the test fails at 'do_convert_data'
        rm_tree(test_slack_unzipped_file)

        user_data_fixture = ujson.loads(
            self.fixture_data('user_data.json', type='slack_fixtures'))
        mock_get_slack_api_data.side_effect = [
            user_data_fixture['members'], {}
        ]

        do_convert_data(test_slack_zip_file, output_dir, token)
        self.assertTrue(os.path.exists(output_dir))
        self.assertTrue(os.path.exists(output_dir + '/realm.json'))

        # test import of the converted slack data into an existing database
        do_import_realm(output_dir, test_realm_subdomain)
        realm = get_realm(test_realm_subdomain)
        self.assertTrue(realm.name, test_realm_subdomain)

        # test RealmAuditLog
        realmauditlog = RealmAuditLog.objects.filter(realm=realm)
        realmauditlog_event_type = {log.event_type for log in realmauditlog}
        self.assertEqual(realmauditlog_event_type, {'subscription_created'})

        Realm.objects.filter(name=test_realm_subdomain).delete()

        remove_folder(output_dir)
        # remove tar file created in 'do_convert_data' function
        os.remove(output_dir + '.tar.gz')
        self.assertFalse(os.path.exists(output_dir))
Beispiel #2
0
    def test_slack_import_to_existing_database(self, mock_get_slack_api_data: mock.Mock,
                                               mock_build_avatar_url: mock.Mock,
                                               mock_build_avatar: mock.Mock,
                                               mock_process_uploads: mock.Mock,
                                               mock_attachment: mock.Mock) -> None:
        test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver", "tests", "fixtures",
                                      "slack_fixtures")
        test_slack_zip_file = os.path.join(test_slack_dir, "test_slack_importer.zip")
        test_slack_unzipped_file = os.path.join(test_slack_dir, "test_slack_importer")

        test_realm_subdomain = 'test-slack-import'
        output_dir = os.path.join(settings.DEPLOY_ROOT, "var", "test-slack-importer-data")
        token = 'valid-token'

        # If the test fails, the 'output_dir' would not be deleted and hence it would give an
        # error when we run the tests next time, as 'do_convert_data' expects an empty 'output_dir'
        # hence we remove it before running 'do_convert_data'
        rm_tree(output_dir)
        # Also the unzipped data file should be removed if the test fails at 'do_convert_data'
        rm_tree(test_slack_unzipped_file)

        user_data_fixture = ujson.loads(self.fixture_data('user_data.json', type='slack_fixtures'))
        mock_get_slack_api_data.side_effect = [user_data_fixture['members'], {}]

        do_convert_data(test_slack_zip_file, output_dir, token)
        self.assertTrue(os.path.exists(output_dir))
        self.assertTrue(os.path.exists(output_dir + '/realm.json'))

        # test import of the converted slack data into an existing database
        do_import_realm(output_dir, test_realm_subdomain)
        realm = get_realm(test_realm_subdomain)
        self.assertTrue(realm.name, test_realm_subdomain)

        # test RealmAuditLog
        realmauditlog = RealmAuditLog.objects.filter(realm=realm)
        realmauditlog_event_type = {log.event_type for log in realmauditlog}
        self.assertEqual(realmauditlog_event_type, {'subscription_created'})

        Realm.objects.filter(name=test_realm_subdomain).delete()

        remove_folder(output_dir)
        # remove tar file created in 'do_convert_data' function
        os.remove(output_dir + '.tar.gz')
        self.assertFalse(os.path.exists(output_dir))
Beispiel #3
0
    def test_slack_import_to_existing_database(
            self, mock_get_user_data: mock.Mock,
            mock_build_avatar_url: mock.Mock, mock_build_avatar: mock.Mock,
            mock_process_uploads: mock.Mock) -> None:
        test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver",
                                      "fixtures", "slack_fixtures")
        test_slack_zip_file = os.path.join(test_slack_dir,
                                           "test_slack_importer.zip")
        test_slack_unzipped_file = os.path.join(test_slack_dir,
                                                "test_slack_importer")

        test_realm_subdomain = 'test-slack-import'
        output_dir = os.path.join(settings.DEPLOY_ROOT, "var",
                                  "test-slack-importer-data")
        token = 'valid-token'

        # If the test fails, the 'output_dir' would not be deleted and hence it would give an
        # error when we run the tests next time, as 'do_convert_data' expects an empty 'output_dir'
        # hence we remove it before running 'do_convert_data'
        rm_tree(output_dir)
        # Also the unzipped data file should be removed if the test fails at 'do_convert_data'
        rm_tree(test_slack_unzipped_file)

        user_data_fixture = os.path.join(settings.DEPLOY_ROOT, "zerver",
                                         "fixtures", "slack_fixtures",
                                         "user_data.json")
        mock_get_user_data.return_value = ujson.load(
            open(user_data_fixture))['members']

        do_convert_data(test_slack_zip_file, test_realm_subdomain, output_dir,
                        token)
        self.assertTrue(os.path.exists(output_dir))
        self.assertTrue(os.path.exists(output_dir + '/realm.json'))

        # test import of the converted slack data into an existing database
        do_import_realm(output_dir)
        self.assertTrue(
            get_realm(test_realm_subdomain).name, test_realm_subdomain)
        Realm.objects.filter(name=test_realm_subdomain).delete()

        remove_folder(output_dir)
        # remove tar file created in 'do_convert_data' function
        os.remove(output_dir + '.tar.gz')
        self.assertFalse(os.path.exists(output_dir))
Beispiel #4
0
    def test_slack_import_to_existing_database(self, mock_get_user_data: mock.Mock,
                                               mock_build_avatar_url: mock.Mock,
                                               mock_build_avatar: mock.Mock,
                                               mock_process_uploads: mock.Mock) -> None:
        test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver", "fixtures",
                                      "slack_fixtures")
        test_slack_zip_file = os.path.join(test_slack_dir, "test_slack_importer.zip")
        test_slack_unzipped_file = os.path.join(test_slack_dir, "test_slack_importer")

        test_realm_subdomain = 'test-slack-import'
        output_dir = os.path.join(settings.DEPLOY_ROOT, "var", "test-slack-importer-data")
        token = 'valid-token'

        # If the test fails, the 'output_dir' would not be deleted and hence it would give an
        # error when we run the tests next time, as 'do_convert_data' expects an empty 'output_dir'
        # hence we remove it before running 'do_convert_data'
        rm_tree(output_dir)
        # Also the unzipped data file should be removed if the test fails at 'do_convert_data'
        rm_tree(test_slack_unzipped_file)

        user_data_fixture = os.path.join(settings.DEPLOY_ROOT, "zerver", "fixtures",
                                         "slack_fixtures", "user_data.json")
        mock_get_user_data.return_value = ujson.load(open(user_data_fixture))['members']

        do_convert_data(test_slack_zip_file, test_realm_subdomain, output_dir, token)
        self.assertTrue(os.path.exists(output_dir))
        self.assertTrue(os.path.exists(output_dir + '/realm.json'))

        # test import of the converted slack data into an existing database
        do_import_realm(output_dir)
        self.assertTrue(get_realm(test_realm_subdomain).name, test_realm_subdomain)
        Realm.objects.filter(name=test_realm_subdomain).delete()

        remove_folder(output_dir)
        # remove tar file created in 'do_convert_data' function
        os.remove(output_dir + '.tar.gz')
        self.assertFalse(os.path.exists(output_dir))