| Conditions | 3 | 
| Total Lines | 81 | 
| Code Lines | 50 | 
| Lines | 10 | 
| Ratio | 12.35 % | 
| 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  | 
            ||
| 105 | def mocked_get_submission(*args, **kwargs):  | 
            ||
| 106 | class MockResponse:  | 
            ||
| 107 | def __init__(self, json_data, status_code):  | 
            ||
| 108 | self.json_data = json_data  | 
            ||
| 109 | self.status_code = status_code  | 
            ||
| 110 | self.text = "MockResponse not implemented: %s" % (args[0])  | 
            ||
| 111 | |||
| 112 | def json(self):  | 
            ||
| 113 | return self.json_data  | 
            ||
| 114 | |||
| 115 | # this variable will collect all replies  | 
            ||
| 116 | replies = defaultdict(lambda: MockResponse(None, 404))  | 
            ||
| 117 | |||
| 118 | # a custom function to set up replies for link  | 
            ||
| 119 | View Code Duplication | def set_reply(url, filename, status=200):  | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 120 | # referring to the upper replies variable  | 
            ||
| 121 | nonlocal replies  | 
            ||
| 122 | |||
| 123 | # open data file  | 
            ||
| 124 | with open(os.path.join(DATA_PATH, filename)) as handle:  | 
            ||
| 125 | data = json.load(handle)  | 
            ||
| 126 | |||
| 127 | # track reply to URL  | 
            ||
| 128 | replies[url] = MockResponse(data, status)  | 
            ||
| 129 | |||
| 130 | submission_prefix = "https://submission-test.ebi.ac.uk/api/submissions"  | 
            ||
| 131 | status_suffix = "submissionStatus"  | 
            ||
| 132 | |||
| 133 | status_link1 = "/".join([  | 
            ||
| 134 | submission_prefix,  | 
            ||
| 135 | "87e7abda-81a8-4b5e-a1c0-323f7f0a4e43",  | 
            ||
| 136 | status_suffix])  | 
            ||
| 137 | |||
| 138 | status_link2 = "/".join([  | 
            ||
| 139 | submission_prefix,  | 
            ||
| 140 | "8b05e7f2-92c1-4651-94cb-9101f351f000",  | 
            ||
| 141 | status_suffix])  | 
            ||
| 142 | |||
| 143 | # --- to test get_submission_by_name  | 
            ||
| 144 | byname_link = "/".join([  | 
            ||
| 145 | submission_prefix, "c8c86558-8d3a-4ac5-8638-7aa354291d61"])  | 
            ||
| 146 | |||
| 147 | status_link3 = "/".join([  | 
            ||
| 148 | submission_prefix,  | 
            ||
| 149 | "c8c86558-8d3a-4ac5-8638-7aa354291d61",  | 
            ||
| 150 | status_suffix])  | 
            ||
| 151 | |||
| 152 | # --- for each url, return a different response  | 
            ||
| 153 | set_reply(  | 
            ||
| 154 | 'https://submission-test.ebi.ac.uk/api/user/submissions',  | 
            ||
| 155 | "userSubmissionsPage1.json")  | 
            ||
| 156 | |||
| 157 | set_reply(  | 
            ||
| 158 | 'https://submission-test.ebi.ac.uk/api/user/submissions'  | 
            ||
| 159 | '?page=1&size=1',  | 
            ||
| 160 | "userSubmissionsPage2.json")  | 
            ||
| 161 | |||
| 162 | set_reply(status_link1, "submissionStatus1.json")  | 
            ||
| 163 | |||
| 164 | set_reply(status_link2, "submissionStatus2.json")  | 
            ||
| 165 | |||
| 166 | set_reply(byname_link, "newSubmission.json")  | 
            ||
| 167 | |||
| 168 | set_reply(byname_link, "newSubmission.json")  | 
            ||
| 169 | |||
| 170 | set_reply(status_link3, "submissionStatus2.json")  | 
            ||
| 171 | |||
| 172 | # to reload submissions  | 
            ||
| 173 | set_reply(  | 
            ||
| 174 | submission_prefix + "/" +  | 
            ||
| 175 | "87e7abda-81a8-4b5e-a1c0-323f7f0a4e43",  | 
            ||
| 176 | "Submission1.json"  | 
            ||
| 177 | )  | 
            ||
| 178 | |||
| 179 | set_reply(  | 
            ||
| 180 | submission_prefix + "/" +  | 
            ||
| 181 | "8b05e7f2-92c1-4651-94cb-9101f351f000",  | 
            ||
| 182 | "Submission2.json"  | 
            ||
| 183 | )  | 
            ||
| 184 | |||
| 185 | return replies[args[0]]  | 
            ||
| 186 | |||
| 258 |