<commit_before>require 'lib/popit_watir_test_case'
require 'pry'
require 'net/http'
require 'uri'


class HostingTests < PopItWatirTestCase

  def test_hosting_site_homepage
    goto_hosting_site
    assert_match( /Welcome to PopIt/, @b.text )
  end

  def test_404_page
    goto_hosting_site
    goto '/instances/not_found'
    assert_equal 'Page not found', @b.title
    
    # Watir won't let us check that we got a 404 code
    u = URI.parse @b.url
    status_code = Net::HTTP.start(u.host,u.port){|http| http.head(u.request_uri).code }
    assert_equal '404', status_code
  end

  def test_create_instance
    goto_hosting_site
    delete_instance 'test'

    # check that the instance does not exist
    goto "/instances/test"
    assert_equal "Page not found", @b.title    

    # go to the create new site page
    goto_home_page
    @b.link(:text, 'Create your PopIt site').click

    # submit the form with no values, check for error
    @b.input(:value, 'Create your own PopIt').click
    assert_match "Error is 'required'", @b.text
    assert_match "Error is 'required'", @b.text    
    
    # check a slug that is too short
    @b.text_field(:name, 'slug').set("foo")
    @b.input(:value, 'Create your own PopIt').click
    assert_match "Error is 'regexp'", @b.text
    assert_match "Error is 'required'", @b.text    
    <commit_msg>[testing] - don't cause instance 404 page to be cached in varnish<commit_after>require 'lib/popit_watir_test_case'
require 'pry'
require 'net/http'
require 'uri'


class HostingTests < PopItWatirTestCase

  def test_hosting_site_homepage
    goto_hosting_site
    assert_match( /Welcome to PopIt/, @b.text )
  end

  def test_404_page
    goto_hosting_site
    goto '/instances/not_found'
    assert_equal 'Page not found', @b.title
    
    # Watir won't let us check that we got a 404 code
    u = URI.parse @b.url
    status_code = Net::HTTP.start(u.host,u.port){|http| http.head(u.request_uri).code }
    assert_equal '404', status_code
  end

  def test_create_instance
    goto_hosting_site
    delete_instance 'test'

    # check that the instance does not exist - use testing=1 so that the proper
    # url is not cached by varnish as a 404. This allows these tests to be run
    # against the development machine.
    goto "/instances/test?testing=1"
    assert_equal "Page not found", @b.title    

    # go to the create new site page
    goto_home_page
    @b.link(:text, 'Create your PopIt site').click

    # submit the form with no values, check for error
    @b.input(:value, 'Create your own PopIt').click
    assert_match "Error is 'required'", @b.text
    assert_match "Error is 'required'", @b.text    
    
    # check a slug that is too short
    @b.text_field(:name, 'slug').set("foo")
    @b.input(:value, 'Create your own PopIt').click
    assert_match "Error is 'regexp'", @b.text
    assert_match "Error is 'required'", @b.text    
    
{'fraction_non_alphanumeric': 0.10099622122981793, 'fraction_numerical': 0.008931638612160769, 'mean_word_length': 3.202020202020202, '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': '5371701', 'n_tokens_mistral': 995, 'n_tokens_neox': 958, 'n_words': 298}