~launchpad-pqm/launchpad/devel

10918.4.2 by Michael Nelson
Added failing test for second oops - LocationError: (None, 'filesize')
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
# pylint: disable-msg=F0401
5
10918.4.4 by Michael Nelson
switched to use QuietFakeLogger.
6
"""Unit tests for TestSourcePackageReleaseFiles."""
10918.4.2 by Michael Nelson
Added failing test for second oops - LocationError: (None, 'filesize')
7
8
__metaclass__ = type
9
__all__ = [
10
    'TestSourcePackageReleaseFiles',
11
    'test_suite',
12
    ]
13
14
from zope.security.proxy import removeSecurityProxy
15
11666.3.5 by Curtis Hovey
Import layers from canonical.testing.layers.
16
from canonical.testing.layers import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
17
    DatabaseFunctionalLayer,
18
    LaunchpadFunctionalLayer,
19
    )
10918.4.2 by Michael Nelson
Added failing test for second oops - LocationError: (None, 'filesize')
20
from lp.testing import TestCaseWithFactory
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
21
from lp.testing.factory import remove_security_proxy_and_shout_at_engineer
10918.4.2 by Michael Nelson
Added failing test for second oops - LocationError: (None, 'filesize')
22
from lp.testing.views import create_initialized_view
23
24
25
class TestSourcePackageReleaseFiles(TestCaseWithFactory):
26
    """Source package release files are rendered correctly."""
27
28
    layer = LaunchpadFunctionalLayer
29
30
    def setUp(self):
31
        super(TestSourcePackageReleaseFiles, self).setUp()
32
        self.source_package_release = self.factory.makeSourcePackageRelease()
33
34
    def test_spr_files_none(self):
35
        # The snippet renders appropriately when there are no files.
36
        view = create_initialized_view(self.source_package_release, "+files")
37
        html = view.__call__()
38
        self.failUnless('No files available for download.' in html)
39
40
    def test_spr_files_one(self):
41
        # The snippet links to the file when present.
42
        library_file = self.factory.makeLibraryFileAlias(
43
            filename='test_file.dsc', content='0123456789')
44
        self.source_package_release.addFile(library_file)
45
        view = create_initialized_view(self.source_package_release, "+files")
46
        html = view.__call__()
47
        self.failUnless('test_file.dsc' in html)
48
49
    def test_spr_files_deleted(self):
50
        # The snippet handles deleted files too.
51
        library_file = self.factory.makeLibraryFileAlias(
52
            filename='test_file.dsc', content='0123456789')
53
        self.source_package_release.addFile(library_file)
54
        removeSecurityProxy(library_file).content = None
55
        view = create_initialized_view(self.source_package_release, "+files")
56
        html = view.__call__()
10918.4.3 by Michael Nelson
Updated template to cope with deleted files.
57
        self.failUnless('test_file.dsc (deleted)' in html)
10918.4.5 by Michael Nelson
Removed lint.
58
59
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
60
class TestSourcePackageReleaseView(TestCaseWithFactory):
61
62
    layer = DatabaseFunctionalLayer
63
64
    def setUp(self):
65
        super(TestSourcePackageReleaseView, self).setUp()
66
        self.source_package_release = self.factory.makeSourcePackageRelease()
67
68
    def test_highlighted_copyright_is_None(self):
69
        expected = ''
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
70
        remove_security_proxy_and_shout_at_engineer(
71
            self.source_package_release).copyright = None
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
72
        view = create_initialized_view(
73
            self.source_package_release, '+copyright')
74
        self.assertEqual(expected, view.highlighted_copyright)
75
76
    def test_highlighted_copyright_no_matches(self):
77
        expected = 'nothing to see and/or do.'
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
78
        remove_security_proxy_and_shout_at_engineer(
79
            self.source_package_release).copyright = expected
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
80
        view = create_initialized_view(
81
            self.source_package_release, '+copyright')
82
        self.assertEqual(expected, view.highlighted_copyright)
83
84
    def test_highlighted_copyright_match_url(self):
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
85
        remove_security_proxy_and_shout_at_engineer(
86
            self.source_package_release).copyright = (
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
87
            'Downloaded from https://upstream.dom/fnord/no/ and')
88
        expected = (
89
            'Downloaded from '
12079.2.7 by Curtis Hovey
Resolved conflicts and removed last uses of the highlighted css class.
90
            '<span class="highlight">https://upstream.dom/fnord/no/</span> '
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
91
            'and')
92
        view = create_initialized_view(
93
            self.source_package_release, '+copyright')
94
        self.assertEqual(expected, view.highlighted_copyright)
95
96
    def test_highlighted_copyright_match_path(self):
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
97
        remove_security_proxy_and_shout_at_engineer(
98
            self.source_package_release).copyright = (
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
99
            'See /usr/share/common-licenses/GPL')
100
        expected = (
101
            'See '
12079.2.7 by Curtis Hovey
Resolved conflicts and removed last uses of the highlighted css class.
102
            '<span class="highlight">/usr/share/common-licenses/GPL</span>')
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
103
        view = create_initialized_view(
104
            self.source_package_release, '+copyright')
105
        self.assertEqual(expected, view.highlighted_copyright)
106
107
    def test_highlighted_copyright_match_multiple(self):
11151.3.3 by Abel Deuring
fix tests that failed for proxied distroseries and productseries objects
108
        remove_security_proxy_and_shout_at_engineer(
109
            self.source_package_release).copyright = (
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
110
            'See /usr/share/common-licenses/GPL or https://osi.org/mit')
111
        expected = (
112
            'See '
12079.2.7 by Curtis Hovey
Resolved conflicts and removed last uses of the highlighted css class.
113
            '<span class="highlight">/usr/share/common-licenses/GPL</span> '
114
             'or <span class="highlight">https://osi.org/mit</span>')
11078.4.3 by Curtis Hovey
Added sourcepackage +copyright.
115
        view = create_initialized_view(
116
            self.source_package_release, '+copyright')
117
        self.assertEqual(expected, view.highlighted_copyright)