Project

General

Profile

Download (3.72 KB) Statistics
| Branch: | Tag: | Revision:

runcible / test / extensions / deb_repository_test.rb @ c022bb6f

1
require 'rubygems'
2
require 'minitest/autorun'
3

    
4
require './test/support/repository_support'
5
require './lib/runcible'
6

    
7
module Extensions
8
  module TestDebRepositoryBase
9
    def setup
10
      @support = RepositorySupport.new('deb')
11
      @extension = TestRuncible.server.extensions.repository
12
    end
13
  end
14

    
15
  class TestDebRepositoryCreate < MiniTest::Unit::TestCase
16
    include TestDebRepositoryBase
17

    
18
    def teardown
19
      @support.destroy_repo
20
      super
21
    end
22

    
23
    def test_create_with_importer
24
      response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'deb_importer')
25
      assert_equal 201, response.code
26

    
27
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
28
      assert_equal RepositorySupport.repo_id, response['id']
29
      assert_equal 'deb_importer', response['importers'].first['importer_type_id']
30
    end
31

    
32
    def test_create_with_importer_object
33
      response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::DebImporter.new)
34
      assert_equal 201, response.code
35

    
36
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
37
      assert_equal RepositorySupport.repo_id, response['id']
38
      assert_equal 'deb_importer', response['importers'].first['importer_type_id']
39

    
40
      @extension.expects(:create).with(RepositorySupport.repo_id, has_entry(:notes, anything)).returns(true)
41
      @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::DebImporter.new)
42
    end
43

    
44
    def test_create_with_distributors
45
      distributors = [{'type_id' => 'deb_distributor', 'id' => '123', 'auto_publish' => true,
46
                       'config' => {'relative_url' => '/path', 'http' => true, 'https' => true}}]
47
      response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors)
48

    
49
      assert_equal 201, response.code
50
      assert_equal RepositorySupport.repo_id, response['id']
51
    end
52

    
53
    def test_create_with_distributor_object
54
      repo_id = RepositorySupport.repo_id + '_distro'
55
      response = @extension.create_with_distributors(repo_id, [Runcible::Models::DebDistributor.new(
56
        '/path', true, true, :id => '123')])
57
      assert_equal 201, response.code
58

    
59
      response = @extension.retrieve(repo_id, :details => true)
60
      assert_equal repo_id, response['id']
61
      assert_equal 'deb_distributor', response['distributors'].first['distributor_type_id']
62
    ensure
63
      @support.destroy_repo(repo_id)
64
    end
65

    
66
    def test_create_with_importer_and_distributors
67
      distributors = [{'type_id' => 'deb_distributor', 'id' => '234', 'auto_publish' => true,
68
                       'config' => {'relative_url' => '/path', 'http' => true, 'https' => true}}]
69
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id,
70
                                                                 {:id => 'deb_importer'}, distributors)
71
      assert_equal 201, response.code
72

    
73
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
74
      assert_equal RepositorySupport.repo_id, response['id']
75
      assert_equal 'deb_distributor', response['distributors'].first['distributor_type_id']
76
    end
77

    
78
    def test_create_with_importer_and_distributors_objects
79
      distributors = [Runcible::Models::DebDistributor.new('/path', true, true, :id => '123')]
80
      importer = Runcible::Models::DebImporter.new
81
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors)
82
      assert_equal 201, response.code
83

    
84
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
85
      assert_equal RepositorySupport.repo_id, response['id']
86
      assert_equal 'deb_importer', response['importers'].first['importer_type_id']
87
    end
88
  end
89
end