MCPcopy Index your code
hub / github.com/WebODM/WebODM / test_plugin_loading

Method test_plugin_loading

app/tests/test_plugins.py:257–364  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

255
256
257 def test_plugin_loading(self):
258 c = Client()
259
260 plugin_file = open("app/fixtures/testabc_plugin.zip", 'rb')
261 bad_dir_plugin_file = open("app/fixtures/bad_dir_plugin.zip", 'rb')
262 missing_manifest_plugin_file = open("app/fixtures/missing_manifest_plugin.zip", 'rb')
263
264 # Cannot upload new plugins anonymously
265 res = c.post('/admin/app/plugin/actions/upload/', {'file': plugin_file}, follow=True)
266 self.assertRedirects(res, '/admin/login/?next=/admin/app/plugin/actions/upload/')
267 self.assertFalse(os.path.exists(get_plugins_persistent_path("testabc")))
268 plugin_file.seek(0)
269
270 # Cannot upload plugins as a normal user
271 c.login(username='testuser', password='test1234')
272 res = c.post('/admin/app/plugin/actions/upload/', {'file': plugin_file}, follow=True)
273 self.assertRedirects(res, '/admin/login/?next=/admin/app/plugin/actions/upload/')
274 self.assertFalse(os.path.exists(get_plugins_persistent_path("testabc")))
275 self.assertEqual(Plugin.objects.filter(pk='testabc').count(), 0)
276 plugin_file.seek(0)
277
278 # Can upload plugin as an admin
279 c.login(username='testsuperuser', password='test1234')
280 res = c.post('/admin/app/plugin/actions/upload/', {'file': plugin_file}, follow=True)
281 self.assertRedirects(res, '/admin/app/plugin/')
282 messages = list(res.context['messages'])
283 self.assertTrue('Plugin added successfully' in str(messages[0]))
284 self.assertTrue(os.path.exists(get_plugins_persistent_path("testabc")))
285 plugin_file.seek(0)
286
287 # Plugin has been added to db
288 self.assertEqual(Plugin.objects.filter(pk='testabc').count(), 1)
289
290 # This is not a persistent plugin
291 self.assertFalse(get_plugin_by_name('testabc').is_persistent())
292
293 # Cannot upload the same plugin again (same name)
294 res = c.post('/admin/app/plugin/actions/upload/', {'file': plugin_file}, follow=True)
295 self.assertRedirects(res, '/admin/app/plugin/')
296 messages = list(res.context['messages'])
297 self.assertTrue('already exist' in str(messages[0]))
298 plugin_file.seek(0)
299
300 # Can access paths (while being logged in)
301 res = c.get('/plugins/testabc/hello/')
302 self.assertEqual(res.status_code, status.HTTP_200_OK)
303 res = c.get('/api/plugins/testabc/hello/')
304 self.assertEqual(res.status_code, status.HTTP_200_OK)
305
306 # Can access public paths as logged-in, (per plugin directive)
307 res = c.get('/plugins/testabc/file.txt')
308 self.assertEqual(res.status_code, status.HTTP_200_OK)
309
310 c.logout()
311
312 # Can still access the paths as anonymous
313 res = c.get('/plugins/testabc/hello/')
314 self.assertEqual(res.status_code, status.HTTP_200_OK)

Callers

nothing calls this directly

Calls 8

get_plugin_by_nameFunction · 0.90
existsMethod · 0.80
loginMethod · 0.80
is_persistentMethod · 0.80
postMethod · 0.45
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected