Exemple #1
0
def test_submission_view(app, submission_user):
    submission = create_visual(
        app,
        submission_user,
        submitfile=webtest.Upload('wesley1.png', read_asset('img/wesley1.png'),
                                  'image/png'),
    )
    d.engine.execute(
        'UPDATE submission SET unixtime = 1581092121 WHERE submitid = %(id)s',
        id=submission)

    resp_json = app.get('/api/submissions/%i/view' % (submission, )).json
    media = resp_json.pop('media', None)
    owner_media = resp_json.pop('owner_media', None)

    assert resp_json == {
        'comments': 0,
        'description': '<p>Description</p>\n',
        'embedlink': None,
        'favorited': False,
        'favorites': 0,
        'folderid': None,
        'folder_name': None,
        'friends_only': False,
        'link': 'http://localhost/submission/%i/test-title' % (submission, ),
        'owner': 'submission_test',
        'owner_login': '******',
        'posted_at': '2020-02-07T21:15:21+00:00Z',
        'rating': 'general',
        'submitid': submission,
        'subtype': 'visual',
        'tags': ['bar', 'foo'],
        'title': 'Test title',
        'type': 'submission',
        'views': 1,
    }
    assert set(media) == {
        'thumbnail', 'submission', 'cover', 'thumbnail-generated-webp',
        'thumbnail-generated'
    }
    assert type(media['submission'][0].pop('mediaid')) is int
    assert set(media['submission'][0].pop('links')) == {'cover'}
    assert media['submission'] == [{
        'url':
        'http://localhost/~submissiontest/submissions/%i/ca23760d8ca4bf6c2d721f5b02e389627b6b9181d5f323001f2d5801c086407b/submissiontest-test-title.png'
        % (submission, ),
    }]
    assert owner_media == {
        'avatar': [{
            'mediaid': None,
            'url': 'http://localhost/img/default-avatar-vuOx5v6OBn.jpg',
        }],
    }
Exemple #2
0
def test_rating_accessibility(app, age):
    submission_user = db_utils.create_user(
        'submission_test', birthday=arrow.utcnow().shift(years=-age))
    cookie = db_utils.create_session(submission_user)

    def _post_expecting(form, expected_rating):
        success = expected_rating is not None
        resp = app.post('/submit/visual',
                        form,
                        headers={'Cookie': cookie},
                        status=303 if success else 422)

        if success:
            resp = resp.maybe_follow(headers={'Cookie': cookie})
            assert "Rating: %s" % (expected_rating, ) in resp.html.find(
                id='di-info').dl.text
        else:
            assert resp.html.find(
                id='error_content'
            ).p.text == "The specified rating is invalid."

    form = dict(
        BASE_VISUAL_FORM,
        rating=u'30',
        submitfile=webtest.Upload('wesley1.png', read_asset('img/wesley1.png'),
                                  'image/png'),
    )
    _post_expecting(form, 'Mature' if age >= 18 else None)

    form['submitfile'] = webtest.Upload(
        'wesley-jumpingtext.png',
        read_asset('img/help/wesley-jumpingtext.png'), 'image/png')
    form['rating'] = u'40'
    _post_expecting(form, 'Explicit' if age >= 18 else None)

    form['submitfile'] = webtest.Upload('wesley-draw.png',
                                        read_asset('img/help/wesley-draw.png'),
                                        'image/png')
    form['rating'] = u'10'
    _post_expecting(form, 'General')
Exemple #3
0
def _character(app, db, character_user, no_csrf):
    cookie = db_utils.create_session(character_user)

    form = dict(
        _BASE_FORM,
        submitfile=webtest.Upload('wesley', read_asset('img/wesley1.png'),
                                  'image/png'),
    )

    resp = app.post('/submit/character', form, headers={
        'Cookie': cookie
    }).follow(headers={'Cookie': cookie})
    charid = int(resp.html.find('input', {'name': 'charid'})['value'])

    return charid
