def test_duedate_delete_project_propagates(): """Tests due date deletion at the project level propagate to existing due dates that point to the same resource across languages. """ project_code = "project0" store_path = "/projects/%s/store0.po" % project_code DueDateFactory.create(pootle_path=store_path, ) project_path = "/projects/%s/" % project_code due_date = DueDateFactory.create(pootle_path=project_path, ) tp_due_dates = DueDate.objects.for_project_path(project_path).exclude( pootle_path=project_path, ) tps = TranslationProject.objects.filter(project__code=project_code) assert tp_due_dates.count() == tps.count() != 0 due_date.delete() tp_due_dates = DueDate.objects.for_project_path(project_path).exclude( pootle_path=project_path, ) assert tp_due_dates.count() == 0 store_due_dates = DueDate.objects.for_project_path(store_path).exclude( pootle_path=store_path, ) assert store_due_dates.count() != 0
def test_duedate_update_project_propagates(): """Tests due date updates at the project level propagate to existing due dates that point to the same resource across languages. """ project_code = "project0" store_path = "/projects/%s/store0.po" % project_code DueDateFactory.create(pootle_path=store_path, ) project_path = "/projects/%s/" % project_code due_date = DueDateFactory.create(pootle_path=project_path, ) # Update due date with different values other_user = UserFactory.create() other_due_on = aware_datetime(2017, 1, 1, 1, 2, 3) due_date.due_on = other_due_on due_date.modified_by = other_user due_date.save() tp_due_dates = DueDate.objects.for_project_path(project_path).exclude( pootle_path=project_path, ) for tp_due_date in tp_due_dates: assert tp_due_date.due_on == other_due_on assert tp_due_date.modified_by == other_user # Ensure the other due dates haven't been modified store_due_dates = DueDate.objects.for_project_path(store_path).exclude( pootle_path=store_path, ) for store_due_date in store_due_dates: assert store_due_date.due_on != other_due_on assert store_due_date.modified_by != other_user
def test_duedate_create_invalid_paths(pootle_path): """Tests certain path restrictions when creating due dates.""" with pytest.raises(ValidationError) as excinfo: DueDateFactory.create(pootle_path=pootle_path) message_dict = excinfo.value.message_dict assert "pootle_path" in message_dict assert "Cannot set due date for this path." in message_dict["pootle_path"]
def test_duedate_get_pending_tasks(): """Tests pending task retrieval for a particular language.""" language = "language0" tasks = DueDate.tasks(language) assert isinstance(tasks, TaskResultSet) DueDateFactory.create(pootle_path="/%s/project0/" % language, ) tasks = DueDate.tasks(language) assert isinstance(tasks, TaskResultSet)
def test_duedate_unicode(): due_on = aware_datetime(2017, 1, 1, 1, 2, 3) due_date = DueDateFactory.create( pootle_path="/foo/bar/", due_on=due_on, ) assert "%s" % due_date == "<DueDate: %s>" % due_date.due_on
def test_duedate_delete(client, request_users, test_name, snapshot_stack, path): """Tests removing existing due dates.""" user = request_users["user"] data = { "due_on": timezone.now(), "modified_by": user, "pootle_path": path, } due_date = DueDateFactory.create(**data) assert due_date.id is not None url = "/xhr/duedates/%s/" % due_date.id with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(path)]): if not user.is_anonymous: client.force_login(user) response = client.delete(url, content_type="application/json") with snapshot_stack.push("status_code") as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push("context") as snapshot: snapshot.assert_matches(response.json())
def test_critical_task_importance_factor(words_left, days_left, expected_factor): """Tests `CriticalTask`'s importance factor.""" now = aware_datetime(2017, 2, 28, 9, 0) due_on = now + timedelta(days=days_left) due_date = DueDateFactory.build(due_on=due_on) task = CriticalTask(due_date=due_date, now=now, words_left=words_left) assert task.importance_factor == expected_factor
def test_taskresultset_get_single(): """Tests retrieving a single task resultset item by index.""" due_on = now = aware_datetime(2017, 2, 28, 9, 0) due_date = DueDateFactory.build(due_on=due_on) task = TranslationTask(due_date=due_date, now=now, words_left=1) task_resultset = TaskResultSet([task]) assert task_resultset[0] == task.data
def test_duedate_delete(client, request_users, test_name, snapshot_stack, path): """Tests removing existing due dates.""" user = request_users['user'] data = { 'due_on': datetime.now(), 'modified_by': user, 'pootle_path': path, } due_date = DueDateFactory.create(**data) assert due_date.id is not None url = '/xhr/duedates/%s/' % due_date.id with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(path)]): if not user.is_anonymous: client.force_login(user) response = client.delete(url, content_type='application/json') with snapshot_stack.push('status_code') as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push('context') as snapshot: snapshot.assert_matches(response.json())
def test_taskresultset_get_raises(index): """Tests retrieving from a task resultset by using an invalid index/slice.""" due_on = now = aware_datetime(2017, 2, 28, 9, 0) due_date = DueDateFactory.build(due_on=due_on) task = TranslationTask(due_date=due_date, now=now, words_left=1) task_resultset = TaskResultSet([task]) with pytest.raises(TypeError): task_resultset[index]
def test_translation_task_repr(): """Tests `TranslationTask`'s representation.""" due_on = now = aware_datetime(2017, 02, 28, 9, 00) due_date = DueDateFactory.build(due_on=due_on) task = TranslationTask( due_date=due_date, now=now, words_left=1, ) assert (task.__repr__() == '<TranslationTask: /foo/ (2017-02-28 09:00:00+01:00)>')
def test_translation_task_importance_factor(words_left, days_left, expected_factor): """Tests `TranslationTask`'s importance factor.""" now = aware_datetime(2017, 02, 28, 9, 00) due_on = now + timedelta(days=days_left) due_date = DueDateFactory.build(due_on=due_on) task = TranslationTask( due_date=due_date, now=now, words_left=words_left, ) assert task.importance_factor == expected_factor
def test_duedate_create_project_propagates(): """Tests due date creation at the project level propagates to existing resources. """ project_code = "project0" store_path = "/projects/%s/store0.po" % project_code DueDateFactory.create(pootle_path=store_path, ) store_due_dates = DueDate.objects.for_project_path(store_path).exclude( pootle_path=store_path, ) stores = Store.objects.filter(pootle_path__endswith="/%s/store0.po" % project_code, ) assert store_due_dates.count() == stores.count() != 0 project_path = "/projects/%s/" % project_code DueDateFactory.create(pootle_path=project_path, ) tp_due_dates = DueDate.objects.for_project_path(project_path).exclude( pootle_path=project_path, ) tps = TranslationProject.objects.filter(project__code=project_code) assert tp_due_dates.count() == tps.count() != 0
def test_get_tasks_permissions( client, test_name, snapshot_stack, refresh_stats, request, request_users, patch_timezone_now, project0, hide, ): """Tests pending tasks retrieval with restricted permissions.""" language = "language0" url = "/xhr/tasks/%s/" % language user = request_users["user"] # Disallow `project0` access to `member` if user.username == "member": _require_permission_set(user, project0.directory, negative_permissions=[hide]) # FIXME: stats refreshing boilerplate global users_with_stats if user not in users_with_stats: request.getfixturevalue("refresh_stats") users_with_stats.add(user) now = aware_datetime(2017, 2, 28, 9, 0) patch_timezone_now(now) DueDateFactory.create( pootle_path="/projects/project0/", due_on=now + timedelta(days=8), ) DueDateFactory.create( pootle_path="/%s/project0/store0.po" % language, due_on=now + timedelta(days=2), ) DueDateFactory.create( pootle_path="/%s/project1/store0.po" % language, due_on=now + timedelta(days=4), ) with snapshot_stack.push([as_dir(test_name), as_dir(user.username)]): if not user.is_anonymous: client.force_login(user) response = client.get(url) with snapshot_stack.push("status_code") as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push("context") as snapshot: snapshot.assert_matches(response.json())
def test_duedate_update(client, request_users, test_name, snapshot_stack, path): """Tests updating existing due dates.""" user = request_users["user"] initial_due_on = aware_datetime(2017, 1, 26, 1, 2, 3) data = { "due_on": initial_due_on, "modified_by": user, "pootle_path": path, } due_date = DueDateFactory.create(**data) assert due_date.id is not None url = "/xhr/duedates/%s/" % due_date.id put_data = { "due_on": "2017-01-27", "pootle_path": path, } with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(path)]): if not user.is_anonymous: client.force_login(user) response = client.put(url, jsonify(put_data), content_type="application/json") if response.status_code == 200: due_date.refresh_from_db() assert due_date.due_on != initial_due_on with snapshot_stack.push("status_code") as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push("context") as snapshot: snapshot.assert_matches(response.json())
def test_duedate_update(client, request_users, test_name, snapshot_stack, path): """Tests updating existing due dates.""" user = request_users['user'] initial_due_on = aware_datetime(2017, 01, 26, 01, 02, 03) data = { 'due_on': initial_due_on, 'modified_by': user, 'pootle_path': path, } due_date = DueDateFactory.create(**data) assert due_date.id is not None url = '/xhr/duedates/%s/' % due_date.id put_data = { 'due_on': '2017-01-27', 'pootle_path': path, } with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(path)]): if not user.is_anonymous: client.force_login(user) response = client.put(url, jsonify(put_data), content_type='application/json') if response.status_code == 200: due_date.refresh_from_db() assert due_date.due_on != initial_due_on with snapshot_stack.push('status_code') as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push('context') as snapshot: snapshot.assert_matches(response.json())
def test_get_tasks(client, request, request_users, test_name, snapshot_stack, patch_timezone_now): """Tests pending tasks retrieval.""" language = 'language0' url = '/xhr/tasks/%s/' % language user = request_users['user'] # FIXME: stats refreshing boilerplate global users_with_stats if user not in users_with_stats: request.getfixturevalue('refresh_stats') users_with_stats.add(user) now = aware_datetime(2017, 02, 28, 9, 00) patch_timezone_now(now) DueDateFactory.create( pootle_path='/projects/project0/', due_on=now + timedelta(days=8), ) DueDateFactory.create( pootle_path='/%s/project0/store0.po' % language, due_on=now + timedelta(days=2), ) DueDateFactory.create( pootle_path='/%s/project1/store0.po' % language, due_on=now + timedelta(days=4), ) with snapshot_stack.push([as_dir(test_name), as_dir(user.username)]): if not user.is_anonymous: client.force_login(user) response = client.get(url) with snapshot_stack.push('status_code') as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push('context') as snapshot: snapshot.assert_matches(response.json())
def __init__(self, importance_factor, days_left, path, *args, **kwargs): self.importance_factor = importance_factor self.days_left = days_left self.due_date = DueDateFactory.build(pootle_path=path)
def test_duedate_get_pending_tasks_no_language_code(): due_date = DueDateFactory.create(pootle_path="/projects/foo/") now = aware_datetime(2017, 1, 1, 1, 2, 3) assert due_date.get_pending_tasks(now) == []
def test_duedate_manager_for_project_path(dummy_path): """Tests the manager method does nothing for non-project paths.""" DueDateFactory.create(pootle_path=dummy_path) assert DueDate.objects.for_project_path(dummy_path).count() == 0
def test_duedate_create(pootle_path): """Tests due dates creation for valid paths.""" due_date = DueDateFactory.create(pootle_path=pootle_path, ) assert due_date.id is not None