def test_pinboard_with_note(session, test_user): runner = CliRunner() json_path = path.join(test_data_path, "pinboard-note.json") result = runner.invoke( sut.pinboard_import, [str(test_user.user_uuid), json_path], catch_exceptions=False, ) assert result.exit_code == 0 expected_url = sut.URL.from_string( "http://notes.pinboard.in/u:calpaterson/abc123") bookmark = sut.get_bookmark_by_url(sut.db.session, test_user.user_uuid, expected_url.to_string()) creation_dt = datetime(2011, 12, 13, 11, 38, 4, tzinfo=timezone.utc) assert bookmark == sut.Bookmark( url=expected_url, title="Secret Password", created=creation_dt, description="", updated=datetime(2018, 1, 3, tzinfo=timezone.utc), unread=False, deleted=False, tag_triples=frozenset([("london", creation_dt, False)]), )
def test_pinboard_bookmark(session, test_user): runner = CliRunner() json_path = path.join(test_data_path, "pinboard-bookmark.json") result = runner.invoke( sut.pinboard_import, [str(test_user.user_uuid), json_path], catch_exceptions=False, ) assert result.exit_code == 0 expected_url = sut.URL.from_string( "https://mitpress.mit.edu/books/" "building-successful-online-communities") bookmark = sut.get_bookmark_by_url(sut.db.session, test_user.user_uuid, expected_url.to_string()) creation_dt = datetime(2019, 12, 18, 16, 51, 31, tzinfo=timezone.utc) assert bookmark == sut.Bookmark( url=expected_url, title="Building Successful Online Communities | The MIT Press", description= "<blockquote>How insights from the social sciences, including social psychology and economics, can improve the design of online communities.\n Online communities are among the most popular destinations on the Internet, but not all online communities are equally successful. For every flourishing Facebook, there is a moribund Friendster—not to mention the scores of smaller social networking sites that never attracted enough members to be viable. This book offers lessons from theory an...", created=creation_dt, updated=datetime(2018, 1, 3, tzinfo=timezone.utc), unread=True, deleted=False, tag_triples=frozenset((t, creation_dt, False) for t in [ "mitpress", "online", "sociology", ]), )
def test_creating_a_bookmark(test_user, signed_in_client, session, unread, tags): url = sut.URL.from_string("http://example.com/" + random_string()) form_data = dict( url=url.to_string(), title="Example", description="Example description", tags=",".join(tags), ) if unread: form_data["unread"] = "on" response = signed_in_client.post( flask.url_for("quarchive.create_bookmark", username=test_user.username), data=form_data, ) assert response.status_code == 303 bookmark = sut.get_bookmark_by_url(session, test_user.user_uuid, url.to_string()) assert bookmark is not None assert response.headers["Location"].endswith( flask.url_for( "quarchive.edit_bookmark_form", url_uuid=str(bookmark.url.url_uuid), username=test_user.username, )) assert bookmark.title == form_data["title"] assert bookmark.description == form_data["description"] assert bookmark.unread == unread assert (bookmark.created == bookmark.updated == datetime( 2018, 1, 3, tzinfo=timezone.utc)) assert bookmark.current_tags() == tags
def test_syncing_with_an_extension_that_doesnt_know_about_tags( client, session, test_user): """This test checks that syncs from extensions that don't know about tags don't clober existing tags.""" url = sut.URL.from_string("http://example/com/1") bm_1 = make_bookmark(url=url, title="Example 1") initial_sync = post_bookmarks(client, test_user, [bm_1]) assert initial_sync.status_code == 200 bm_1_no_tags = sut.Bookmark( url=url, title=bm_1.title, description=bm_1.description, created=bm_1.created, updated=bm_1.updated, unread=bm_1.unread, deleted=bm_1.deleted, tag_triples=frozenset(), ) second_sync = post_bookmarks(client, test_user, [bm_1_no_tags]) assert second_sync.status_code == 200 end_state = sut.get_bookmark_by_url(session, test_user.user_uuid, url.to_string()) assert end_state == bm_1
def test_pinboard_uses_merge(session, tmpdir, test_user): runner = CliRunner() existing_bookmark = make_bookmark( created=datetime(2018, 2, 1, tzinfo=timezone.utc), updated=datetime(2018, 2, 1, tzinfo=timezone.utc), description="as of 2018-02", ) sut.set_bookmark(session, test_user.user_uuid, existing_bookmark) session.commit() pinboard_bookmarks = [ dict( href=existing_bookmark.url.to_string(), extended="", description="as of 2018-01-01", time=datetime(2018, 1, 12, tzinfo=timezone.utc).isoformat(), toread=False, deleted=False, ) ] json_path = tmpdir.join("pinboard.json") with open(str(json_path), "w") as json_file: json.dump(pinboard_bookmarks, json_file) runner.invoke( sut.pinboard_import, [str(test_user.user_uuid), str(json_path), "--as-of", "2018-01-01"], catch_exceptions=False, ) url_uuid = existing_bookmark.url.url_uuid assert ( session.query(sut.SQLABookmark) .filter(sut.SQLABookmark.url_uuid == url_uuid) .count() == 1 ) final_bookmark = sut.get_bookmark_by_url( session, test_user.user_uuid, existing_bookmark.url.to_string() ) assert final_bookmark is not None assert final_bookmark.created == datetime(2018, 1, 12, tzinfo=timezone.utc) assert final_bookmark.updated == datetime(2018, 2, 1, tzinfo=timezone.utc)
def test_editing_a_bookmark( signed_in_client, session, test_user, obj_attr, form_attr, obj_start, form_value, obj_end, ): """Submits the edit bookmark form with varying arguments.""" bm_args = {obj_attr: obj_start} bm = make_bookmark(**bm_args) sync_bookmarks(signed_in_client, test_user, [bm]) url_uuid = bm.url.url_uuid form_data = { "title": bm.title, "description": bm.description, "tags": "", # "unread": False and "deleted": False are by default } if form_value is not None: form_data[form_attr] = form_value response = signed_in_client.post( flask.url_for( "quarchive.edit_bookmark", url_uuid=url_uuid, username=test_user.username, redirect_to="/test_location", ), data=form_data, ) assert response.status_code == 303 assert response.headers["Location"] == "http://localhost/test_location" bookmark_obj = sut.get_bookmark_by_url(session, test_user.user_uuid, bm.url.to_string()) assert getattr(bookmark_obj, obj_attr) == obj_end