skipped 44 lines 45 45 } 46 46 } 47 47 48 + BROKEN_RESULTS = { 49 + 'GitHub': { 50 + 'username': 'test', 51 + 'parsing_enabled': True, 52 + 'url_main': 'https://www.github.com/', 53 + 'url_user': 'https://www.github.com/test', 54 + 'http_status': 200, 55 + 'is_similar': False, 56 + 'rank': 78, 57 + 'site': MaigretSite('test', {}), 58 + } 59 + } 60 + 48 61 GOOD_500PX_RESULT = copy.deepcopy(GOOD_RESULT) 49 62 GOOD_500PX_RESULT.tags = ['photo', 'us', 'global'] 50 63 GOOD_500PX_RESULT.ids_data = { skipped 188 lines 239 252 ] 240 253 241 254 SUPPOSED_BRIEF = """Search by username alexaimephotographycars returned 1 accounts. Found target's other IDs: alexaimephotography, Alexaimephotogr. Search by username alexaimephotography returned 2 accounts. Search by username Alexaimephotogr returned 1 accounts. Extended info extracted from 3 accounts.""" 255 + SUPPOSED_BROKEN_BRIEF = """Search by username alexaimephotographycars returned 0 accounts. Search by username alexaimephotography returned 2 accounts. Search by username Alexaimephotogr returned 1 accounts. Extended info extracted from 2 accounts.""" 256 + 257 + SUPPOSED_GEO = "Geo: us <span class=\"text-muted\">(3)</span>" 258 + SUPPOSED_BROKEN_GEO = "Geo: us <span class=\"text-muted\">(2)</span>" 242 259 243 260 SUPPOSED_INTERESTS = "Interests: photo <span class=\"text-muted\">(2)</span>, news <span class=\"text-muted\">(1)</span>, social <span class=\"text-muted\">(1)</span>" 244 - 245 - SUPPOSED_GEO = "Geo: us <span class=\"text-muted\">(3)</span>" 261 + SUPPOSED_BROKEN_INTERESTS = "Interests: news <span class=\"text-muted\">(1)</span>, photo <span class=\"text-muted\">(1)</span>, social <span class=\"text-muted\">(1)</span>" 246 262 247 263 248 264 def test_generate_report_template(): skipped 21 lines 270 286 ] 271 287 272 288 289 + def test_generate_csv_report_broken(): 290 + csvfile = StringIO() 291 + generate_csv_report('test', BROKEN_RESULTS, csvfile) 292 + 293 + csvfile.seek(0) 294 + data = csvfile.readlines() 295 + 296 + assert data == [ 297 + 'username,name,url_main,url_user,exists,http_status\r\n', 298 + 'test,GitHub,https://www.github.com/,https://www.github.com/test,Unknown,200\r\n', 299 + ] 300 + 301 + 273 302 def test_generate_txt_report(): 274 303 txtfile = StringIO() 275 304 generate_txt_report('test', EXAMPLE_RESULTS, txtfile) skipped 7 lines 283 312 ] 284 313 285 314 315 + def test_generate_txt_report_broken(): 316 + txtfile = StringIO() 317 + generate_txt_report('test', BROKEN_RESULTS, txtfile) 318 + 319 + txtfile.seek(0) 320 + data = txtfile.readlines() 321 + 322 + assert data == [ 323 + 'Total Websites Username Detected On : 0', 324 + ] 325 + 326 + 286 327 def test_generate_json_simple_report(): 287 328 jsonfile = StringIO() 288 329 MODIFIED_RESULTS = dict(EXAMPLE_RESULTS) skipped 7 lines 296 337 assert list(json.loads(data[0]).keys()) == ['GitHub', 'GitHub2'] 297 338 298 339 340 + def test_generate_json_simple_report_broken(): 341 + jsonfile = StringIO() 342 + MODIFIED_RESULTS = dict(BROKEN_RESULTS) 343 + MODIFIED_RESULTS['GitHub2'] = BROKEN_RESULTS['GitHub'] 344 + generate_json_report('test', BROKEN_RESULTS, jsonfile, 'simple') 345 + 346 + jsonfile.seek(0) 347 + data = jsonfile.readlines() 348 + 349 + assert len(data) == 1 350 + assert list(json.loads(data[0]).keys()) == [] 351 + 352 + 299 353 def test_generate_json_ndjson_report(): 300 354 jsonfile = StringIO() 301 355 MODIFIED_RESULTS = dict(EXAMPLE_RESULTS) skipped 27 lines 329 383 ) 330 384 331 385 386 + def test_save_xmind_report_broken(): 387 + filename = 'report_test.xmind' 388 + save_xmind_report(filename, 'test', BROKEN_RESULTS) 389 + 390 + workbook = xmind.load(filename) 391 + sheet = workbook.getPrimarySheet() 392 + data = sheet.getData() 393 + 394 + assert data['title'] == 'test Analysis' 395 + assert data['topic']['title'] == 'test' 396 + assert len(data['topic']['topics']) == 1 397 + assert data['topic']['topics'][0]['title'] == 'Undefined' 398 + 399 + 332 400 def test_html_report(): 333 401 report_name = 'report_test.html' 334 402 context = generate_report_context(TEST) skipped 6 lines 341 409 assert SUPPOSED_INTERESTS in report_text 342 410 343 411 412 + def test_html_report_broken(): 413 + report_name = 'report_test_broken.html' 414 + BROKEN_DATA = copy.deepcopy(TEST) 415 + BROKEN_DATA[0][2]['500px']['status'] = None 416 + 417 + context = generate_report_context(BROKEN_DATA) 418 + save_html_report(report_name, context) 419 + 420 + report_text = open(report_name).read() 421 + 422 + assert SUPPOSED_BROKEN_BRIEF in report_text 423 + assert SUPPOSED_BROKEN_GEO in report_text 424 + assert SUPPOSED_BROKEN_INTERESTS in report_text 425 + 426 + 344 427 def test_pdf_report(): 345 428 report_name = 'report_test.pdf' 346 429 context = generate_report_context(TEST) skipped 11 lines 358 441 assert 'us' in report_text 359 442 assert 'photo' in report_text 360 443 444 + 445 + def test_text_report_broken(): 446 + BROKEN_DATA = copy.deepcopy(TEST) 447 + BROKEN_DATA[0][2]['500px']['status'] = None 448 + 449 + context = generate_report_context(BROKEN_DATA) 450 + report_text = get_plaintext_report(context) 451 + 452 + for brief_part in SUPPOSED_BROKEN_BRIEF.split(): 453 + assert brief_part in report_text 454 + assert 'us' in report_text 455 + assert 'photo' in report_text 456 +