Skip to content

Commit

Permalink
Merge pull request #210 from dmacvicar/dmacvicar_testing
Browse files Browse the repository at this point in the history
Fix tests and add them to travis
  • Loading branch information
Ana06 committed Feb 3, 2018
2 parents 8191aae + e91e969 commit b7440c7
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 27 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ rvm:
- 2.4.3
script:
- 'bundle exec rubocop -D'
- 'bundle exec rails test'
2 changes: 1 addition & 1 deletion app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def prepare_desc(desc)
end

def default_baseproject
'openSUSE:Leap:42.2'
'openSUSE:Leap:42.3'
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/_piwik.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script type="text/javascript">
var _paq = _paq || [];
(function(){
var u=(("https:" == document.location.protocol) ? "https://beans.opensuse.org/piwik/" : "http://beans.opensuse.org/piwik/");
var u="https://beans.opensuse.org/piwik/";
_paq.push(['setSiteId', 7]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script type="text/javascript">
var _paq = _paq || [];
(function(){
var u=(("https:" == document.location.protocol) ? "https://beans.opensuse.org/piwik/" : "http://beans.opensuse.org/piwik/");
var u="https://beans.opensuse.org/piwik/";
_paq.push(['setSiteId', 7]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/download.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script type="text/javascript">
var _paq = _paq || [];
(function(){
var u=(("https:" == document.location.protocol) ? "https://beans.opensuse.org/piwik/" : "http://beans.opensuse.org/piwik/");
var u="https://beans.opensuse.org/piwik/";
_paq.push(['setSiteId', 7]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
Expand Down
7 changes: 1 addition & 6 deletions config/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ development:
api_username: wiki_hermes
api_password: w_h_p1

testing:
test:
<<: *defaults
# only for production use
#opensuse_cookie:
stage:
<<: *defaults
use_static: software.o.o-stage
# only for production use
#opensuse_cookie:
production:
<<: *defaults
relative_url_root:
Expand Down
6 changes: 3 additions & 3 deletions test/integration/package_information_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'test_helper'
require File.expand_path('../../test_helper', __FILE__)

class PackageInformationTest < ActionDispatch::IntegrationTest

def test_package_information
# Check that package information is displayed
visit '/package/pidgin'
assert page.has_content? 'Pidgin'
assert page.has_content? 'InstantMessaging'
assert page.has_content? 'Multiprotocol Instant Messaging Client'
assert page.has_content? 'Pidgin is a chat program'
end
end
11 changes: 11 additions & 0 deletions test/models/appdata_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require File.expand_path('../../test_helper', __FILE__)

class AppdataTest < ActiveSupport::TestCase
test 'Factory Appdata can be parsed' do
appdata = Appdata.get('factory')
pkg_list = appdata[:apps].map { |p| p[:pkgname] }.uniq

assert_equal 4, pkg_list.size
assert_equal ['0ad', '4pane', 'opera', 'steam'], pkg_list
end
end
Binary file added test/support/appdata-non-oss.xml.gz
Binary file not shown.
506 changes: 502 additions & 4 deletions test/support/distributions.xml

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ENV["RAILS_ENV"] = "test"

require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

Expand All @@ -14,30 +12,32 @@
class ActiveSupport::TestCase
# Helper to associate queries to OBS with the corresponding file in
# test/support
def stub_remote_file(url, filename)
def stub_content(url, body)
%w[http https].each do |protocol|
stub_request(:any, "#{protocol}://test:test@#{url}").to_return(body: File.read(Rails.root.join('test', 'support', filename)))
stub = stub_request(:any, "#{protocol}://#{url}").to_return(body: body)
stub.with(basic_auth: ['test', 'test']) if url =~ /^api/
end
end

def stub_remote_file(url, filename)
stub_content(url, File.read(Rails.root.join('test', 'support', filename)))
end

setup do
# stub OBS using WebMock
stub_remote_file("api.opensuse.org/public/distributions?", "distributions.xml")
stub_remote_file("download.opensuse.org/factory/repo/oss/suse/setup/descr/appdata.xml.gz?", "appdata.xml.gz")
# stub_remote_file("download.opensuse.org/factory/repo/non-oss/suse/setup/descr/appdata.xml.gz?", "appdata-non-oss.xml.gz")
stub_remote_file("download.opensuse.org/tumbleweed/repo/oss/suse/setup/descr/appdata.xml.gz", "appdata.xml.gz")
stub_remote_file("download.opensuse.org/tumbleweed/repo/non-oss/suse/setup/descr/appdata.xml.gz", "appdata-non-oss.xml.gz")
stub_remote_file("api.opensuse.org/search/published/binary/id?match=@name%20=%20'pidgin'%20", "pidgin.xml")
stub_remote_file("api.opensuse.org/published/openSUSE:13.1/standard/i586/pidgin-2.10.7-4.1.3.i586.rpm?view=fileinfo", "pidgin-fileinfo.xml")
stub_request(:get, "https://test:test@api.opensuse.org/source/openSUSE:13.1/_attribute/OBS:QualityCategory").to_return(body: "<attributes/>")
stub_content("api.opensuse.org/source/openSUSE:13.1/_attribute/OBS:QualityCategory", "<attributes/>")
end
end

class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL

# Stop ActiveRecord from wrapping tests in transactions
self.use_transactional_fixtures = false

teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
Expand Down

0 comments on commit b7440c7

Please sign in to comment.