|
| 1 | +import pytest |
| 2 | +import scaleapi |
| 3 | +import os |
| 4 | + |
| 5 | +try: |
| 6 | + test_api_key = os.environ['SCALE_TEST_API_KEY'] |
| 7 | + client = scaleapi.ScaleClient(test_api_key) |
| 8 | +except KeyError: |
| 9 | + raise Exception("Please set the environment variable SCALE_TEST_API_KEY to run tests.") |
| 10 | + |
| 11 | + |
| 12 | +def test_categorize_ok(): |
| 13 | + task = client.create_categorization_task( |
| 14 | + callback_url='http://www.example.com/callback', |
| 15 | + instruction='Is this company public or private?', |
| 16 | + attachment_type='website', |
| 17 | + attachment='http://www.google.com/', |
| 18 | + categories=['public', 'private']) |
| 19 | + |
| 20 | + |
| 21 | +def test_categorize_fail(): |
| 22 | + with pytest.raises(scaleapi.ScaleInvalidRequest): |
| 23 | + client.create_categorization_task( |
| 24 | + callback_url='http://www.example.com/callback', |
| 25 | + categories=['public', 'private']) |
| 26 | + |
| 27 | + |
| 28 | +def test_transcrption_ok(): |
| 29 | + task = client.create_transcription_task( |
| 30 | + callback_url='http://www.example.com/callback', |
| 31 | + instruction='Transcribe the given fields. Then for each news item on the page, transcribe the information for the row.', |
| 32 | + attachment_type='website', |
| 33 | + attachment='http://www.google.com/', |
| 34 | + fields={ |
| 35 | + 'title': 'Title of Webpage', |
| 36 | + 'top_result': 'Title of the top result' |
| 37 | + }, |
| 38 | + row_fields={ |
| 39 | + 'username': 'Username of submitter', |
| 40 | + 'comment_count': 'Number of comments' |
| 41 | + }) |
| 42 | + |
| 43 | + |
| 44 | +def test_transcription_fail(): |
| 45 | + with pytest.raises(scaleapi.ScaleInvalidRequest): |
| 46 | + client.create_transcription_task( |
| 47 | + callback_url='http://www.example.com/callback', |
| 48 | + attachment_type='website') |
| 49 | + |
| 50 | + |
| 51 | +def test_phonecall_ok(): |
| 52 | + task = client.create_phonecall_task( |
| 53 | + callback_url='http://www.example.com/callback', |
| 54 | + instruction='Call this person and follow the script provided, recording responses', |
| 55 | + phone_number='5055006865', |
| 56 | + entity_name='Alexandr Wang', |
| 57 | + script='Hello ! Are you happy today? (pause) One more thing - what is your email address?', |
| 58 | + fields={'email': 'Email Address'}, |
| 59 | + choices=['He is happy', 'He is not happy']) |
| 60 | + |
| 61 | + |
| 62 | +def test_phonecall_fail(): |
| 63 | + with pytest.raises(scaleapi.ScaleInvalidRequest): |
| 64 | + client.create_phonecall_task( |
| 65 | + callback_url='http://www.example.com/callback', |
| 66 | + instruction='Call this person and follow the script provided, recording responses') |
| 67 | + |
| 68 | + |
| 69 | +def test_comparison_ok(): |
| 70 | + task = client.create_comparison_task( |
| 71 | + callback_url='http://www.example.com/callback', |
| 72 | + instruction='Do the objects in these images have the same pattern?', |
| 73 | + attachment_type='image', |
| 74 | + attachments=[ |
| 75 | + 'http://i.ebayimg.com/00/$T2eC16dHJGwFFZKjy5ZjBRfNyMC4Ig~~_32.JPG', |
| 76 | + 'http://images.wisegeek.com/checkered-tablecloth.jpg' |
| 77 | + ], |
| 78 | + choices=['yes', 'no']) |
| 79 | + |
| 80 | + |
| 81 | +def test_comparison_fail(): |
| 82 | + with pytest.raises(scaleapi.ScaleInvalidRequest): |
| 83 | + client.create_comparison_task( |
| 84 | + callback_url='http://www.example.com/callback', |
| 85 | + instruction='Do the objects in these images have the same pattern?', |
| 86 | + attachment_type='image') |
| 87 | + |
| 88 | + |
| 89 | +def test_annotation_ok(): |
| 90 | + task = client.create_annotation_task( |
| 91 | + callback_url='http://www.example.com/callback', |
| 92 | + instruction='Draw a box around each **baby cow** and **big cow**', |
| 93 | + attachment_type='image', |
| 94 | + attachment='http://i.imgur.com/v4cBreD.jpg', |
| 95 | + objects_to_annotate=['baby cow', 'big cow'], |
| 96 | + with_labels=True) |
| 97 | + |
| 98 | + |
| 99 | +def test_annotation_fail(): |
| 100 | + with pytest.raises(scaleapi.ScaleInvalidRequest): |
| 101 | + client.create_annotation_task( |
| 102 | + callback_url='http://www.example.com/callback', |
| 103 | + instruction='Draw a box around each **baby cow** and **big cow**', |
| 104 | + attachment_type='image') |
| 105 | + |
| 106 | + |
| 107 | +def test_cancel(): |
| 108 | + task = client.create_annotation_task( |
| 109 | + callback_url='http://www.example.com/callback', |
| 110 | + instruction='Draw a box around each **baby cow** and **big cow**', |
| 111 | + attachment_type='image', |
| 112 | + attachment='http://i.imgur.com/v4cBreD.jpg', |
| 113 | + objects_to_annotate=['baby cow', 'big cow'], |
| 114 | + with_labels=True) |
| 115 | + |
| 116 | + # raises a scaleexception, because test tasks complete instantly |
| 117 | + with pytest.raises(scaleapi.ScaleException): |
| 118 | + task.cancel() |
0 commit comments