<commit_before>require 'test_helper'

class StrainTest < ActiveSupport::TestCase
  fixtures :all
  def setup
    User.current_user = Factory(:user)
  end

  def setup
    User.current_user = Factory(:user)
  end

  test 'info' do
    strain = Factory(:strain, title: 'CCTV')
    assert_equal 'CCTV (wild-type / wild-type)', strain.info

    genotype = Factory(:genotype, gene: Factory(:gene, title: 'fff'), modification: Factory(:modification, title: 'del'))
    strain.genotypes << genotype

    assert_equal 'CCTV (del fff / wild-type)', strain.info

    genotype = Factory(:genotype, gene: Factory(:gene, title: 'ggg'), modification: Factory(:modification, title: 'ins'))
    strain.genotypes << genotype

    assert_equal 'CCTV (del fff;ins ggg / wild-type)', strain.info

    strain.phenotypes << Factory(:phenotype, description: 'yellow beard')

    assert_equal 'CCTV (del fff;ins ggg / yellow beard)', strain.info
  end

  test 'to_rdf' do
    object = Factory(:strain, organism: Factory(:organism, bioportal_concept: Factory(:bioportal_concept)), provider_id: 'Dxxu1')
    Factory :assay_organism, strain: object, organism: object.organism

    rdf = object.to_rdf
    RDF::Reader.for(:rdfxml).new(rdf) do |reader|
      assert reader.statements.count >= 1
      assert_equal RDF::URI.new("http://localhost:3000/strains/#{object.id}"), reader.statements.first.subject
    end
  end

  test 'assays' do
    ao = Factory(:assay_organism)
    strain = ao.strain
    assert_equal [ao.assay], strain.assays
  end

  test 'ncbi uri' do
    strain = Factory(:strain, organism: Factory(:organism, bioportal_concept: Factory(:bioportal_concept)))
    assert_equal 'http://purl.obolibrary.org/obo/NCBITaxon_2287', strain.ncbi_uri

    strain = Factory(:organism)

    assert_nil strain.ncbi_uri
  end
<commit_msg>fix to strain test following ncbi_uri behaviour change<commit_after>require 'test_helper'

class StrainTest < ActiveSupport::TestCase
  fixtures :all
  def setup
    User.current_user = Factory(:user)
  end

  def setup
    User.current_user = Factory(:user)
  end

  test 'info' do
    strain = Factory(:strain, title: 'CCTV')
    assert_equal 'CCTV (wild-type / wild-type)', strain.info

    genotype = Factory(:genotype, gene: Factory(:gene, title: 'fff'), modification: Factory(:modification, title: 'del'))
    strain.genotypes << genotype

    assert_equal 'CCTV (del fff / wild-type)', strain.info

    genotype = Factory(:genotype, gene: Factory(:gene, title: 'ggg'), modification: Factory(:modification, title: 'ins'))
    strain.genotypes << genotype

    assert_equal 'CCTV (del fff;ins ggg / wild-type)', strain.info

    strain.phenotypes << Factory(:phenotype, description: 'yellow beard')

    assert_equal 'CCTV (del fff;ins ggg / yellow beard)', strain.info
  end

  test 'to_rdf' do
    object = Factory(:strain, organism: Factory(:organism, bioportal_concept: Factory(:bioportal_concept)), provider_id: 'Dxxu1')
    Factory :assay_organism, strain: object, organism: object.organism

    rdf = object.to_rdf
    RDF::Reader.for(:rdfxml).new(rdf) do |reader|
      assert reader.statements.count >= 1
      assert_equal RDF::URI.new("http://localhost:3000/strains/#{object.id}"), reader.statements.first.subject
    end
  end

  test 'assays' do
    ao = Factory(:assay_organism)
    strain = ao.strain
    assert_equal [ao.assay], strain.assays
  end

  test 'ncbi uri' do
    strain = Factory(:strain, organism: Factory(:organism, bioportal_concept: Factory(:bioportal_concept)))
    assert_equal 'http://purl.bioontology.org/ontology/NCBITAXON/2287', strain.ncbi_uri

    strain = Factory(:organism)

    assert_nil strain.ncbi_uri
  end

{'fraction_non_alphanumeric': 0.12666848270226097, 'fraction_numerical': 0.005448106782892944, 'mean_word_length': 4.1645569620253164, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3067797', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1145, 'n_words': 285}