Skip to content

Commit

Permalink
Merge 16ea750 into bd6d97e
Browse files Browse the repository at this point in the history
  • Loading branch information
phlax committed Apr 4, 2018
2 parents bd6d97e + 16ea750 commit 9956af7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
dist: trusty
sudo: false
language: python
addons:
hosts:
- redis
env:
- TOXENV=py27-django110-sqlite PYTHONPATH=$HOME/virtualenv/python2.7.14/lib/python2.7/site-packages TOX_TESTENV_PASSENV="PYTHONPATH"
- TOXENV=py27-django110-mysql PYTHONPATH=$HOME/virtualenv/python2.7.14/lib/python2.7/site-packages TOX_TESTENV_PASSENV="PYTHONPATH"
Expand Down
2 changes: 2 additions & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pytest==3.2.2
pytest-catchlog==1.2.2
pytest-cov==2.5.1
pytest-django==3.1.2

pytest-mock
6 changes: 2 additions & 4 deletions tests/pootle_fs/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def test_fs_response_display_instance(localfs_pootle_untracked):
assert str(display) == "%s\n" % result


@pytest.mark.django_db
def test_fs_response_display_no_change(localfs_pootle_untracked):
plugin = localfs_pootle_untracked
assert str(ResponseDisplay(plugin.sync())) == "No changes made\n"
def test_fs_response_display_no_change():
assert str(ResponseDisplay([])) == "No changes made\n"


@pytest.mark.django_db
Expand Down
64 changes: 33 additions & 31 deletions tests/pootle_fs/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

import os

from mock import PropertyMock, patch

import pytest

from translate.storage.factory import getclass
from translate.storage.po import pofile

from django.contrib.auth import get_user_model

from pootle_fs.models import StoreFS

from pootle_fs.files import FSFile
Expand Down Expand Up @@ -346,42 +350,40 @@ def test_wrap_store_fs_pull_submission_type(store_fs_file_store):
== SubmissionTypes.SYSTEM)


@pytest.mark.django_db
def test_fs_file_latest_author(system, member2):

member2.email = "member2@poot.le"
member2.save()
@patch("pootle_fs.files.FSFile.latest_author", new_callable=PropertyMock)
@patch("pootle_fs.files.FSFile.plugin", new_callable=PropertyMock)
@patch("pootle_fs.files.User.objects", new_callable=PropertyMock)
def test_fs_file_latest_author(user_mock, plugin_mock, author_mock):
user_mock.configure_mock(
**{"return_value.get.return_value": 73})
author_mock.return_value = None, None
plugin_mock.configure_mock(
**{"return_value.pootle_user": 23})

class DummyPlugin(object):
pootle_user = system
User = get_user_model()

class DummyFile(FSFile):

_author_name = None
_author_email = None

def __init__(self):
pass

@property
def plugin(self):
return DummyPlugin()
myfile = DummyFile()
assert myfile.latest_user == 23

@property
def latest_author(self):
return self._author_name, self._author_email
author_mock.return_value = 7, None
assert myfile.latest_user == 23
author_mock.return_value = None, 7
assert myfile.latest_user == 23

myfile = DummyFile()
assert myfile.latest_user == system
myfile._author_name = "DOES NOT EXIST"
assert myfile.latest_user == system
myfile._author_email = member2.email
assert myfile.latest_user == member2
myfile._author_name = member2.username
assert myfile.latest_user == member2
myfile._author_email = None
assert myfile.latest_user == system
myfile._author_email = "DOESNT@EXIST.EMAIL"
assert myfile.latest_user == member2
myfile._author_name = "DOES NOT EXIST"
assert myfile.latest_user == system
author_mock.return_value = 7, 17
assert myfile.latest_user == 73
assert (
list(user_mock.return_value.get.call_args)
== [(), {'email': 17}])

user_mock.return_value.get.side_effect = User.DoesNotExist
assert myfile.latest_user == 23
assert (
[list(l) for l in user_mock.return_value.get.call_args_list]
== [[(), {'email': 17}],
[(), {'email': 17}],
[(), {'username': 7}]])
2 changes: 0 additions & 2 deletions tests/pootle_fs/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pootle_fs.localfs import LocalFSPlugin, LocalFSUrlValidator


@pytest.mark.django_db
def test_validator_localfs():
validator = fs_url_validator.get(LocalFSPlugin)()
assert isinstance(validator, LocalFSUrlValidator)
Expand All @@ -24,7 +23,6 @@ def test_validator_localfs():
validator.validate("/foo/bar")


@pytest.mark.django_db
def test_validator_translation_mapping():
validator = fs_translation_mapping_validator.get()("asdf")
assert isinstance(validator, TranslationMappingValidator)
6 changes: 3 additions & 3 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@
# place that will abort everything otherwise
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/13',
'LOCATION': 'redis://redis:6379/13',
'TIMEOUT': 604800, # 1 week
},
'redis': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/14',
'LOCATION': 'redis://redis:6379/14',
'TIMEOUT': None,
},
'lru': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/15',
'LOCATION': 'redis://redis:6379/15',
'TIMEOUT': 604800, # 1 week
},
'exports': {
Expand Down

0 comments on commit 9956af7

Please sign in to comment.