def test_stats_checks(client, request_users, test_name, request, snapshot_stack, path): """Tests the /xhr/stats/checks/ endpoint's context.""" 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) with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(path)]): if not user.is_anonymous: client.force_login(user) url = "/xhr/stats/checks/?path=%s" % path response = client.get(url, HTTP_X_REQUESTED_WITH="XMLHttpRequest") with snapshot_stack.push("status_code") as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push("response_body") as snapshot: snapshot.assert_matches(response.json())
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_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_export( client, request_users, test_name, monkeypatch, snapshot_stack, url, limit, include_disabled, ): """Tests correctness of the export view context.""" user = request_users["user"] stack = [as_dir(test_name), as_dir(user.username), url_name(url)] if limit is not None: stack.append("limit=%s" % limit) monkeypatch.setattr("pootle.core.views.export.UNITS_LIMIT", limit) if include_disabled: stack.append("include_disabled") url += "?all" with snapshot_stack.push(stack): 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.context)
def test_get_stats(client, request_users, test_name, request, snapshot_stack, params): """Tests the /xhr/stats/ view.""" url = "/xhr/stats/" user = request_users["user"] # stats refreshing boilerplate global users_with_stats if user not in users_with_stats: request.getfixturevalue("refresh_stats") users_with_stats.add(user) qs = urllib.parse.urlencode(params, True) with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(url + qs)]): if not user.is_anonymous: client.force_login(user) response = client.get(url, params, HTTP_X_REQUESTED_WITH="XMLHttpRequest") with snapshot_stack.push("status_code") as snapshot: snapshot.assert_matches(response.status_code) with snapshot_stack.push("response") as snapshot: snapshot.assert_matches(response.json())
def test_stats_retrieval_no_stats(test_name, snapshot_stack, flush_stats): """Tests no stats are provided when these haven't been calculated.""" path = "/language0/project0/" with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { "total": stats.total, "translated": stats.translated, "fuzzy": stats.fuzzy, "incomplete": stats.incomplete, "critical": stats.critical, "suggestions": stats.suggestions, "last_action": stats.last_action, "last_updated": stats.last_updated, } snapshot.assert_matches(stats_data)
def test_stats_retrieval_dummy(test_name, snapshot_stack, refresh_stats): """Tests no stats are provided for dummy paths.""" path = "/non/existing/" with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { "total": stats.total, "translated": stats.translated, "fuzzy": stats.fuzzy, "incomplete": stats.incomplete, "critical": stats.critical, "suggestions": stats.suggestions, "last_action": stats.last_action, "last_updated": stats.last_updated, } snapshot.assert_matches(stats_data)
def test_stats_retrieval(test_name, snapshot_stack, refresh_stats): """Tests stats values are retrieved properly.""" path = "/language0/project0/" with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { "total": stats.total, "translated": stats.translated, "fuzzy": stats.fuzzy, "incomplete": stats.incomplete, "critical": stats.critical, "suggestions": stats.suggestions, "last_action": stats.last_action, "last_updated": stats.last_updated, } snapshot.assert_matches(stats_data)
def test_stats_retrieval(test_name, snapshot_stack, refresh_stats): """Tests stats values are retrieved properly.""" path = '/language0/project0/' with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { 'total': stats.total, 'translated': stats.translated, 'fuzzy': stats.fuzzy, 'incomplete': stats.incomplete, 'critical': stats.critical, 'suggestions': stats.suggestions, 'last_action': stats.last_action, 'last_updated': stats.last_updated, } snapshot.assert_matches(stats_data)
def test_stats_retrieval_dummy(test_name, snapshot_stack, refresh_stats): """Tests no stats are provided for dummy paths.""" path = '/non/existing/' with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { 'total': stats.total, 'translated': stats.translated, 'fuzzy': stats.fuzzy, 'incomplete': stats.incomplete, 'critical': stats.critical, 'suggestions': stats.suggestions, 'last_action': stats.last_action, 'last_updated': stats.last_updated, } snapshot.assert_matches(stats_data)
def test_stats_retrieval_no_stats(test_name, snapshot_stack, flush_stats): """Tests no stats are provided when these haven't been calculated.""" path = '/language0/project0/' with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot: stats = Stats(path) stats_data = { 'total': stats.total, 'translated': stats.translated, 'fuzzy': stats.fuzzy, 'incomplete': stats.incomplete, 'critical': stats.critical, 'suggestions': stats.suggestions, 'last_action': stats.last_action, 'last_updated': stats.last_updated, } snapshot.assert_matches(stats_data)
def test_translate(client, request_users, test_name, snapshot_stack, url): """Tests correctness of the translate view context.""" user = request_users["user"] with snapshot_stack.push( [as_dir(test_name), as_dir(user.username), url_name(url)]): 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.context)
def test_browse(client, request_users, test_name, request, snapshot_stack, url): """Tests correctness of the browsing view context.""" user = request_users["user"] # stats refreshing boilerplate global users_with_stats if user not in users_with_stats: request.getfixturevalue("refresh_stats") users_with_stats.add(user) with snapshot_stack.push([as_dir(test_name), as_dir(user.username), url_name(url)]): 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.context)
def test_export(client, request_users, test_name, monkeypatch, snapshot_stack, url, limit): """Tests correctness of the export view context.""" user = request_users['user'] stack = [as_dir(test_name), as_dir(user.username), url_name(url)] if limit is not None: stack.append('limit=%s' % limit) monkeypatch.setattr('pootle.core.views.export.UNITS_LIMIT', limit) with snapshot_stack.push(stack): 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.context)
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_duedate_post(client, request_users, test_name, snapshot_stack, path): """Tests creating new due dates.""" url = '/xhr/duedates/' user = request_users['user'] post_data = { 'due_on': '2017-01-26', '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.post(url, jsonify(post_data), 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_duedate_post(client, request_users, test_name, snapshot_stack, path): """Tests creating new due dates.""" url = "/xhr/duedates/" user = request_users["user"] post_data = { "due_on": "2017-01-26", "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.post(url, jsonify(post_data), 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())