How to use writable method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

testSearchAndModifyEntries.py

Source:testSearchAndModifyEntries.py Github

copy

Full Screen

...87 def test_search_and_delete_entry(self):88 add_user(self.connection, testcase_id, 'del1', attributes={'givenName': 'givenname-delete'})89 read_only_entry = self.get_entry('del1')90 self.assertEqual(read_only_entry.entry_status, STATUS_READ)91 writable_entry = read_only_entry.entry_writable('inetorgperson')92 self.assertEqual(writable_entry.entry_status, STATUS_WRITABLE)93 writable_entry.entry_delete()94 self.assertEqual(writable_entry.entry_status, STATUS_READY_FOR_DELETION)95 result = writable_entry.entry_commit_changes()96 self.assertEqual(writable_entry.entry_status, STATUS_DELETED)97 self.assertTrue(result)98 counter = 2099 while counter > 0: # waits for at maximum 20 times - delete operation can take some time to complete100 status, result, response, request = get_response_values(self.connection.search(search_base=test_base, search_filter='(' + test_name_attr + '=' + testcase_id + 'del1)', attributes=[test_name_attr, 'givenName']), self.connection)101 entries = self.connection._get_entries(response, request)102 if len(entries) == 0:103 break104 sleep(3)105 counter -= 1106 self.assertEqual(result['description'], 'success')107 self.assertEqual(len(entries), 0)108 self.compare_entries(read_only_entry, writable_entry)109 def test_search_and_add_value_to_existing_single_value(self):110 read_only_entry = self.get_entry('mod-2')111 writable_entry = read_only_entry.entry_writable('inetorgperson')112 writable_entry[test_singlevalued_attribute].add('single')113 writable_entry.entry_commit_changes()114 cursor = writable_entry.entry_cursor115 if not cursor.failed:116 self.fail('error assigning to existing single value')117 self.assertEqual(len(cursor.errors), 1)118 self.assertTrue(cursor.errors[0].result['result'] in [RESULT_CONSTRAINT_VIOLATION, RESULT_ATTRIBUTE_OR_VALUE_EXISTS])119 def test_search_and_implicit_add_value_to_existing_single_value(self):120 read_only_entry = self.get_entry('mod-2')121 writable_entry = read_only_entry.entry_writable('inetorgperson')122 writable_entry[test_singlevalued_attribute] += 'single'123 writable_entry.entry_commit_changes()124 cursor = writable_entry.entry_cursor125 if not cursor.failed:126 self.fail('error assigning to existing single value')127 self.assertEqual(len(cursor.errors), 1)128 self.assertTrue(cursor.errors[0].result['result'] in [RESULT_CONSTRAINT_VIOLATION, RESULT_ATTRIBUTE_OR_VALUE_EXISTS])129 def test_search_and_add_value_to_existing_single_value_with_exception(self):130 if test_strategy != REUSABLE: # in REUSABLE strategy the connection can't be changed131 old_raise_exception = self.connection.raise_exceptions132 self.connection.raise_exceptions = True133 read_only_entry = self.get_entry('mod-2')134 writable_entry = read_only_entry.entry_writable('inetorgperson')135 writable_entry[test_singlevalued_attribute].add('single')136 try:137 writable_entry.entry_commit_changes()138 except (LDAPConstraintViolationResult, LDAPAttributeOrValueExistsResult):139 return140 finally:141 self.connection.raise_exceptions = old_raise_exception142 self.fail('error assigning to existing single value')143 def test_search_and_implicit_add_value_to_existing_single_value_with_exception(self):144 if test_strategy != REUSABLE: # in REUSABLE strategy the connection can't be changed145 old_raise_exception = self.connection.raise_exceptions146 self.connection.raise_exceptions = True147 read_only_entry = self.get_entry('mod-2')148 writable_entry = read_only_entry.entry_writable('inetorgperson')149 writable_entry[test_singlevalued_attribute] += 'single'150 try:151 writable_entry.entry_commit_changes()152 except (LDAPConstraintViolationResult, LDAPAttributeOrValueExistsResult):153 return154 finally:155 self.connection.raise_exceptions = old_raise_exception156 self.fail('error assigning to existing single value')157 def test_search_and_add_value_to_non_existing_single_value(self):158 read_only_entry = self.get_entry('mod-1')159 writable_entry = read_only_entry.entry_writable('inetorgperson')160 writable_entry[test_singlevalued_attribute].add('single')161 result = writable_entry.entry_commit_changes()162 self.assertTrue(result)163 self.assertEqual(writable_entry[test_singlevalued_attribute], 'single')164 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)165 self.compare_entries(read_only_entry, writable_entry)166 def test_search_and_implicit_add_value_to_non_existing_single_value(self):167 read_only_entry = self.get_entry('mod-1')168 writable_entry = read_only_entry.entry_writable('inetorgperson', attributes=[test_singlevalued_attribute])169 writable_entry[test_singlevalued_attribute] += 'single'170 result = writable_entry.entry_commit_changes()171 self.assertTrue(result)172 self.assertEqual(writable_entry[test_singlevalued_attribute], 'single')173 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)174 self.compare_entries(read_only_entry, writable_entry)175 def test_search_and_add_value_to_existing_multi_value(self):176 read_only_entry = self.get_entry('mod-1')177 writable_entry = read_only_entry.entry_writable('inetorgperson')178 writable_entry[test_multivalued_attribute].add('added-givenname-1')179 result = writable_entry.entry_commit_changes()180 self.assertTrue(result)181 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])182 self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute])183 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)184 self.compare_entries(read_only_entry, writable_entry)185 def test_search_and_implicit_add_value_to_existing_multi_value(self):186 read_only_entry = self.get_entry('mod-1')187 writable_entry = read_only_entry.entry_writable('inetorgperson')188 writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-1'189 result = writable_entry.entry_commit_changes()190 self.assertTrue(result)191 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])192 self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute])193 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)194 self.compare_entries(read_only_entry, writable_entry)195 def test_search_and_add_values_to_existing_multi_value(self):196 read_only_entry = self.get_entry('mod-1')197 writable_entry = read_only_entry.entry_writable('inetorgperson')198 writable_entry[test_multivalued_attribute].add('added-givenname-1')199 writable_entry[test_multivalued_attribute].add('added-givenname-2')200 result = writable_entry.entry_commit_changes()201 self.assertTrue(result)202 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])203 self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute])204 self.assertTrue('added-givenname-2' in writable_entry[test_multivalued_attribute])205 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3)206 self.compare_entries(read_only_entry, writable_entry)207 def test_search_and_implicit_add_values_to_existing_multi_value(self):208 read_only_entry = self.get_entry('mod-1')209 writable_entry = read_only_entry.entry_writable('inetorgperson')210 writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-1'211 writable_entry[test_multivalued_attribute] += 'implicit-added-givenname-2'212 result = writable_entry.entry_commit_changes()213 self.assertTrue(result)214 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])215 self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute])216 self.assertTrue('implicit-added-givenname-2' in writable_entry[test_multivalued_attribute])217 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3)218 self.compare_entries(read_only_entry, writable_entry)219 def test_search_and_add_values_from_sequence_to_existing_multi_value(self):220 read_only_entry = self.get_entry('mod-1')221 writable_entry = read_only_entry.entry_writable('inetorgperson')222 writable_entry[test_multivalued_attribute].add(['added-givenname-1', 'added-givenname-2'])223 result = writable_entry.entry_commit_changes()224 self.assertTrue(result)225 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])226 self.assertTrue('added-givenname-1' in writable_entry[test_multivalued_attribute])227 self.assertTrue('added-givenname-2' in writable_entry[test_multivalued_attribute])228 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3)229 self.compare_entries(read_only_entry, writable_entry)230 def test_search_and_implicit_add_values_from_sequence_to_existing_multi_value(self):231 read_only_entry = self.get_entry('mod-1')232 writable_entry = read_only_entry.entry_writable('inetorgperson')233 writable_entry[test_multivalued_attribute] += ['implicit-added-givenname-1', 'implicit-added-givenname-2']234 result = writable_entry.entry_commit_changes()235 self.assertTrue(result)236 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])237 self.assertTrue('implicit-added-givenname-1' in writable_entry[test_multivalued_attribute])238 self.assertTrue('implicit-added-givenname-2' in writable_entry[test_multivalued_attribute])239 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 3)240 self.compare_entries(read_only_entry, writable_entry)241 def test_search_and_add_value_to_non_existing_multi_value(self):242 read_only_entry = self.get_entry('mod-1')243 writable_entry = read_only_entry.entry_writable('inetorgperson')244 writable_entry.postalAddress.add('postalAddress-1')245 result = writable_entry.entry_commit_changes()246 self.assertTrue(result)247 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)248 self.assertEqual(len(writable_entry.postalAddress), 1)249 self.compare_entries(read_only_entry, writable_entry)250 def test_search_and_implicit_add_value_to_non_existing_multi_value(self):251 read_only_entry = self.get_entry('mod-1')252 writable_entry = read_only_entry.entry_writable('inetorgperson')253 writable_entry.postalAddress += 'postalAddress-1'254 result = writable_entry.entry_commit_changes()255 self.assertTrue(result)256 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)257 self.assertEqual(len(writable_entry.postalAddress), 1)258 self.compare_entries(read_only_entry, writable_entry)259 def test_search_and_add_values_to_non_existing_multi_value(self):260 read_only_entry = self.get_entry('mod-1')261 writable_entry = read_only_entry.entry_writable('inetorgperson')262 writable_entry.postalAddress.add('postalAddress-1')263 writable_entry.postalAddress.add('postalAddress-2')264 result = writable_entry.entry_commit_changes()265 self.assertTrue(result)266 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)267 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)268 self.assertEqual(len(writable_entry.postalAddress), 2)269 self.compare_entries(read_only_entry, writable_entry)270 def test_search_and_implicit_add_values_to_non_existing_multi_value(self):271 read_only_entry = self.get_entry('mod-1')272 writable_entry = read_only_entry.entry_writable('inetorgperson')273 writable_entry.postalAddress += 'postalAddress-1'274 writable_entry.postalAddress += 'postalAddress-2'275 result = writable_entry.entry_commit_changes()276 self.assertTrue(result)277 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)278 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)279 self.assertEqual(len(writable_entry.postalAddress), 2)280 self.compare_entries(read_only_entry, writable_entry)281 def test_search_and_add_values_from_sequence_to_non_existing_multi_value(self):282 read_only_entry = self.get_entry('mod-1')283 writable_entry = read_only_entry.entry_writable('inetorgperson')284 writable_entry.postalAddress.add(['postalAddress-1', 'postalAddress-2'])285 result = writable_entry.entry_commit_changes()286 self.assertTrue(result)287 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)288 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)289 self.assertEqual(len(writable_entry.postalAddress), 2)290 self.compare_entries(read_only_entry, writable_entry)291 def test_search_and_implicit_add_values_from_sequence_to_non_existing_multi_value(self):292 read_only_entry = self.get_entry('mod-1')293 writable_entry = read_only_entry.entry_writable('inetorgperson')294 writable_entry.postalAddress += ['postalAddress-1', 'postalAddress-2']295 result = writable_entry.entry_commit_changes()296 self.assertTrue(result)297 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)298 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)299 self.assertEqual(len(writable_entry.postalAddress), 2)300 self.compare_entries(read_only_entry, writable_entry)301 def test_search_and_set_value_to_existing_single_value(self):302 read_only_entry = self.get_entry('mod-2')303 writable_entry = read_only_entry.entry_writable('inetorgperson')304 writable_entry[test_singlevalued_attribute].set('single')305 result = writable_entry.entry_commit_changes()306 self.assertTrue(result)307 self.assertEqual(writable_entry[test_singlevalued_attribute], 'single')308 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)309 self.compare_entries(read_only_entry, writable_entry)310 def test_search_and_implicit_set_value_to_existing_single_value(self):311 read_only_entry = self.get_entry('mod-2')312 writable_entry = read_only_entry.entry_writable('inetorgperson')313 writable_entry[test_singlevalued_attribute] = 'single'314 result = writable_entry.entry_commit_changes()315 self.assertTrue(result)316 self.assertEqual(writable_entry[test_singlevalued_attribute], 'single')317 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)318 self.compare_entries(read_only_entry, writable_entry)319 def test_search_and_set_value_to_non_existing_single_value(self):320 read_only_entry = self.get_entry('mod-1')321 writable_entry = read_only_entry.entry_writable('inetorgperson')322 writable_entry[test_singlevalued_attribute].set('init')323 result = writable_entry.entry_commit_changes()324 self.assertTrue(result)325 self.assertEqual(writable_entry[test_singlevalued_attribute], 'init')326 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)327 self.compare_entries(read_only_entry, writable_entry)328 def test_search_and_implicit_set_value_to_non_existing_single_value(self):329 read_only_entry = self.get_entry('mod-1')330 writable_entry = read_only_entry.entry_writable('inetorgperson')331 writable_entry[test_singlevalued_attribute] = 'init'332 result = writable_entry.entry_commit_changes()333 self.assertTrue(result)334 self.assertEqual(writable_entry[test_singlevalued_attribute], 'init')335 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 1)336 self.compare_entries(read_only_entry, writable_entry)337 def test_search_and_set_value_to_existing_multi_value(self):338 read_only_entry = self.get_entry('mod-1')339 writable_entry = read_only_entry.entry_writable('inetorgperson')340 writable_entry[test_multivalued_attribute].set('set-givenname-1')341 result = writable_entry.entry_commit_changes()342 self.assertTrue(result)343 self.assertTrue('set-givenname-1' in writable_entry[test_multivalued_attribute])344 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1)345 self.compare_entries(read_only_entry, writable_entry)346 def test_search_and_implicit_set_value_to_existing_multi_value(self):347 read_only_entry = self.get_entry('mod-1')348 writable_entry = read_only_entry.entry_writable('inetorgperson')349 writable_entry[test_multivalued_attribute] = 'implicit-set-givenname-1'350 result = writable_entry.entry_commit_changes()351 self.assertTrue(result)352 self.assertTrue('implicit-set-givenname-1' in writable_entry[test_multivalued_attribute])353 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1)354 self.compare_entries(read_only_entry, writable_entry)355 def test_search_and_set_values_from_sequence_to_existing_multi_value(self):356 read_only_entry = self.get_entry('mod-1')357 writable_entry = read_only_entry.entry_writable('inetorgperson')358 writable_entry[test_multivalued_attribute].set(['set-givenname-1', 'set-givenname-2'])359 result = writable_entry.entry_commit_changes()360 self.assertTrue(result)361 self.assertTrue('set-givenname-1' in writable_entry[test_multivalued_attribute])362 self.assertTrue('set-givenname-2' in writable_entry[test_multivalued_attribute])363 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)364 self.compare_entries(read_only_entry, writable_entry)365 def test_search_and_implicit_set_values_from_sequence_to_existing_multi_value(self):366 read_only_entry = self.get_entry('mod-1')367 writable_entry = read_only_entry.entry_writable('inetorgperson')368 writable_entry[test_multivalued_attribute] = ['implicit-set-givenname-1', 'implicit-set-givenname-2']369 result = writable_entry.entry_commit_changes()370 self.assertTrue(result)371 self.assertTrue('implicit-set-givenname-1' in writable_entry[test_multivalued_attribute])372 self.assertTrue('implicit-set-givenname-2' in writable_entry[test_multivalued_attribute])373 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)374 self.compare_entries(read_only_entry, writable_entry)375 def test_search_and_set_value_to_non_existing_multi_value(self):376 read_only_entry = self.get_entry('mod-1')377 writable_entry = read_only_entry.entry_writable('inetorgperson')378 writable_entry.postalAddress.set('postalAddress-1')379 result = writable_entry.entry_commit_changes()380 self.assertTrue(result)381 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)382 self.assertEqual(len(writable_entry.postalAddress), 1)383 self.compare_entries(read_only_entry, writable_entry)384 def test_search_and_implicit_set_value_to_non_existing_multi_value(self):385 read_only_entry = self.get_entry('mod-1')386 writable_entry = read_only_entry.entry_writable('inetorgperson')387 writable_entry.postalAddress = 'postalAddress-1'388 result = writable_entry.entry_commit_changes()389 self.assertTrue(result)390 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)391 self.assertEqual(len(writable_entry.postalAddress), 1)392 self.compare_entries(read_only_entry, writable_entry)393 def test_search_and_set_values_from_sequence_to_non_existing_multi_value(self):394 read_only_entry = self.get_entry('mod-1')395 writable_entry = read_only_entry.entry_writable('inetorgperson')396 writable_entry.postalAddress.set(['postalAddress-1', 'postalAddress-2'])397 result = writable_entry.entry_commit_changes()398 self.assertTrue(result)399 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)400 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)401 self.assertEqual(len(writable_entry.postalAddress), 2)402 self.compare_entries(read_only_entry, writable_entry)403 def test_search_and_implicit_set_values_from_sequence_to_non_existing_multi_value(self):404 read_only_entry = self.get_entry('mod-1')405 writable_entry = read_only_entry.entry_writable('inetorgperson')406 writable_entry.postalAddress = ['postalAddress-1', 'postalAddress-2']407 result = writable_entry.entry_commit_changes()408 self.assertTrue(result)409 self.assertTrue('postalAddress-1' in writable_entry.postalAddress)410 self.assertTrue('postalAddress-2' in writable_entry.postalAddress)411 self.assertEqual(len(writable_entry.postalAddress), 2)412 self.compare_entries(read_only_entry, writable_entry)413 def test_search_and_remove_existing_attribute(self):414 read_only_entry = self.get_entry('mod-1')415 writable_entry = read_only_entry.entry_writable('inetorgperson')416 writable_entry[test_multivalued_attribute].remove()417 result = writable_entry.entry_commit_changes()418 self.assertTrue(result)419 self.assertEqual(writable_entry[test_multivalued_attribute].values, [])420 self.assertEqual(writable_entry[test_multivalued_attribute].virtual, True)421 def test_search_and_delete_value_from_existing_single_value(self):422 read_only_entry = self.get_entry('mod-2')423 writable_entry = read_only_entry.entry_writable('inetorgperson', attributes='preferreddeliverymethod')424 writable_entry[test_singlevalued_attribute].delete('init')425 result = writable_entry.entry_commit_changes()426 self.assertTrue(result)427 self.assertEqual(writable_entry[test_singlevalued_attribute].value, None)428 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 0)429 def test_search_and_implicit_delete_value_from_existing_single_value(self):430 read_only_entry = self.get_entry('mod-2')431 writable_entry = read_only_entry.entry_writable('inetorgperson', attributes='preferreddeliverymethod')432 writable_entry[test_singlevalued_attribute] -= 'init'433 result = writable_entry.entry_commit_changes()434 self.assertTrue(result)435 self.assertEqual(writable_entry[test_singlevalued_attribute].value, None)436 self.assertEqual(len(writable_entry[test_singlevalued_attribute]), 0)437 def test_search_and_delete_value_from_existing_multi_value(self):438 read_only_entry = self.get_entry('mod-2')439 writable_entry = read_only_entry.entry_writable('inetorgperson')440 writable_entry[test_multivalued_attribute].delete('givenname-2a')441 result = writable_entry.entry_commit_changes()442 self.assertTrue(result)443 self.assertTrue('givenname-2b' in writable_entry[test_multivalued_attribute].value)444 self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value)445 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)446 def test_search_and_implicit_delete_value_from_existing_multi_value(self):447 read_only_entry = self.get_entry('mod-2')448 writable_entry = read_only_entry.entry_writable('inetorgperson')449 writable_entry[test_multivalued_attribute] -= 'givenname-2a'450 result = writable_entry.entry_commit_changes()451 self.assertTrue(result)452 self.assertTrue('givenname-2b' in writable_entry[test_multivalued_attribute].value)453 self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value)454 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 2)455 def test_search_and_delete_values_from_existing_multi_value(self):456 read_only_entry = self.get_entry('mod-2')457 writable_entry = read_only_entry.entry_writable('inetorgperson')458 writable_entry[test_multivalued_attribute].delete(['givenname-2a', 'givenname-2b'])459 result = writable_entry.entry_commit_changes()460 self.assertTrue(result)461 self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value)462 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1)463 def test_search_and_implicit_delete_values_from_existing_multi_value(self):464 read_only_entry = self.get_entry('mod-2')465 writable_entry = read_only_entry.entry_writable('inetorgperson')466 writable_entry[test_multivalued_attribute] -= ['givenname-2a', 'givenname-2b']467 result = writable_entry.entry_commit_changes()468 self.assertTrue(result)469 self.assertTrue('givenname-2c' in writable_entry[test_multivalued_attribute].value)470 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 1)471 def test_search_and_delete_all_values_from_existing_multi_value(self):472 read_only_entry = self.get_entry('mod-2')473 writable_entry = read_only_entry.entry_writable('inetorgperson')474 writable_entry[test_multivalued_attribute].delete(['givenname-2a', 'givenname-2b', 'givenname-2c'])475 result = writable_entry.entry_commit_changes()476 self.assertTrue(result)477 self.assertEqual(writable_entry[test_multivalued_attribute].value, None)478 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 0)479 def test_search_and_implicit_delete_all_values_from_existing_multi_value(self):480 read_only_entry = self.get_entry('mod-2')481 writable_entry = read_only_entry.entry_writable('inetorgperson')482 writable_entry[test_multivalued_attribute] -= ['givenname-2a', 'givenname-2b', 'givenname-2c']483 result = writable_entry.entry_commit_changes()484 self.assertTrue(result)485 self.assertEqual(writable_entry[test_multivalued_attribute].value, None)486 self.assertEqual(len(writable_entry[test_multivalued_attribute]), 0)487 def test_search_and_add_value_to_existing_multi_value_using_alias(self):488 if test_server_type != 'AD': # AD doens't use alias for cn489 read_only_entry = self.get_entry('mod-1')490 writable_entry = read_only_entry.entry_writable('inetorgperson')491 self.assertTrue(testcase_id + 'mod-1' in writable_entry.cn)492 self.assertTrue(testcase_id + 'mod-1' in writable_entry.commonname)493 writable_entry.commonname.add('added-commonname-1')494 result = writable_entry.entry_commit_changes()495 self.assertTrue(result)496 self.assertTrue('added-commonname-1' in writable_entry.cn)497 self.assertTrue('added-commonname-1' in writable_entry.commonname)498 self.assertEqual(len(writable_entry.commonname), 2)499 self.compare_entries(read_only_entry, writable_entry)500 def test_search_and_implicit_add_value_to_existing_multi_value_using_alias(self):501 if test_server_type != 'AD': # AD doens't use alias for cn502 read_only_entry = self.get_entry('mod-1')503 writable_entry = read_only_entry.entry_writable('inetorgperson')504 self.assertTrue(testcase_id + 'mod-1' in writable_entry.cn)505 self.assertTrue(testcase_id + 'mod-1' in writable_entry.commonname)506 writable_entry.commonname += 'implicit-added-commonname-1'507 result = writable_entry.entry_commit_changes()508 self.assertTrue(result)509 self.assertTrue('givenname-1' in writable_entry[test_multivalued_attribute])510 self.assertTrue('implicit-added-commonname-1' in writable_entry.cn)511 self.assertTrue('implicit-added-commonname-1' in writable_entry.commonname)512 self.assertEqual(len(writable_entry.commonname), 2)...

