Conditions | 1 |
Total Lines | 55 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python3 |
||
71 | def setUp(self): |
||
72 | # calling my base class setup |
||
73 | super().setUp() |
||
74 | |||
75 | # track submission ID |
||
76 | self.submission_id = 1 |
||
77 | |||
78 | # get a submission object |
||
79 | self.submission_obj = Submission.objects.get(pk=self.submission_id) |
||
80 | |||
81 | # set a status which I can submit (equal as calling submit by view) |
||
82 | self.submission_obj.status = WAITING |
||
83 | self.submission_obj.message = "Waiting for biosample submission" |
||
84 | self.submission_obj.save() |
||
85 | |||
86 | # get the names I want to submit |
||
87 | self.name_qs = Name.objects.filter( |
||
88 | Q(animal__isnull=False) | Q(sample__isnull=False), |
||
89 | submission=self.submission_obj) |
||
90 | |||
91 | # set status for names, like validation does. Update only animal |
||
92 | # and sample names (excluding unkwnon animals) |
||
93 | self.name_qs.update(status=READY) |
||
94 | |||
95 | # count number of names in UID for such submission (exclude |
||
96 | # unknown animals) |
||
97 | self.n_to_submit = self.name_qs.count() |
||
98 | |||
99 | # starting mocked objects |
||
100 | self.mock_root_patcher = patch('pyUSIrest.client.Root') |
||
101 | self.mock_root = self.mock_root_patcher.start() |
||
102 | |||
103 | # start root object |
||
104 | self.my_root = self.mock_root.return_value |
||
105 | |||
106 | # mocking chain |
||
107 | self.my_team = self.my_root.get_team_by_name.return_value |
||
108 | self.my_team.name = "subs.test-team-1" |
||
109 | |||
110 | # mocking a new submission |
||
111 | self.new_submission = self.my_team.create_submission.return_value |
||
112 | self.new_submission.name = "new-submission" |
||
113 | |||
114 | # set status. Because of the way mock attributes are stored you can’t |
||
115 | # directly attach a PropertyMock to a mock object. Instead you can |
||
116 | # attach it to the mock type object: |
||
117 | self.new_submission.propertymock = PropertyMock(return_value='Draft') |
||
118 | type(self.new_submission).status = self.new_submission.propertymock |
||
119 | |||
120 | # mocking get_submission_by_name |
||
121 | self.my_submission = self.my_root.get_submission_by_name.return_value |
||
122 | self.my_submission.name = "test-submission" |
||
123 | |||
124 | self.my_submission.propertymock = PropertyMock(return_value='Draft') |
||
125 | type(self.my_submission).status = self.my_submission.propertymock |
||
126 | |||
195 |