예제 #1
0
def test_Submission_gets_success_and_not_all_expected_keys():
    expected_keys = {'filename': 'Foo.jpg',
                     'filepath': 'path/to/Foo.jpg',
                     'image_url': 'https://foo.bar/asdf.jpg',
                     'thumbnail_url': 'https://foo.bar/asdf_t.jpg',
                     'web_url': 'https://foo.bar/asdf',
                     'gallery_url': 'https://foo.bar/fdsa',
                     'edit_url': 'https://foo.bar/fdsa/edit'}
    for k in expected_keys:
        with pytest.raises(AssertionError, match=rf"^Missing key: '{k}'$"):
            keys = expected_keys.copy()
            del keys[k]
            _upload.Submission(success=True, **keys)
예제 #2
0
def test_Submission_gets_valid_error_arguments():
    assert _upload.Submission(
        success=False,
        error='Trouble is afoot!',
    ) == {'success': False,
          'error': 'Trouble is afoot!',
          'filename': None,
          'filepath': None,
          'image_url': None,
          'thumbnail_url': None,
          'web_url': None,
          'gallery_url': None,
          'edit_url': None}
예제 #3
0
def test_Submission_gets_valid_success_arguments():
    assert _upload.Submission(
        success=True,
        filename='Foo.jpg',
        filepath='path/to/Foo.jpg',
        image_url='https://foo.bar/asdf.jpg',
        thumbnail_url='https://foo.bar/asdf_t.jpg',
        web_url='https://foo.bar/asdf',
        gallery_url='https://foo.bar/fdsa',
        edit_url='https://foo.bar/fdsa/edit'
    ) == {'success': True,
          'error': None,
          'filename': 'Foo.jpg',
          'filepath': 'path/to/Foo.jpg',
          'image_url': 'https://foo.bar/asdf.jpg',
          'thumbnail_url': 'https://foo.bar/asdf_t.jpg',
          'web_url': 'https://foo.bar/asdf',
          'gallery_url': 'https://foo.bar/fdsa',
          'edit_url': 'https://foo.bar/fdsa/edit'}
예제 #4
0
def test_Gallery_submit_file_succeeds(mock_post_json):
    gallery = _upload.Gallery()
    mock_token = {'token_id': '123', 'token_secret': '456',
                  'gallery_id': 'abc', 'gallery_secret': 'def'}
    gallery._token = mock_token
    mock_post_json.return_value = {'files': [{'original_url': 'https://foo.example.org/asdf.jpg',
                                              'thumbnail_url': 'https://foo.example.org/asdf_t.jpg',
                                              'url': 'https://foo.example.org/asdf'}]}
    sub = gallery._submit_file('path/to/file.jpg',
                               content_type=_const.CONTENT_TYPES['adult'],
                               thumbnail_size=_const.THUMBNAIL_WIDTHS_SQUARE[300],
                               timeout=12)
    assert sub == _upload.Submission(
        success=True,
        filename='file.jpg',
        filepath='path/to/file.jpg',
        image_url='https://foo.example.org/asdf.jpg',
        thumbnail_url='https://foo.example.org/asdf_t.jpg',
        web_url='https://foo.example.org/asdf',
        gallery_url=_const.GALLERY_URL_FORMAT.format(**mock_token),
        edit_url=_const.EDIT_URL_FORMAT.format(**mock_token),
    )
예제 #5
0
def test_Submission_needs_success_key():
    with pytest.raises(TypeError, match=r"required keyword-only argument: 'success'$"):
        _upload.Submission(x='y')
예제 #6
0
def test_Submission_gets_conflicting_success_and_error():
    with pytest.raises(AssertionError, match=r"^Conflicting keys: 'error', 'success'$"):
        _upload.Submission(success=True, error='Huh?')
예제 #7
0
def test_Submission_gets_failure_and_no_error():
    with pytest.raises(AssertionError, match=r"^Missing key: 'error'$"):
        _upload.Submission(success=False, filename='foo')
예제 #8
0
def test_Submission_gets_unknown_key():
    with pytest.raises(AssertionError, match=r"^Unknown key: 'x'$"):
        _upload.Submission(success=False, x='y')