<commit_before>require "pathname"
require Pathname(__FILE__).dirname + "../../helper"

require "do_sqlite3"
require "harbor/contrib/session/data_objects"

module Contrib
  module Session
    class DataObjectsTest < Test::Unit::TestCase

      CookieRequest = Class.new(Harbor::Test::Request) do
        def cookies
          @cookies ||= {}
        end
      end

      def setup        
        Harbor::Session.configure do |session|
          session[:store] = Harbor::Contrib::Session::DataObjects
          session[:connection_uri] = 'sqlite3::memory:'
        end
      end

      def teardown
        if Harbor::Contrib::Session::DataObjects.session_table_exists?
          Harbor::Contrib::Session::DataObjects.execute('DROP TABLE sessions')
        end
      
        Harbor::Contrib::Session::DataObjects.instance_eval do
          @table_exists = nil
        end
      
        Harbor::Session.configure do |session|
          session[:store] = Harbor::Session::Cookie
          session.delete(:connection_uri)
        end
      end
      
      def test_creating_session_table
        assert ! Harbor::Contrib::Session::DataObjects.session_table_exists?<commit_msg>session table should be deleted on setup instead of teardown, otherwise it might break because of DM tests<commit_after>require "pathname"
require Pathname(__FILE__).dirname + "../../helper"

require "do_sqlite3"
require "harbor/contrib/session/data_objects"

module Contrib
  module Session
    class DataObjectsTest < Test::Unit::TestCase

      CookieRequest = Class.new(Harbor::Test::Request) do
        def cookies
          @cookies ||= {}
        end
      end

      def setup        
        Harbor::Session.configure do |session|
          session[:store] = Harbor::Contrib::Session::DataObjects
          session[:connection_uri] = 'sqlite3::memory:'
        end
        
        if Harbor::Contrib::Session::DataObjects.session_table_exists?
          Harbor::Contrib::Session::DataObjects.execute('DROP TABLE sessions')
        end
        
        Harbor::Contrib::Session::DataObjects.instance_eval do
          @table_exists = nil
        end
      end

      def teardown      
        Harbor::Session.configure do |session|
          session[:store] = Harbor::Session::Cookie
          session.delete(:connection_uri)
        end
      end
      
      def test_creating_session_table
        assert ! Harbor::Contrib::Session::DataObjects.session_table_exists?
{'fraction_non_alphanumeric': 0.0989816700610998, 'fraction_numerical': 0.001629327902240326, 'mean_word_length': 2.601173020527859, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4140888', 'n_tokens_mistral': 650, 'n_tokens_neox': 651, 'n_words': 136}