Skip to content

Commit

Permalink
NXDRIVE-1715: Move more DirectEdit tests from old_functional to funct…
Browse files Browse the repository at this point in the history
…ional

* Moved test_url_missing_username() to test_handle_url_missing_username();
* Merged test_user_name() into test_binder().
  • Loading branch information
Mickaël Schoentgen authored and BoboTiG committed Jun 17, 2019
1 parent a47f6c3 commit dae85ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
3 changes: 3 additions & 0 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def _make_manager(home: str = "", with_engine: bool = True):
conf_folder, nuxeo_url, user.uid, user.password, start_engine=False
)

# Let the possibility to access user's attributes from the manager
manager.user_details = user

engine = None
for uid, engine_ in manager.get_engines().items():
engine = engine_
Expand Down
30 changes: 30 additions & 0 deletions tests/functional/test_direct_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def __init__(self, url: str, user: str):
self._invalid_credentials = False

def get_binder(self):
"""
Must redefine to prevent:
RuntimeError: super-class __init__() of type MockUrlTestEngine was never called
"""
return ServerBindingSettings(self._url, None, self._user, ROOT, True)


Expand All @@ -29,6 +33,7 @@ def direct_edit(manager_factory):


def test_binder(manager_factory):
"""Also test username retrieval."""
manager, engine = manager_factory()

with manager:
Expand All @@ -42,6 +47,17 @@ def test_binder(manager_factory):
assert binder.initialized
assert binder.local_folder

# Test user name retrieval
full_username = (
f"{manager.user_details.firstName} {manager.user_details.lastName}"
)
username = engine.get_user_full_name(binder.username)
assert username == full_username

# Test unknown user name retrieval
username = engine.get_user_full_name("unknown")
assert username == "unknown"


def test_cleanup_no_local_folder(direct_edit):
"""If local folder does not exist, it should be created."""
Expand Down Expand Up @@ -110,6 +126,20 @@ def test_handle_url_malformed(direct_edit):
assert not direct_edit.handle_url("https://example.org")


def test_handle_url_missing_username(direct_edit):
""" The username must be in the URL. """
url = (
"nxdrive://edit/https/server.cloud.nuxeo.com/nuxeo"
"/repo/default"
"/nxdocid/xxxxxxxx-xxxx-xxxx-xxxx"
"/filename/lebron-james-beats-by-dre-powerb.psd"
"/downloadUrl/nxfile/default/xxxxxxxx-xxxx-xxxx-xxxx"
"/file:content/lebron-james-beats-by-dre-powerb.psd"
)
with pytest.raises(ValueError):
direct_edit.handle_url(url)


def test_invalid_credentials(manager_factory):
"""Opening a document without being authenticated is not allowed."""

Expand Down
42 changes: 0 additions & 42 deletions tests/old_functional/test_direct_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import pytest
from unittest.mock import patch
from nuxeo.exceptions import HTTPError
from nuxeo.models import User

from nxdrive.exceptions import (
DocumentAlreadyLocked,
Expand Down Expand Up @@ -437,46 +435,6 @@ def test_url_with_accents(self):

self._direct_edit_update(doc_id, filename, b"Test", url=url)

def test_url_missing_username(self):
""" The username must be in the URL. """
url = (
"nxdrive://edit/https/server.cloud.nuxeo.com/nuxeo"
"/repo/default"
"/nxdocid/xxxxxxxx-xxxx-xxxx-xxxx"
"/filename/lebron-james-beats-by-dre-powerb.psd"
"/downloadUrl/nxfile/default/xxxxxxxx-xxxx-xxxx-xxxx"
"/file:content/lebron-james-beats-by-dre-powerb.psd"
)
with pytest.raises(ValueError):
self._direct_edit_update("", "", b"", url=url)

def test_user_name(self):
# Create a complete user
remote = self.root_remote
try:
user = remote.users.create(
User(
properties={
"username": "john",
"firstName": "John",
"lastName": "Doe",
}
)
)
except HTTPError as exc:
assert exc.status != 409
user = remote.users.get("john")

try:
username = self.engine_1.get_user_full_name("john")
assert username == "John Doe"
finally:
user.delete()

# Unknown user
username = self.engine_1.get_user_full_name("unknown")
assert username == "unknown"

def test_double_lock_same_user(self):
filename = "Mode opératoire¹.txt"
uid = self.remote.make_file("/", filename, content=b"Some content.")
Expand Down

0 comments on commit dae85ed

Please sign in to comment.