Full Screen

Full Screen

arrange.py

Source:arrange.py Github

copy

Full Screen

...15last_row = dict()16write_row = list()17write_rows = list()18count = 019def update_writable(writable, row):20 writable.setdefault('num', 0)21 writable.setdefault('auction', dict())22 writable.setdefault('merchandise', dict())23 writable.setdefault('device', dict())24 writable.setdefault('country', dict())25 writable.setdefault('ip', dict())26 writable.setdefault('url', dict())27 writable.setdefault('time', dict())28 writable['num'] += 129 # Update each auction the bidder has particapated30 writable['auction'].setdefault(row['auction'], dict())31 writable['auction'][row['auction']].setdefault('device', dict())32 writable['auction'][row['auction']].setdefault('country', dict())33 writable['auction'][row['auction']].setdefault('ip', dict())34 writable['auction'][row['auction']].setdefault('url', dict())35 writable['auction'][row['auction']].setdefault('time', dict())36 writable['auction'][row['auction']].setdefault('amount', 0)37 writable['auction'][row['auction']].setdefault('success', 0)38 writable['auction'][row['auction']]['device'].setdefault(row['device'], 0)39 writable['auction'][row['auction']]['country'].setdefault(row['country'], 0)40 writable['auction'][row['auction']]['ip'].setdefault(row['ip'], 0)41 writable['auction'][row['auction']]['url'].setdefault(row['url'], 0)42 writable['auction'][row['auction']]['time'].setdefault(row['time'], 0)43 writable['auction'][row['auction']]['device'][row['device']] += 144 writable['auction'][row['auction']]['country'][row['country']] += 145 writable['auction'][row['auction']]['ip'][row['ip']] += 146 writable['auction'][row['auction']]['url'][row['url']] += 147 writable['auction'][row['auction']]['time'][row['time']] += 148 if row['amount'] > writable['auction'][row['auction']]['amount']:49 writable['auction'][row['auction']]['amount'] = row['amount']50 if int(row['success']) == 1:51 writable['auction'][row['auction']]['success'] = 152 # Update other features of the bidder53 writable['merchandise'].setdefault(row['merchandise'], 0)54 writable['merchandise'][row['merchandise']] += 155 writable['device'].setdefault(row['device'], 0)56 writable['device'][row['device']] += 157 writable['country'].setdefault(row['country'], 0)58 writable['country'][row['country']] += 159 writable['ip'].setdefault(row['ip'], 0)60 writable['ip'][row['ip']] += 161 writable['url'].setdefault(row['url'], 0)62 writable['url'][row['url']] += 163 writable['time'].setdefault(row['time'], 0)64 writable['time'][row['time']] += 165def argmax(d):66 """67 :param68 d: A dictionary69 :return:70 max_class: the key that have the maximum value of the dictionary71 max_value: the maximum value of the dictionary72 """73 max_value = 074 max_class = None75 for key in d:76 if d[key] > max_value:77 max_value = d[key]78 max_class = key79 return max_value, max_class80def avg_auction(d, target):81 """82 :param83 d: An auction dictionary84 target: 'country', 'device', 'ip' or 'url'85 :return:86 avg_value: the average value of the target87 """88 sum_value = 089 count = 090 for key in d:91 current_value = len(d[key][target].keys())92 sum_value += current_value93 count += 194 return float(sum_value) / count95def max_auction(d, target):96 """97 :param98 d: An auction dictionary99 target: 'country', 'device', 'ip' or 'url'100 :return:101 max_value: the maximum value of the target102 """103 max_value = 0104 for key in d:105 current_value = len(d[key][target].keys())106 if current_value > max_value:107 max_value = current_value108 return max_value109def min_auction(d, target):110 """111 :param112 d: An auction dictionary113 target: 'country', 'device', 'ip' or 'url'114 :return:115 min_value: the minimum value of the target116 """117 min_value = 9999118 for key in d:119 current_value = len(d[key][target].keys())120 if current_value < min_value:121 min_value = current_value122 return min_value123def avg_auction_time(d):124 """125 :param126 d: An auction dictionary127 :return:128 avg_time: the average time the bidder takes to make a bid129 """130 sum_times = 0131 count = 0132 for key in d:133 single_times = sum(d[key]['time'].values())134 sum_times += single_times135 count += 1136 return float(sum_times) / count137def avg_auction_time2(d):138 """139 :param140 d: An auction dictionary141 :return:142 avg_time: the average time the bidder takes to make a bid143 """144 sum_times = 0145 count = 0146 for key in d:147 single_times = np.array(d[key]['time'].values()).mean()148 sum_times += single_times149 count += 1150 return float(sum_times) / count151def auction_amount(d):152 """153 :param154 d: An auction dictionary155 :return:156 avg_amount: the average amount the bidder takes to make a bid157 max_amount: the maximum amount the bidder takes to make a bid158 min_amount: the minimum amount the bidder takes to make a bid159 """160 sum_amount = 0161 max_amount = 0162 min_amount = 99999999163 count = 0164 for key in d:165 amount = int(d[key]['amount'])166 sum_amount += amount167 count += 1168 if amount < min_amount:169 min_amount = amount170 if amount > max_amount:171 max_amount = amount172 return min_amount, float(sum_amount) / count, max_amount173def auction_success(d):174 """175 :param176 d: An auction dictionary177 :return:178 success_num: number of successful bid179 """180 num_success = 0181 for key in d:182 num_success += int(d[key]['success'])183 return num_success184for t, row in enumerate(DictReader(open(filename))):185 if t == 0:186 last_row = row187 update_writable(writable, row)188 continue189 if row['bidder_id'] != last_row['bidder_id']:190 if np.array(writable['time'].values()).mean() > 1:191 avg_times = 1192 else:193 avg_times = 0194 if np.array(writable['time'].values()).max() > 1:195 max_times = 1196 else:197 max_times = 0198 min_amount, avg_amount, max_amount = auction_amount(writable['auction'])199 write_row = [last_row['bidder_id'], writable['num'], avg_auction_time2(writable['auction']),200 avg_auction_time(writable['auction']), avg_auction(writable['auction'], 'device'),201 avg_auction(writable['auction'], 'country'), avg_auction(writable['auction'], 'ip'),202 avg_auction(writable['auction'], 'url'), max_auction(writable['auction'], 'device'),203 max_auction(writable['auction'], 'country'), max_auction(writable['auction'], 'ip'),204 max_auction(writable['auction'], 'url'), min_auction(writable['auction'], 'device'),205 min_auction(writable['auction'], 'country'), min_auction(writable['auction'], 'ip'),206 min_auction(writable['auction'], 'url'), len(writable['auction'].keys()),207 argmax(writable['merchandise'])[1], len(writable['merchandise'].keys()), argmax(writable['device'])[1],208 len(writable['device'].keys()), argmax(writable['country'])[1],209 len(writable['country'].keys()), argmax(writable['ip'])[1], len(writable['ip'].keys()),210 argmax(writable['url'])[1], len(writable['url'].keys()), avg_times,211 np.array(writable['time'].values()).min(), max_times, min_amount, avg_amount, max_amount,212 auction_success(writable['auction'])]213 write_rows.append(write_row)214 count += 1215 writable = dict()216 write_row = list()217 update_writable(writable, row)218 if (count%1000 == 0) and (count != 0):219 print t, count220 last_row = row221open_file_object.writerows(write_rows)...

