File: test_pagure_flask_ui_repo_mirrored_from.py

package info (click to toggle)
pagure 5.14.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 30,904 kB
  • sloc: python: 125,288; javascript: 22,012; makefile: 209; sh: 191
file content (150 lines) | stat: -rw-r--r-- 4,898 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- coding: utf-8 -*-

"""
 (c) 2020 - Copyright Red Hat Inc

 Authors:
   Pierre-Yves Chibon <pingou@pingoured.fr>

"""

from __future__ import unicode_literals, absolute_import

import datetime
import os
import shutil
import sys
import tempfile
import time
import unittest

import pygit2
import six
from unittest.mock import patch, MagicMock, ANY, call

sys.path.insert(
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
)

import pagure.lib.git
import tests

from pagure.lib.repo import PagureRepo


class PagureUiRepoMirroredFromTests(tests.Modeltests):
    """Tests for pagure project that are mirrored from a remote location"""

    maxDiff = None

    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(PagureUiRepoMirroredFromTests, self).setUp()

        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

        # Make the test project mirrored from elsewhere
        self.project = pagure.lib.query.get_authorized_project(
            self.session, "test"
        )
        self.project.mirrored_from = "https://example.com/foo/bar.git"
        self.session.add(self.project)
        self.session.commit()

    def test_custom_projecticon(self):
        """Ensure that the customized project icon is shown the main page of
        the project.
        """
        output = self.app.get("/test")
        output_text = output.get_data(as_text=True)
        self.assertIn(
            '<i class="fa fa-cloud-download text-muted" title="Mirrored from '
            'https://example.com/foo/bar.git"></i>',
            output_text,
        )

    def test_regular_projecticon(self):
        """Ensure that the customized project icon is shown the main page of
        the project.
        """
        output = self.app.get("/test2")
        output_text = output.get_data(as_text=True)
        self.assertNotIn(
            '<i class="fa fa-cloud-download text-muted" title="Mirrored from ',
            output_text,
        )

    def test_settings_shows(self):
        """Ensure that the box to edit the mirrored from value shows up
        in the settings.
        """
        user = tests.FakeUser(username="pingou")
        with tests.user_set(self.app.application, user):
            output = self.app.get("/test/settings")
            self.assertEqual(output.status_code, 200)
            output_text = output.get_data(as_text=True)
            self.assertIn(
                '<input class="form-control" name="mirrored_from" '
                'value="https://example.com/foo/bar.git" />',
                output_text,
            )
            self.assertIn(
                "The (public) url from which this repository is mirrored.",
                output_text,
            )

    def test_settings_not_show(self):
        """Ensure that the box to edit the mirrored from value does not
        show up in the settings when it shouldn't.
        """
        user = tests.FakeUser(username="pingou")
        with tests.user_set(self.app.application, user):
            output = self.app.get("/test2/settings")
            self.assertEqual(output.status_code, 200)
            output_text = output.get_data(as_text=True)
            self.assertNotIn(
                '<input class="form-control" name="mirrored_from" ',
                output_text,
            )
            self.assertNotIn(
                "The (public) url from which this repository is mirrored.",
                output_text,
            )

    def test_edit_mirrored_from(self):
        """Ensure that we can successfully edit the content of the
        mirrored_from field.
        """
        user = tests.FakeUser(username="pingou")
        with tests.user_set(self.app.application, user):
            output = self.app.get("/test/settings")
            self.assertEqual(output.status_code, 200)
            output_text = output.get_data(as_text=True)
            self.assertIn(
                '<input class="form-control" name="mirrored_from" '
                'value="https://example.com/foo/bar.git" />',
                output_text,
            )

            csrf_token = self.get_csrf(output=output)

            data = {
                "csrf_token": csrf_token,
                "description": "test repo",
                "mirrored_from": "https://example2.com/bar.git",
            }
            output = self.app.post(
                "/test/update", data=data, follow_redirects=True
            )
            self.assertEqual(output.status_code, 200)
            output_text = output.get_data(as_text=True)
            self.assertIn(
                '<input class="form-control" name="mirrored_from" '
                'value="https://example2.com/bar.git" />',
                output_text,
            )


if __name__ == "__main__":
    unittest.main(verbosity=2)