<commit_before>package com.jetbrains.env.django;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.UsefulTestCase;
import com.jetbrains.django.DjangoNames;
import com.jetbrains.django.model.DjangoAdmin;
import com.jetbrains.django.util.DjangoUtil;
import com.jetbrains.env.python.debug.PyEnvTestCase;
import com.jetbrains.env.python.debug.PyExecutionFixtureTestTask;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyUtil;
import com.jetbrains.python.psi.impl.PyBlockEvaluator;
import org.hamcrest.Matchers;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * Tests projection creation for Django
 *
 * @author Ilya.Kazakevich
 */
public class DjangoProjectCreationTest extends PyEnvTestCase {

  private static final String ROOT_FOLDER_NAME = "content_root";
  private static final String WEB_SITE_NAME = "myWebSite";
  private static final String DJANGO_TAG = "django";
  private static final MyDjangoProjectCreationTest.Canonicator CANONICATOR = new MyDjangoProjectCreationTest.Canonicator();

  public DjangoProjectCreationTest() {
    super(DJANGO_TAG);
  }


  // TODO: Doc
  public void testProjectWithTemplates() throws Exception {
    runPythonTest(new MyDjangoProjectCreationTest());
  }

  private static class MyDjangoProjectCreationTest extends PyExecutionFixtureTestTask {
    @Override
    public void runTestOn(@NotNull final String sdkHome) throws Exception {
      final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
      final String djangoPath = DjangoUtil.getDjangoPath(sdk);
      assert djangoPath != null : "No django found under " + sdkHome;

      final VirtualFile contentRoot = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME);
      final String templateDir = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME + "/templates_dir").getCanonicalPath();
      assert templateDir != null : "Failed to create template dirs";

      UsefulTestCase.edt(new Runnable() {
        @Override
        public void run() {
          try {
            DjangoAdmin.createProject(
              myFixture.getProject(),
              sdk,
              contentRoot,
              WEB_SITE_NAME,
              "myMainApp",
              djangoPath,
              false,
              false
            );
          }
          catch (final ExecutionException ex) {
            Assert.fail(ex.toString());
          }
        }
      });

      final String pathToSettingsPy;
      if (DjangoAdmin.isDjangoVersionAtLeast(sdk, "1.4")) {
        pathToSettingsPy = ROOT_FOLDER_NAME + '/' + WEB_SITE_NAME + '/' + DjangoNames.SETTINGS_FILE;
      }
      else {
        pathToSettingsPy = ROOT_FOLDER_NAME + '/' + DjangoNames.SETTINGS_FILE;
      }

      final PyFile settingsPy =<commit_msg>reverted back templates folder setup in django<commit_after>package com.jetbrains.env.django;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.UsefulTestCase;
import com.jetbrains.django.DjangoNames;
import com.jetbrains.django.model.DjangoAdmin;
import com.jetbrains.django.util.DjangoUtil;
import com.jetbrains.env.python.debug.PyEnvTestCase;
import com.jetbrains.env.python.debug.PyExecutionFixtureTestTask;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyUtil;
import com.jetbrains.python.psi.impl.PyBlockEvaluator;
import org.hamcrest.Matchers;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * Tests projection creation for Django
 *
 * @author Ilya.Kazakevich
 */
public class DjangoProjectCreationTest extends PyEnvTestCase {

  private static final String ROOT_FOLDER_NAME = "content_root";
  private static final String WEB_SITE_NAME = "myWebSite";
  private static final String DJANGO_TAG = "django";
  private static final MyDjangoProjectCreationTest.Canonicator CANONICATOR = new MyDjangoProjectCreationTest.Canonicator();

  public DjangoProjectCreationTest() {
    super(DJANGO_TAG);
  }


  // TODO: Doc
  public void testProjectWithTemplates() throws Exception {
    runPythonTest(new MyDjangoProjectCreationTest());
  }

  private static class MyDjangoProjectCreationTest extends PyExecutionFixtureTestTask {
    @Override
    public void runTestOn(@NotNull final String sdkHome) throws Exception {
      final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
      final String djangoPath = DjangoUtil.getDjangoPath(sdk);
      assert djangoPath != null : "No django found under " + sdkHome;

      final VirtualFile contentRoot = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME);
      final String templateDir = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME + "/templates_dir").getCanonicalPath();
      assert templateDir != null : "Failed to create template dirs";

      UsefulTestCase.edt(new Runnable() {
        @Override
        public void run() {
          try {
            DjangoAdmin.createProject(
              myFixture.getProject(),
              sdk,
              contentRoot,
              WEB_SITE_NAME,
              "myMainApp",
              templateDir,
              djangoPath,
              false,
              false
            );
          }
          catch (final ExecutionException ex) {
            Assert.fail(ex.toString());
          }
        }
      });

      final String pathToSettingsPy;
      if (DjangoAdmin.isDjangoVersionAtLeast(sdk, "1.4")) {
        pathToSettingsPy = ROOT_FOLDER_NAME + '/' + WEB_SITE_NAME + '/' + DjangoNames.SETTINGS_FILE;
      }
      else {
        pathToSettingsPy = ROOT_FOLDER_NAME + '/' + DjangoNames.SETTINGS_FILE;
      }

      final PyFile settingsPy =
{'fraction_non_alphanumeric': 0.08934762054837693, 'fraction_numerical': 0.0009454774661203908, 'mean_word_length': 3.4446778711484596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '259601', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1858, 'n_words': 371}