Пример #1
0
def test_notebook_view_old_revision(client, test_notebook):
    initial_revision = NotebookRevision.objects.filter(
        notebook=test_notebook).last()
    new_revision_content = "My new fun content"
    NotebookRevision.objects.create(content=new_revision_content,
                                    notebook=test_notebook,
                                    title="Second revision")
    resp = client.get(
        reverse("notebook-view", args=[str(test_notebook.id)]) +
        f"?revision={initial_revision.id}")
    assert resp.status_code == 200
    assert get_title_block(resp.content) == initial_revision.title
    print(str(resp.content))
    assert get_script_block(resp.content, "iomd",
                            "text/iomd") == initial_revision.content
    assert get_script_block_json(resp.content, "notebookInfo") == {
        "connectionMode": "SERVER",
        "files": [],
        "forked_from": False,
        "notebook_id": test_notebook.id,
        "revision_id": initial_revision.id,
        "revision_is_latest": False,
        "title": "First revision",
        "user_can_save": False,
        "username": "******",
        "max_filename_length": MAX_FILENAME_LENGTH,
        "max_file_size": MAX_FILE_SIZE,
    }
Пример #2
0
def test_user_view_with_different_names(transactional_db, client, username,
                                        first_name, last_name):
    test_user = User.objects.create(
        username=username,
        first_name=first_name,
        last_name=last_name,
        email="*****@*****.**",
        password="******",
    )
    notebook = Notebook.objects.create(owner=test_user, title="Fake notebook")
    revision = NotebookRevision.objects.create(
        notebook=notebook,
        title="First revision",
        content="*fake notebook content*")
    resp = client.get(reverse("user", kwargs={"name": test_user.username}))
    assert resp.status_code == 200
    if test_user.get_full_name():
        assert (get_title_block(resp.content) ==
                f"{test_user.username} ({test_user.get_full_name()})")
    else:
        assert get_title_block(resp.content) == f"{test_user.username}"

    assert get_script_block(resp.content, "pageData") == {
        "notebookList": [{
            "id": notebook.id,
            "last_revision": revision.created.isoformat(),
            "title": revision.title,
        }],
        "thisUser": {
            "avatar": None,
            "full_name": test_user.get_full_name(),
            "name": username
        },
        "userInfo": {},
    }
Пример #3
0
def test_user_view_with_different_names(transactional_db, client, username):
    test_user = User.objects.create(username=username,
                                    first_name="User",
                                    last_name="McUsertons",
                                    email="*****@*****.**",
                                    password="******")
    notebook = Notebook.objects.create(owner=test_user, title='Fake notebook')
    revision = NotebookRevision.objects.create(
        notebook=notebook,
        title="First revision",
        content="*fake notebook content*")
    resp = client.get(reverse('user', kwargs={'name': test_user.username}))
    assert resp.status_code == 200
    assert get_script_block(resp.content, 'pageData') == {
        'notebookList': [{
            'id': notebook.id,
            'last_revision': revision.created.isoformat(),
            'title': revision.title
        }],
        'thisUser': {
            'avatar': None,
            'full_name': test_user.get_full_name(),
            'name': username
        },
        'userInfo': {}
    }
Пример #4
0
def test_user_view_github(settings, transactional_db, client, fake_user):
    settings.SOCIAL_AUTH_GITHUB_KEY = "yabbadabbadoo"
    resp = client.get(reverse("user", kwargs={"name": fake_user.username}))
    assert resp.status_code == 200
    assert get_script_block(resp.content, "pageData") == {
        "notebookList": [],
        "thisUser": {
            "avatar": None,
            "full_name": fake_user.get_full_name(),
            "name": fake_user.username,
            "github_url": "https://github.com/{}/".format(fake_user.username),
        },
        "userInfo": {},
    }
Пример #5
0
def test_index_view(client, two_test_notebooks, fake_user, logged_in):
    if logged_in:
        client.force_login(fake_user)
    resp = client.get(reverse("index"))
    assert resp.status_code == 200

    # if user logged in, they should have an avatar defined
    fake_user.refresh_from_db()
    if logged_in:
        assert fake_user.avatar.startswith("http://www.gravatar.com/avatar/")
    else:
        assert fake_user.avatar is None

    # assert that the pageData element has the expected structure
    assert get_title_block(resp.content) == "Iodide"
    assert get_script_block(resp.content, "pageData") == {
        "notebookList": [{
            "avatar":
            fake_user.avatar,
            "id":
            test_notebook.id,
            "latestRevision": (NotebookRevision.objects.get(
                notebook=test_notebook).created.isoformat()),
            "owner":
            test_notebook.owner.username,
            "title":
            test_notebook.title,
        } for test_notebook in reversed(two_test_notebooks)],
        "userInfo": {
            "name":
            fake_user.username,
            "avatar":
            "http://www.gravatar.com/avatar/eaee5961bc7ad96538a4933cb069fda9?d=identicon",
            "notebooks": [{
                "id":
                test_notebook.id,
                "latestRevision": (NotebookRevision.objects.get(
                    notebook=test_notebook).created.isoformat()),
                "title":
                test_notebook.title,
            } for test_notebook in reversed(two_test_notebooks)],
        } if logged_in else {},
    }
Пример #6
0
def test_index_view(client, two_test_notebooks, fake_user, logged_in):
    if logged_in:
        client.force_login(fake_user)
    resp = client.get(reverse('index'))
    assert resp.status_code == 200

    # if user logged in, they should have an avatar defined
    fake_user.refresh_from_db()
    if logged_in:
        assert fake_user.avatar.startswith('http://www.gravatar.com/avatar/')
    else:
        assert fake_user.avatar is None

    # assert that the pageData element has the expected structure
    assert get_script_block(resp.content, 'pageData') == {
        'notebookList': [{
            'avatar':
            fake_user.avatar,
            'id':
            test_notebook.id,
            'latestRevision': (NotebookRevision.objects.get(
                notebook=test_notebook).created.isoformat()),
            'owner':
            test_notebook.owner.username,
            'title':
            test_notebook.title
        } for test_notebook in reversed(two_test_notebooks)],
        'userInfo': {
            'name':
            fake_user.username,
            'avatar':
            'http://www.gravatar.com/avatar/eaee5961bc7ad96538a4933cb069fda9?d=identicon',
            'notebooks': [{
                'id':
                test_notebook.id,
                'latestRevision': (NotebookRevision.objects.get(
                    notebook=test_notebook).created.isoformat()),
                'title':
                test_notebook.title
            } for test_notebook in reversed(two_test_notebooks)]
        } if logged_in else {}
    }