swot/test/test_swot.rb
Aidan Feldman 6da1bcba05 Merge pull request #49 from benbalter/better-blacklisting
Better blacklist support through regex
2014-04-14 19:14:32 -04:00

73 lines
3.6 KiB
Ruby

# encoding: UTF-8
require 'helper'
class TestEmail < Test::Unit::TestCase
should "recognizes academic email addresses and domains" do
assert_equal Swot::is_academic?('lreilly@stanford.edu'), true
assert_equal Swot::is_academic?('LREILLY@STANFORD.EDU'), true
assert_equal Swot::is_academic?('Lreilly@Stanford.Edu'), true
assert_equal Swot::is_academic?('lreilly@slac.stanford.edu'), true
assert_equal Swot::is_academic?('lreilly@strath.ac.uk'), true
assert_equal Swot::is_academic?('lreilly@soft-eng.strath.ac.uk'), true
assert_equal Swot::is_academic?('lee@ugr.es'), true
assert_equal Swot::is_academic?('lee@uottawa.ca'), true
assert_equal Swot::is_academic?('lee@mother.edu.ru'), true
assert_equal Swot::is_academic?('lee@ucy.ac.cy'), true
assert_equal Swot::is_academic?('lee@leerilly.net'), false
assert_equal Swot::is_academic?('lee@gmail.com'), false
assert_equal Swot::is_academic?('lee@stanford.edu.com'), false
assert_equal Swot::is_academic?('lee@strath.ac.uk.com'), false
assert_equal Swot::is_academic?('stanford.edu'), true
assert_equal Swot::is_academic?('slac.stanford.edu'), true
assert_equal Swot::is_academic?('www.stanford.edu'), true
assert_equal Swot::is_academic?('http://www.stanford.edu'), true
assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true
assert_equal Swot::is_academic?('strath.ac.uk'), true
assert_equal Swot::is_academic?('soft-eng.strath.ac.uk'), true
assert_equal Swot::is_academic?('ugr.es'), true
assert_equal Swot::is_academic?('uottawa.ca'), true
assert_equal Swot::is_academic?('mother.edu.ru'), true
assert_equal Swot::is_academic?('ucy.ac.cy'), true
assert_equal Swot::is_academic?('leerilly.net'), false
assert_equal Swot::is_academic?('gmail.com'), false
assert_equal Swot::is_academic?('stanford.edu.com'), false
assert_equal Swot::is_academic?('strath.ac.uk.com'), false
assert_equal Swot::is_academic?(nil), false
assert_equal Swot::is_academic?(''), false
assert_equal Swot::is_academic?('the'), false
assert_equal Swot::is_academic?(' stanford.edu'), true
assert_equal Swot::is_academic?('lee@strath.ac.uk '), true
assert_equal Swot::is_academic?(' gmail.com '), false
end
should "returns name of valid institution" do
assert_equal Swot::get_institution_name('lreilly@cs.strath.ac.uk'), "University of Strathclyde"
assert_equal Swot::get_institution_name('lreilly@fadi.at'), "BRG Fadingerstraße Linz, Austria"
end
should "returns nil when institution invalid" do
assert_equal Swot::get_institution_name('foo@shop.com'), nil
end
should "test aliased methods" do
assert_equal Swot::academic?('stanford.edu'), true
assert_equal Swot::school_name('lreilly@cs.strath.ac.uk'), "University of Strathclyde"
end
should "fail blacklisted domains" do
["si.edu", " si.edu ", "imposter@si.edu", "foo.si.edu"].each do |domain|
assert_equal false, Swot::is_academic?(domain), "#{domain} should be denied"
end
end
should "not err on tld-only domains" do
assert_nothing_raised { Swot::is_academic? ".com" }
assert_equal false, Swot::is_academic?(".com")
end
end