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_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_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_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_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_pending_agreements(): """Tests proper user pending agreements are returned.""" foo_user = UserFactory.create(username="******") privacy_policy = LegalPageFactory.create( active=True, modified_on=aware_datetime(2014, 1, 1), ) # `foo_user` hasn't agreed the privacy policy yet pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert privacy_policy in pending # `foo_user` agreed the privacy policy AgreementFactory.create( user=foo_user, document=privacy_policy, agreed_on=aware_datetime(2014, 2, 2), ) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 0 # Let's add a new ToS tos = LegalPageFactory.create(active=True, modified_on=aware_datetime(2015, 1, 1),) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert tos in pending # `foo_user` also accepted the ToS AgreementFactory.create( user=foo_user, document=tos, agreed_on=aware_datetime(2015, 2, 2), ) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 0 # The ToS were modified, `foo_user` must agree it tos.modified_on = aware_datetime(2015, 3, 3) tos.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert tos in pending # Same with the privacy policy privacy_policy.modified_on = aware_datetime(2015, 4, 4) privacy_policy.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 2 assert privacy_policy in pending assert tos in pending # Let's disable the ToS tos.active = False tos.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert privacy_policy in pending
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_translation_task_repr(): """Tests `TranslationTask`'s representation.""" 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) assert task.__repr__() == "<TranslationTask: /foo/ (2017-02-28 09:00:00+01:00)>"
def test_aware_datetime_explicit_tz(): """Tests the creation of a explicitly provided timezone-aware datetime.""" new_datetime = aware_datetime(2016, 1, 2, 21, 52, 25, tz=pytz.utc) assert timezone.is_aware(new_datetime) assert new_datetime.tzinfo.zone == pytz.utc.zone
def test_aware_datetime(settings): """Tests the creation of a timezone-aware datetime.""" datetime_object = aware_datetime(2016, 1, 2, 21, 52, 25) assert timezone.is_aware(datetime_object) assert datetime_object.tzinfo.zone == settings.TIME_ZONE
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_pending_agreements(): """Tests proper user pending agreements are returned.""" foo_user = UserFactory.create(username='******') privacy_policy = LegalPageFactory.create( active=True, modified_on=aware_datetime(2014, 01, 01), ) # `foo_user` hasn't agreed the privacy policy yet pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert privacy_policy in pending # `foo_user` agreed the privacy policy AgreementFactory.create( user=foo_user, document=privacy_policy, agreed_on=aware_datetime(2014, 02, 02), ) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 0 # Let's add a new ToS tos = LegalPageFactory.create( active=True, modified_on=aware_datetime(2015, 01, 01), ) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert tos in pending # `foo_user` also accepted the ToS AgreementFactory.create( user=foo_user, document=tos, agreed_on=aware_datetime(2015, 02, 02), ) pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 0 # The ToS were modified, `foo_user` must agree it tos.modified_on = aware_datetime(2015, 03, 03) tos.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert tos in pending # Same with the privacy policy privacy_policy.modified_on = aware_datetime(2015, 04, 04) privacy_policy.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 2 assert privacy_policy in pending assert tos in pending # Let's disable the ToS tos.active = False tos.save() pending = list(LegalPage.objects.pending_user_agreement(foo_user)) assert len(pending) == 1 assert privacy_policy in pending