| Total Complexity | 9 |
| Total Lines | 75 |
| Duplicated Lines | 29.33 % |
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 | # coding: utf-8 |
||
| 78 | class ServiceReadabilityTest(TestCase): |
||
| 79 | """ |
||
| 80 | ServiceReadabilityTest |
||
| 81 | """ |
||
| 82 | def setUp(self): |
||
| 83 | self.date_triggered = datetime.datetime(2013, 6, 10, 00, 00) |
||
| 84 | self.data = {'link': 'http://foo.bar/some/thing/else/what/else', |
||
| 85 | 'title': 'what else'} |
||
| 86 | self.consumer_key = settings.TH_READABILITY['consumer_key'] |
||
| 87 | self.consumer_secret = settings.TH_READABILITY['consumer_secret'] |
||
| 88 | |||
| 89 | def test_get_config_th(self): |
||
| 90 | """ |
||
| 91 | does this settings exists ? |
||
| 92 | """ |
||
| 93 | self.assertTrue(settings.TH_READABILITY) |
||
| 94 | self.assertIn('consumer_key', settings.TH_READABILITY) |
||
| 95 | self.assertIn('consumer_secret', settings.TH_READABILITY) |
||
| 96 | |||
| 97 | def test_get_config_th_cache(self): |
||
| 98 | self.assertIn('th_readability', settings.CACHES) |
||
| 99 | |||
| 100 | def test_process_data(self, token='AZERTY123#TH#AZERTY123', trigger_id=1): |
||
| 101 | since = int( |
||
| 102 | time.mktime(datetime.datetime.timetuple(self.date_triggered))) |
||
| 103 | self.assertIn('#TH#', token) |
||
| 104 | token_key, token_secret = token.split('#TH#') |
||
| 105 | |||
| 106 | datas = list() |
||
| 107 | self.assertTrue(isinstance(self.date_triggered, datetime.datetime)) |
||
| 108 | self.assertTrue(token) |
||
| 109 | self.assertTrue(isinstance(trigger_id, int)) |
||
| 110 | self.assertTrue(isinstance(since, int)) |
||
| 111 | self.assertTrue(isinstance(datas, list)) |
||
| 112 | |||
| 113 | client = mock.Mock() |
||
| 114 | client.method(consumer_key=self.consumer_key, |
||
| 115 | consumer_secret=self.consumer_secret, |
||
| 116 | token_key=token_key, |
||
| 117 | token_secret=token_secret) |
||
| 118 | client.method.assert_called_with(consumer_key=self.consumer_key, |
||
| 119 | consumer_secret=self.consumer_secret, |
||
| 120 | token_key=token_key, |
||
| 121 | token_secret=token_secret) |
||
| 122 | |||
| 123 | return datas |
||
| 124 | |||
| 125 | View Code Duplication | def test_save_data(self, token='AZERTY123', trigger_id=1): |
|
| 126 | |||
| 127 | the_return = False |
||
| 128 | self.assertTrue(token) |
||
| 129 | self.assertTrue(isinstance(trigger_id, int)) |
||
| 130 | self.assertIn('link', self.data) |
||
| 131 | self.assertIn('title', self.data) |
||
| 132 | self.assertIsNotNone(self.data['link']) |
||
| 133 | self.assertNotEqual(self.data['title'], '') |
||
| 134 | |||
| 135 | tags = ('test',) |
||
| 136 | title = (self.data['title'] if 'title' in self.data else '') |
||
| 137 | |||
| 138 | readability_instance = mock.Mock(return_value=True) |
||
| 139 | readability_instance.method(url=self.data['link'], title=title, tags=tags) |
||
| 140 | readability_instance.method.assert_called_with(url=self.data['link'], |
||
| 141 | title=title, tags=tags) |
||
| 142 | |||
| 143 | if readability_instance (): |
||
| 144 | the_return = True |
||
| 145 | |||
| 146 | return the_return |
||
| 147 | |||
| 148 | def test_auth(self): |
||
| 149 | pass |
||
| 150 | |||
| 151 | def test_callback(self): |
||
| 152 | pass |
||
| 153 |