<commit_before>package hmda.api.http.public

import akka.event.{ LoggingAdapter, NoLogging }
import akka.http.scaladsl.model.{ ContentTypes, StatusCodes }
import akka.http.scaladsl.testkit.ScalatestRouteTest
import hmda.api.RequestHeaderUtils
import hmda.model.fi.lar.LarGenerators
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, MustMatchers, WordSpec }
import akka.util.Timeout

import scala.concurrent.duration._
import scala.concurrent.Await
import hmda.query.repository.filing.LarConverter._

class PublicHttpApiSpec extends WordSpec with MustMatchers with BeforeAndAfterEach with BeforeAndAfterAll
    with ScalatestRouteTest with RequestHeaderUtils with PublicHttpApi with LarGenerators {

  override val log: LoggingAdapter = NoLogging
  implicit val ec = system.dispatcher
  val larRepository = new LarRepository(config)
  val larTotalRepository = new LarTotalRepository(config)

  val duration = 10.seconds
  override implicit val timeout = Timeout(duration)

  val lar1 = larGen.sample.get.copy(respondentId = "0")
  val lar2 = larGen.sample.get.copy(respondentId = "0")
  val p = "2017"
  val l1 = toLoanApplicationRegisterQuery(lar1).copy(period = p)
  val l2 = toLoanApplicationRegisterQuery(lar2).copy(period = p)

  override def beforeEach(): Unit = {
    loadData()
  }

  private def loadData(): Unit = {
    Await.result(larRepository.insertOrUpdate(l1), duration)
    Await.result(larRepository.insertOrUpdate(l2), duration)
  }

  private def dropSchema(): Unit = {
    import config.profile.api._
    val db = larRepository.config.db
    val dropStmt =
      sqlu"""
            drop table if exists lars cascade
          """
    Await.result(db.run(dropStmt), duration)
    db.close()
  }

  "Modified LAR Http API" must {
    "return list of modified LARs in proper format" in {
      Get("/institutions/0/filings/2017/lar") ~> publicHttpRoutes ~> check {
        status mustBe StatusCodes.OK
        contentType mustBe ContentTypes.`text/csv(UTF-8)`
        responseAs[String].split("\n") must have size 2
      }
    }
  }

}
<commit_msg>Create schema before test<commit_after>package hmda.api.http.public

import akka.event.{ LoggingAdapter, NoLogging }
import akka.http.scaladsl.model.{ ContentTypes, StatusCodes }
import akka.http.scaladsl.testkit.ScalatestRouteTest
import hmda.api.RequestHeaderUtils
import hmda.model.fi.lar.LarGenerators
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, MustMatchers, WordSpec }
import akka.util.Timeout

import scala.concurrent.duration._
import scala.concurrent.Await
import hmda.query.repository.filing.LarConverter._

class PublicHttpApiSpec extends WordSpec with MustMatchers with BeforeAndAfterEach with BeforeAndAfterAll
    with ScalatestRouteTest with RequestHeaderUtils with PublicHttpApi with LarGenerators {

  override val log: LoggingAdapter = NoLogging
  implicit val ec = system.dispatcher
  val larRepository = new LarRepository(config)
  val larTotalRepository = new LarTotalRepository(config)

  val duration = 10.seconds
  override implicit val timeout = Timeout(duration)

  val lar1 = larGen.sample.get.copy(respondentId = "0")
  val lar2 = larGen.sample.get.copy(respondentId = "0")
  val p = "2017"
  val l1 = toLoanApplicationRegisterQuery(lar1).copy(period = p)
  val l2 = toLoanApplicationRegisterQuery(lar2).copy(period = p)

  override def beforeEach(): Unit = {
    larRepository.createSchema()
    modifiedLarRepository.createSchema()
    loadData()
  }

  private def loadData(): Unit = {
    Await.result(larRepository.insertOrUpdate(l1), duration)
    Await.result(larRepository.insertOrUpdate(l2), duration)
  }

  private def dropSchema(): Unit = {
    import config.profile.api._
    val db = larRepository.config.db
    val dropStmt =
      sqlu"""
            drop table if exists lars cascade
          """
    Await.result(db.run(dropStmt), duration)
    db.close()
  }

  "Modified LAR Http API" must {
    "return list of modified LARs in proper format" in {
      Get("/institutions/0/filings/2017/lar") ~> publicHttpRoutes ~> check {
        status mustBe StatusCodes.OK
        contentType mustBe ContentTypes.`text/csv(UTF-8)`
        responseAs[String].split("\n") must have size 2
      }
    }
  }

}

{'fraction_non_alphanumeric': 0.09330819981149858, 'fraction_numerical': 0.010838831291234684, 'mean_word_length': 3.9941176470588236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '827635', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1302, 'n_words': 313}