Exemple #4
0
def test_gif_thumbnail_static(app, submission_user):
    create_visual(
        app,
        submission_user,
        submitfile=webtest.Upload('loader.gif', read_asset('img/loader.gif'),
                                  'image/gif'),
    )

    [thumb_compat
     ] = app.get('/~submissiontest').html.select('#user-thumbs img')
    assert thumb_compat['src'].endswith('.jpg')

    [thumb
     ] = app.get('/~submissiontest').html.select('#user-thumbs .thumb-bounds')
    assert thumb.picture is not None
    assert thumb.picture.source['srcset'].endswith('.webp')
Exemple #5
0
def test_owner_reupload(app, character_user, character):
    cookie = db_utils.create_session(character_user)

    resp = app.post('/reupload/character', {
        'targetid':
        str(character),
        'submitfile':
        webtest.Upload('wesley', read_asset('img/help/wesley-draw.png'),
                       'image/png'),
    },
                    headers={
                        'Cookie': cookie
                    }).follow()

    image_url = resp.html.find(id='detail-art').a['href']
    assert _read_character_image(image_url).tobytes() == read_asset_image(
        'img/help/wesley-draw.png').tobytes()
Exemple #6
0
def test_animated_gif_and_clear(app, submission_user):
    app.set_cookie(*db_utils.create_session(submission_user).split("=", 1))

    form = app.get('/manage/avatar').forms['upload-avatar']
    form['image'] = Upload('loader.gif', read_asset('img/loader.gif'),
                           'image/gif')
    resp = form.submit().follow()
    resp = resp.forms['manage-avatar'].submit().follow()
    avatar_url = resp.html.find(id='avatar')['src']

    with Image.open(get_storage_path(avatar_url)) as avatar:
        assert avatar.n_frames == 12
        assert avatar.size == (100, 100)

    form = app.get('/manage/avatar').forms['upload-avatar']
    form['image'] = None
    resp = form.submit().follow()
    avatar_url = resp.html.find(id='avatar')['src']

    assert avatar_url.startswith('/img/default-avatar-')
Exemple #7
0
def test_crosspost(app, submission_user, monkeypatch):
    monkeypatch.setattr(submission, '_ALLOWED_CROSSPOST_HOST',
                        re.compile(r'\Alocalhost:[0-9]+\Z'))

    crosspost_test_server = HTTPServer(('127.0.0.1', 0), CrosspostHandler)
    image_url = 'http://localhost:%i/wesley1.png' % (
        crosspost_test_server.server_port, )

    test_server_thread = threading.Thread(
        target=crosspost_test_server.serve_forever,
        kwargs={'poll_interval': 0.1},
    )
    test_server_thread.start()

    # Crossposting from a supported source works
    try:
        v1 = create_visual(app, submission_user, imageURL=image_url)
    finally:
        crosspost_test_server.shutdown()
        test_server_thread.join()

    v1_image_url = app.get('/~submissiontest/submissions/%i/test-title' %
                           (v1, )).html.find(id='detail-art').img['src']

    assert open(get_storage_path(v1_image_url),
                'rb').read() == read_asset('img/wesley1.png')

    # Crossposting from an unsupported source doesn’t work
    form = dict(
        BASE_VISUAL_FORM,
        imageURL='http://test.invalid/wesley1.png',
    )
    cookie = db_utils.create_session(submission_user)
    resp = app.post('/submit/visual',
                    form,
                    headers={'Cookie': cookie},
                    status=422)
    assert resp.html.find(
        id='error_content'
    ).p.text == 'The image you crossposted was from an unsupported source. Please report this bug to the creator of the crossposting tool.'
Exemple #8
0
 def do_GET(self):
     self.send_response(200)
     self.send_header('Content-Type', 'image/png')
     self.end_headers()
     self.wfile.write(read_asset('img/wesley1.png'))