| 23 | |
| 24 | @patch("aura.typos.get_all_pypi_packages") |
| 25 | def disable_test_typosquatting_generator(mock, tmp_path, mock_pypi_stats): # FIXME |
| 26 | stats: Path = tmp_path / "pypi_stats.json" |
| 27 | stats.write_text("\n".join(json.dumps(x) for x in config.iter_pypi_stats())) |
| 28 | os.environ["AURA_PYPI_STATS"] = str(stats) |
| 29 | try: |
| 30 | mock.return_value = [ |
| 31 | 'requests', |
| 32 | 'requestes', |
| 33 | 'requests2', |
| 34 | 'requests3', |
| 35 | 'request', |
| 36 | 'grequest', |
| 37 | ] |
| 38 | |
| 39 | runner = CliRunner(mix_stderr=False) |
| 40 | result = runner.invoke( |
| 41 | cli.cli, |
| 42 | ['find-typosquatting', '--limit', '10', '-f', 'json'], |
| 43 | ) |
| 44 | if result.exception: |
| 45 | raise result.exception |
| 46 | |
| 47 | line_count = 0 |
| 48 | for line in result.output.split('\n'): |
| 49 | if not line.strip(): |
| 50 | continue |
| 51 | line_count += 1 |
| 52 | entry = json.loads(line) |
| 53 | assert len(entry.keys()) == 2 |
| 54 | assert 'original' in entry |
| 55 | assert 'typosquatting' in entry |
| 56 | |
| 57 | assert line_count > 0 and line_count <= 10 |
| 58 | finally: |
| 59 | del os.environ["AURA_PYPI_STATS"] |
| 60 | |
| 61 | |
| 62 | @pytest.mark.parametrize( |