Total Complexity | 5 |
Total Lines | 69 |
Duplicated Lines | 76.81 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | #!/usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | """ |
||
4 | Created on Sat Jan 25 17:51:52 2020 |
||
5 | |||
6 | @author: Paolo Cozzi <[email protected]> |
||
7 | """ |
||
8 | |||
9 | from django.test import Client, TestCase |
||
10 | from django.contrib.auth import get_user_model |
||
11 | from django.urls import reverse |
||
12 | |||
13 | from uid.tests.mixins import PersonMixinTestCase |
||
14 | |||
15 | |||
16 | View Code Duplication | class AdminTestCase(PersonMixinTestCase, TestCase): |
|
|
|||
17 | """With this module, I want to test custom admin classes. See: |
||
18 | |||
19 | https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#admin-reverse-urls |
||
20 | |||
21 | to have a list of admin views |
||
22 | """ |
||
23 | |||
24 | fixtures = [ |
||
25 | 'uid/animal', |
||
26 | 'uid/dictbreed', |
||
27 | 'uid/dictcountry', |
||
28 | 'uid/dictrole', |
||
29 | 'uid/dictsex', |
||
30 | 'uid/dictspecie', |
||
31 | 'uid/dictstage', |
||
32 | 'uid/dictuberon', |
||
33 | 'uid/organization', |
||
34 | 'uid/publication', |
||
35 | 'uid/sample', |
||
36 | 'uid/submission', |
||
37 | 'uid/user', |
||
38 | 'validation/validationresult', |
||
39 | 'validation/validationsummary', |
||
40 | ] |
||
41 | |||
42 | @classmethod |
||
43 | def setUpClass(cls): |
||
44 | # calling my base class setup |
||
45 | super().setUpClass() |
||
46 | |||
47 | # create an admin user |
||
48 | User = get_user_model() |
||
49 | User.objects.create_superuser( |
||
50 | username='admin', |
||
51 | password='test', |
||
52 | email='[email protected]') |
||
53 | |||
54 | def setUp(self): |
||
55 | self.client = Client() |
||
56 | self.client.login(username='admin', password='test') |
||
57 | |||
58 | def check_response(self, url): |
||
59 | response = self.client.get(url) |
||
60 | self.assertEqual(response.status_code, 200) |
||
61 | |||
62 | def test_validationresult(self): |
||
63 | url = reverse('admin:validation_validationresult_changelist') |
||
64 | self.check_response(url) |
||
65 | |||
66 | def test_validationsummary(self): |
||
67 | url = reverse('admin:validation_validationsummary_changelist') |
||
68 | self.check_response(url) |
||
69 |