~psivaa/uci-engine/lander-jenkins-plugin

« back to all changes in this revision

Viewing changes to cli/tests/test_changes_processor.py

[r=Francis Ginther] Add CLI component and changes parser  from Ursula Junque

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Ubuntu Continuous Integration Engine
 
2
# Copyright 2013 Canonical Ltd.
 
3
 
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under
 
6
# the terms of the GNU General Public License version 3, as published by the
 
7
# Free Software Foundation.
 
8
 
 
9
# This program is distributed in the hope that it will be useful, but WITHOUT
 
10
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
11
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License along with
 
15
# this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
from os import listdir
 
18
from os.path import basename, join
 
19
from unittest import TestCase
 
20
from cli.changes_processor import ChangesProcessor
 
21
from dput.changes import Changes, ChangesFileException
 
22
 
 
23
 
 
24
TEST_DATA_ROOT = "tests/data/"
 
25
 
 
26
 
 
27
class ChangesProcessorTestCase(TestCase):
 
28
 
 
29
    def create_test_info(self, source_name="foobar", source_version="0.1",
 
30
                         packaging_version="1"):
 
31
        self.source_name = source_name
 
32
        self.source_version = source_version
 
33
        self.packaging_version = packaging_version
 
34
        self.changes_file = (
 
35
            "%s_%s-%s_source.changes" % (self.source_name, self.source_version,
 
36
                                         self.packaging_version))
 
37
        self.dsc_file = (
 
38
            "%s_%s-%s.dsc" % (self.source_name, self.source_version,
 
39
                              self.packaging_version))
 
40
        self.debian_tar_gz_file = (
 
41
            "%s_%s-%s.debian.tar.gz" % (self.source_name, self.source_version,
 
42
                                        self.packaging_version))
 
43
        self.orig_file = "%s_%s.orig.tar.xz" % (self.source_name,
 
44
                                                self.source_version)
 
45
 
 
46
    def setUp(self):
 
47
        self.create_test_info()
 
48
 
 
49
    def test_parse(self):
 
50
        processor = ChangesProcessor(join(TEST_DATA_ROOT, self.changes_file))
 
51
        processor.parse()
 
52
        self.assertIsInstance(processor.changes, Changes)
 
53
        self.assertEqual(processor.changes.get_package_name(),
 
54
                         self.source_name)
 
55
 
 
56
        self.assertEqual(self.dsc_file, processor.changes.get_dsc())
 
57
        self.assertEqual(self.debian_tar_gz_file, processor.changes.get_diff())
 
58
        self.assertTrue(self.orig_file in processor.changes.get_files())
 
59
 
 
60
    def test_parse_changes_file_not_found(self):
 
61
        processor = ChangesProcessor("barbaz_source.changes")
 
62
        self.assertRaises(IOError, processor.parse)
 
63
 
 
64
    def test_all_files_found(self):
 
65
        processor = ChangesProcessor(join(TEST_DATA_ROOT, self.changes_file))
 
66
        processor.parse()
 
67
        # Specifying where processor can find test data.
 
68
        processor.changes.set_directory(TEST_DATA_ROOT)
 
69
        self.assertEqual(len(processor.files_to_upload), 0)
 
70
        processor.validate_files()
 
71
        # The three files (dsc, debian.tar.gz and orig) plus changes file
 
72
        self.assertEqual(len(processor.files_to_upload), 4)
 
73
 
 
74
    def test_signature_check_fails(self):
 
75
        processor = ChangesProcessor(join(TEST_DATA_ROOT, self.changes_file))
 
76
        processor.parse()
 
77
        # Specifying where processor can find test data.
 
78
        processor.changes.set_directory(TEST_DATA_ROOT)
 
79
        self.assertRaises(ChangesFileException, processor.validate_files,
 
80
                          check_signature=True)