Full Screen

Full Screen

filters.py

Source:filters.py Github

copy

Full Screen

1import logging2import core as tb3import urllib, urllib24import simplejson5class Bitly(tb.Filter):6 def __init__(self, username, api_key):7 self.username = username8 self.api_key = api_key9 10 def filter(self, writable):11 data = urllib.urlencode({'login': self.username, 'apiKey': self.api_key, 'format': 'json', 'longUrl': writable.permalink})12 response = urllib2.urlopen('http://api.bit.ly/v3/shorten', data)13 response = simplejson.loads(response.read())14 if response['status_code'] == 200:15 writable.permalink = response['data']['url']16 return writable17 18class Googl(tb.Filter):19 def __init__(self, api_key):20 self.api_key = api_key21 22 def filter(self, writable):23 url = 'https://www.googleapis.com/urlshortener/v1/url?key=%s' % self.api_key24 post_data = '{"longUrl": "%s"}' % writable.permalink25 req = urllib2.Request(url=url, data=post_data)26 req.add_header('Content-Type', 'application/json')27 28 try:29 response = urllib2.urlopen(req)30 response = simplejson.loads(response.read())31 writable.permalink = response['id']32 except (urllib2.HTTPError, KeyError):33 pass34 return writable35class YouTubeEmbed(tb.Filter):36 """37 If the content contains a YouTube video, this filter will change38 the writable's permalink to a shortened YouTube link to the video.39 This will create embedded content in Twitter.40 """41 def filter(self, writable):42 import re43 44 content = writable.content if len(writable.content) > len(writable.summary) else writable.summary45 46 search = re.search(r'(http://(www\.|img\.)?youtube\.com/vi?/(.{11}))', content)47 if search:48 url, t, youtube_id = search.groups()49 if url and youtube_id:50 writable.permalink = 'http://youtu.be/%s' % youtube_id51 return writable52 53class NoRetweets(tb.Filter):54 def filter(self, writable):55 if 'rt' in writable.title.lower().split():56 return tb.Writable()57 else:58 return writable59 60class NoDuplicates(tb.Filter):61 """62 Requires the Levenshtein module.63 """64 def __init__(self, threshold=0.60, cache_size=200):65 self.threshold = threshold66 self.cache = []67 self.cache_size = cache_size68 def filter(self, writable):69 import Levenshtein70 71 if len(self.cache) > self.cache_size:72 self.cache = self.cache[-self.cache_size:]73 74 one = writable.title.encode("utf-8")75 for item in self.cache:76 two = item.encode("utf-8")77 if Levenshtein.ratio(one, two) > self.threshold:78 logging.debug("Duplicate detected: \"%s\" matched \"%s\" with a score of %s" % (one, two, Levenshtein.ratio(one, two)))79 return tb.Writable()80 81 self.cache.append(writable.title)82 return writable83 84class NoLinks(tb.Filter):85 def filter(self, writable):86 if 'http://' in writable.title.lower():87 return tb.Writable()88 else:89 return writable90 91class NoMentioins(tb.Filter):92 def filter(self, writable):93 if '@' in writable.title:94 return tb.Writable()95 else:96 return writable97 98class NoHashtags(tb.Filter):99 def filter(self, writable):100 if '#' in writable.title:101 return tb.Writable()102 else:103 return writable104class TagsToHashtags(tb.Filter):105 """106 Scans through the tags argument of a Writable object and appends107 the hash symbol # to every one of them. Please use this filter after108 inline hashtags.109 """110 111 def filter(self, writable):112 tags = []113 for tag in writable.tags:114 if ' ' not in tag and '-' not in tag:115 tags.append('#%s' % tag.lower())116 117 writable.tags = tags118 return writable119 120class InlineHashtags(tb.Filter):121 """122 Inline hashtags filter, mainly for the Twitter channel, can search for123 and replace tags with hashtags, assuming they're listed in the tags124 attribute of the Writable object. The returned writable object's tags125 attribute is left with tags that were not replaced inline (remaining).126 127 Additional tags could be passed to the filter duruing __init__, these128 will not be appended to the final writable.tags list (remaining) but129 will be inlined.130 """131 def __init__(self, additional_tags=[]):132 self.additional_tags = additional_tags133 134 def filter(self, writable):135 original = writable.title136 letters = list(original)137 remaining = []138 for tag in writable.tags + self.additional_tags:139 140 # Let's see if there's already such a hashtag in the title141 if '#%s' % tag in original.lower():142 continue143 144 pos = original.lower().find(tag)145 if pos > -1:146 letters.insert(pos, '#')147 original = ''.join(letters)148 else:149 if tag in writable.tags:150 remaining.append(tag)151 152 writable.title = ''.join(letters)153 writable.tags = remaining154 return writable155class RemoveTags(tb.Filter):156 """157 Removes all tags from a writable.158 """159 def filter(self, writable):160 writable.tags = []161 return writable162class Trim140PermalinkTooLong(): pass163class Trim140(tb.Filter):164 """165 Use this filter to produce tweets. It scans a Writable object and returns166 it with an extra attribute "output" which contains the text trimmed down167 to 140 (or other via options) characters based on a specific pattern168 """169 170 def __init__(self, max_length=140):171 self.max_length = max_length172 173 def filter(self, writable):174 # This won't loop forever175 while True:176 # Loop while our length is not less or equal to max length177 if len(self.construct(writable.title, writable.permalink, writable.tags)) <= self.max_length:178 break179 180 # Do we have any hashtags left?181 if len(writable.tags):182 writable.tags = writable.tags[:-1]#.remove(len(writable.tags))183 continue184 185 # Start shoreting the title (by removing single words)186 if len(writable.title):187 writable.title = ' '.join(writable.title.split()[:-1])188 continue189 190 # If the statements above have failed to "continue", then the tweet191 # cannot be reduced anymore, thus we state that the permalink is too long.192 raise Trim140PermalinkTooLong193 # Format the final string, attach to the Writable and return194 writable.output = self.construct(writable.title, writable.permalink, writable.tags)195 return writable196 197 def construct(self, title, permalink, tags=[]):198 """199 Construct the final string using the specified format.200 """201 s = "%s %s %s" % (title, permalink, ' '.join(tags))202 return s.strip()203# Self-test code.204if __name__ == '__main__':205 # Googl206 print "Googl()"207 googl = Googl(api_key="AIzaSyCa0M20tZw89pBcYU6XM6Qa_k6_sduBMhI")208 writable = tb.Writable(permalink='http://kovshenin.com')209 print "Long link: http://kovshenin.com"210 print "Shortened: %s" % googl.filter(writable).permalink211 212 exit()213 214 # Bitly215 print "Bitly()"216 bitly = Bitly(username='kovshenin', api_key='R_9f3bde0c5e2d36a3e747490bb37a6d5d')217 writable = tb.Writable(permalink='http://kovshenin.com')218 print "Long link: http://kovshenin.com"219 print "Shortened: %s" % bitly.filter(writable).permalink220 print221 222 # NoRetweets223 print "NoRetweets()"224 writables = [tb.Writable(title="Text"), tb.Writable(title="RT Text"), tb.Writable(title="rt text"), tb.Writable(title="rting text")]225 nort = NoRetweets()226 print "Input:"227 for writable in writables:228 print "\t%s" % writable.title229 230 print "Output:"231 for writable in writables:232 writable = nort.filter(writable)233 if writable.title:234 print "\t%s" % writable.title235 236 print237 238 # NoDuplicates239 print "NoDuplicates()"240 writables = [241 tb.Writable(title="8 Gadgets to Watch in 2011 - http://on.mash.to/giO5HX"),242 tb.Writable(title="Creating a safer email environment http://bit.ly/fk34LG #admin"),243 tb.Writable(title="LivingSocial: #Groupon's Not The Only Company That Can Hire A CFO http://tcrn.ch/fc1xne #tc"),244 tb.Writable(title="#Android App Development - Using Android resources part 1: String Resources http://bit.ly/gRKe52"),245 tb.Writable(title="RT @mashable: 8 #Gadgets to Watch in 2011 - http://bit.ly/123456"),246 tb.Writable(title="LivingSocial: Groupon Can Hire a Company CFO: http://bit.ly/99921"),247 tb.Writable(title=u"A Graphic Designer\u2019s Dilemma: How to Prevent Revisions & Other Client Issues"),248 tb.Writable(title=u"A Graphic Designer\u2019s Dilemma: How to Prevent Revisions & Other Client Issues"),249 ]250 nodups = NoDuplicates()251 print "Input:"252 for writable in writables:253 print "\t%s" % writable.title254 255 print "Output:"256 for writable in writables:257 writable = nodups.filter(writable)258 if writable.title:259 print "\t%s" % writable.title260 261 print262 263 exit()264 265 trim = Trim140(max_length=120)266 t2h = TagsToHashtags()267 inline = InlineHashtags()268 269 writable = tb.Writable(title="#Mashable", excerpt="Excerpt", content="Content", tags=['mashable awards', 'lorem', 'dolor', 'Google', 'boogle', 'nice', 'tech'], permalink='http://kovshenin.com')270 writable = inline.filter(writable)271 writable = t2h.filter(writable)272 writable = trim.filter(writable)273 ...

