Projet

Général

Profil

0003-admin-allow-connector-slug-edition-5778.patch

Nicolas Roche, 08 juin 2022 12:22

Télécharger (3,06 ko)

Voir les différences:

Subject: [PATCH 3/4] admin: allow connector slug edition (#5778)

 passerelle/views.py   |  2 +-
 tests/test_manager.py | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
passerelle/views.py
144 144
    def get_context_data(self, **kwargs):
145 145
        context = super().get_context_data(**kwargs)
146 146
        context['apps'] = [x for x in get_all_apps() if not x.is_legacy()]
147 147
        context['apps'].sort(key=lambda x: x.get_verbose_name())
148 148
        return context
149 149

  
150 150

  
151 151
class GenericConnectorMixin:
152
    exclude_fields = ('slug', 'users')
152
    exclude_fields = ('users',)
153 153

  
154 154
    def get_connector(self, **kwargs):
155 155
        return kwargs.get('connector')
156 156

  
157 157
    def get_form_class(self):
158 158
        return self.model.get_manager_form_class(exclude=self.exclude_fields)
159 159

  
160 160
    def init_stuff(self, request, *args, **kwargs):
tests/test_manager.py
112 112
    resp.forms[0]['description'] = 'simple test'
113 113
    resp.forms[0]['service_url'] = 'https://example.net/'
114 114
    resp = resp.forms[0].submit()
115 115
    assert resp.status_int == 302
116 116
    assert resp.location.endswith('/photon/test-connector/')
117 117
    resp = resp.follow()
118 118
    assert 'Connector updated' in resp.text
119 119

  
120
    resp = app.get('/manage/photon/test-connector/edit', status=200)
121
    open('/var/www/html/index.html', 'w').write(resp.text)
122
    resp.forms[0]['slug'] = 'test'
123
    resp = resp.forms[0].submit()
124
    assert resp.status_int == 302
125
    assert resp.location.endswith('/photon/test/')
126

  
127

  
128
def test_edit_connector_unique_slug(app, admin_user):
129
    Photon.objects.create(
130
        slug='test-connector',
131
        title='Test Connector',
132
        description='Connector for a simple test',
133
        service_url='https://example.org/',
134
    )
135
    Photon.objects.create(
136
        slug='other-connector',
137
        title='Other Connector',
138
        description='Connector for another test',
139
        service_url='https://example.org/',
140
    )
141
    app = login(app)
142
    resp = app.get('/manage/photon/test-connector/edit', status=200)
143
    assert 'Test Connector' in resp.text
144
    assert resp.html.find('input', {'name': 'title'}).attrs['data-slug-sync'] == 'slug'
145

  
146
    resp.forms[0]['slug'] = 'other-connector'
147
    resp = resp.forms[0].submit()
148
    assert resp.status_int == 200
149
    assert 'Photon with this Identifier already exists.' in resp.text
150

  
120 151

  
121 152
def test_visit_connectors(app, admin_user):
122 153
    app = login(app)
123 154
    resp = app.get('/manage/', status=200)
124 155
    resp = resp.click('Add Connector')
125 156
    for link in re.findall('href="(/manage.*add)"', resp.text):
126 157
        resp = app.get(link, status=200)
127 158

  
128
-