Full Screen

Full Screen

test-stream-inheritance.js

Source:test-stream-inheritance.js Github

copy

Full Screen

1'use strict';2require('../common');3const assert = require('assert');4const { Readable, Writable, Duplex, Transform } = require('stream');5const readable = new Readable({ read() {} });6const writable = new Writable({ write() {} });7const duplex = new Duplex({ read() {}, write() {} });8const transform = new Transform({ transform() {} });9assert.ok(readable instanceof Readable);10assert.ok(!(writable instanceof Readable));11assert.ok(duplex instanceof Readable);12assert.ok(transform instanceof Readable);13assert.ok(!(readable instanceof Writable));14assert.ok(writable instanceof Writable);15assert.ok(duplex instanceof Writable);16assert.ok(transform instanceof Writable);17assert.ok(!(readable instanceof Duplex));18assert.ok(!(writable instanceof Duplex));19assert.ok(duplex instanceof Duplex);20assert.ok(transform instanceof Duplex);21assert.ok(!(readable instanceof Transform));22assert.ok(!(writable instanceof Transform));23assert.ok(!(duplex instanceof Transform));24assert.ok(transform instanceof Transform);25assert.ok(!(null instanceof Writable));26assert.ok(!(undefined instanceof Writable));27// Simple inheritance check for `Writable` works fine in a subclass constructor.28function CustomWritable() {29 assert.ok(30 this instanceof CustomWritable,31 `${this} does not inherit from CustomWritable`32 );33 assert.ok(34 this instanceof Writable,35 `${this} does not inherit from Writable`36 );37}38Object.setPrototypeOf(CustomWritable, Writable);39Object.setPrototypeOf(CustomWritable.prototype, Writable.prototype);40new CustomWritable();41assert.throws(42 CustomWritable,43 {44 code: 'ERR_ASSERTION',45 constructor: assert.AssertionError,46 message: 'undefined does not inherit from CustomWritable'47 }48);49class OtherCustomWritable extends Writable {}50assert(!(new OtherCustomWritable() instanceof CustomWritable));...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unittest-xml-reporting automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful