Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 fixes for data migrator #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion onadata/apps/data_migration/decisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def fields_groups_prev(self):
return self.xforms_comparator.fields_groups_prev()

def changed_fields_groups(self):
fields_changes = self.fields_changes
fields_groups_new = self.fields_groups_new()
migrated_fields_groups_prev = self.prev_fields_groups_migrated()
return {
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/data_migration/migrate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def migrate(self):

def save_survey(self, survey):
survey.save()
survey.parsed_instance.save(async=True)
survey.parsed_instance.save(async=True) # noqa: W606


class SurveyFieldsHandler(object):
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/data_migration/models/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def last_common_item(xs, ys):
"""Search for index of last common item in two lists."""
max_i = min(len(xs), len(ys)) - 1
for i, (x, y) in enumerate(zip(xs, ys)):
if x == y and (i == max_i or xs[i+1] != ys[i+1]):
if x == y and (i == max_i or xs[i + 1] != ys[i + 1]):
return i
return -1

Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/data_migration/restore_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _merge_changes(cls, curr_changes, new_changes):
new_changes[MigrationDecisioner.RM_FIELDS_KEY]),
modified=cls._transitive_merge(curr_changes[MigrationDecisioner.MOD_FIELDS_KEY],
new_changes[MigrationDecisioner.MOD_FIELDS_KEY]),
)
)

@staticmethod
def _transitive_merge(curr_changes, new_changes):
Expand Down
11 changes: 11 additions & 0 deletions onadata/apps/data_migration/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
exclude = migrations, settings, __init__.py, fixtures
max-line-length = 100
ignore =
# E731 do not assign a lambda expression, use a def
E731
# W503 line break before binary operator
W503
# W503 line break after binary operator
W504

10 changes: 5 additions & 5 deletions onadata/apps/data_migration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def _are_trees_isomorphic(cls, e1, e2):
cmp_tails = lambda e1, e2: (
remove_whitespaces(e1.tail or '') != remove_whitespaces(e2.tail or '')
)
if e1.tag != e2.tag: return False, get_msg(e1, e2, 'tag')
if e1.text != e2.text: return False, get_msg(e1, e2, 'text')
if cmp_tails(e1, e2): return False, get_msg(e1, e2, 'tail')
if e1.attrib != e2.attrib: return False, get_msg(e1, e2, 'attrib')
if len(e1) != len(e2): return False, "len({}) != len({})".format(str(e1), str(e2))
if e1.tag != e2.tag: return False, get_msg(e1, e2, 'tag') # noqa
if e1.text != e2.text: return False, get_msg(e1, e2, 'text') # noqa
if cmp_tails(e1, e2): return False, get_msg(e1, e2, 'tail') # noqa
if e1.attrib != e2.attrib: return False, get_msg(e1, e2, 'attrib') # noqa
if len(e1) != len(e2): return False, "len({}) != len({})".format(str(e1), str(e2)) # noqa

for c1, c2 in zip(sort_elems(e1), sort_elems(e2)):
are_equal, info = cls._are_trees_isomorphic(c1, c2)
Expand Down
9 changes: 3 additions & 6 deletions onadata/apps/data_migration/tests/test_backup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from onadata.apps.logger.models import Instance
from onadata.apps.data_migration.models import (
BackupInstance, BackupXForm, XFormVersion)
from onadata.apps.data_migration.backup_data import (
backup_xform, backup_survey
)
from onadata.apps.data_migration.models import BackupInstance, BackupXForm, XFormVersion
from onadata.apps.data_migration.backup_data import backup_xform, backup_survey
from .common import MigrationTestCase


Expand Down Expand Up @@ -56,7 +53,7 @@ def test_backup_xform__bind_twice(self):
def test_multiple_xform_backups(self):
exp = [backup_xform(self.xform).backup_version for _ in range(10)]
actual = BackupXForm.objects.filter(xform_id=self.xform.id)\
.values_list('backup_version', flat=True)
.values_list('backup_version', flat=True)
self.assertCountEqual(exp, actual)

def test_backup_survey(self):
Expand Down
1 change: 0 additions & 1 deletion onadata/apps/data_migration/tests/test_compare_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ def test_fields_groups(self):
'current_date': [],
}
)

2 changes: 1 addition & 1 deletion onadata/apps/data_migration/tests/test_data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_migration__grouped_case(self):
)


class DataMigratorIntegrationSecondTestsCase(test_case.ThirdMigrationTestCase):
class DataMigratorIntegrationThirdTestsCase(test_case.ThirdMigrationTestCase):
def test_migration__third_case(self):
self.data_migrator.migrate()
self.xform_new.refresh_from_db()
Expand Down
11 changes: 5 additions & 6 deletions onadata/apps/data_migration/tests/test_decisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def test_prev_fields_groups_migrated(self):
prev_fields_groups = self.migration_decisioner\
.prev_fields_groups_migrated()
self.assertEqual({
'first_name': [],
'gender': [],
'photo': [],
'age': [],
'location': [],
'first_name': [],
'gender': [],
'photo': [],
'age': [],
'location': [],
}, prev_fields_groups)

def test_changed_fields_groups(self):
Expand All @@ -131,7 +131,6 @@ def test_changed_fields_groups(self):
}, changed_fields_groups)



class GroupedMigrationDecisionerUnitTests(GroupedMigrationTestCase):
def setUp(self):
super(GroupedMigrationDecisionerUnitTests, self).setUp()
Expand Down
5 changes: 1 addition & 4 deletions onadata/apps/data_migration/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,5 @@ def test_extract_ancestors_labels(self):
'a_parents': ['root'],
}, {
'c31_parents': self.tree.extract_ancestors_labels(self.c31_node),
'a_parents': self.tree.extract_ancestors_labels(
self.tree.find_child_by_label('a')
)
'a_parents': self.tree.extract_ancestors_labels(self.tree.find_child_by_label('a'))
})

5 changes: 2 additions & 3 deletions onadata/apps/data_migration/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from unittest import skip
from mock import patch

from django.test import Client
Expand Down Expand Up @@ -80,7 +79,7 @@ def test_migration_process(self):
url = reverse('migrate-xform-data',
kwargs=self.get_data__both_id_strings())
response = self.client.post(url, self.get_migration_decisions())
self.assertEqual(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertEqual(XForm.objects.count(), 1)
self.assertEqual(Instance.objects.count(), 1)

Expand All @@ -92,4 +91,4 @@ def test_restore_backup_view(self, restore_backup_mock, *args):
response = self.client.post(url, {'restore_last': True})

restore_backup_mock.assert_called_once()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200)
1 change: 0 additions & 1 deletion onadata/apps/data_migration/tests/test_xformtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,3 @@ def test_get_structured_fields(self):
'math_degree', new_group]
self.assertCountEqual(expected_prev, self.prev_tree.get_structured_fields())
self.assertCountEqual(expected_new, self.new_tree.get_structured_fields())

4 changes: 1 addition & 3 deletions onadata/apps/data_migration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def set_form():
return {
'type': 'alert-success',
'text': _(u'Successfully updated %(form_id)s.'
u' Please proceed now in data migration') % {
'form_id': id_string,
}
u' Please proceed now in data migration') % {'form_id': id_string}
}
message = publish_form(set_form)

Expand Down
4 changes: 2 additions & 2 deletions onadata/apps/data_migration/xformtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_cleaned_nodeset(self, bind):
output: 'name'
"""
nodeset = bind.attrib['nodeset']
return nodeset[nodeset.find('/', 2)+1:]
return nodeset[nodeset.find('/', 2) + 1:]

def get_inputs_as_dict(self):
"""
Expand All @@ -129,7 +129,7 @@ def get_inputs_as_dict(self):

def get_input_name(self, input):
ref = input.attrib['ref']
return ref[ref.find('/', 2)+1:]
return ref[ref.find('/', 2) + 1:]

def get_id_string(self):
return self.get_head_instance().attrib['id']
Expand Down
2 changes: 1 addition & 1 deletion onadata/apps/data_migration/xmltree.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def clean_tag(tag):
Example: '{http://www.w3.org/1999/xhtml}head'
"""
header_end = tag.find('}')
return tag[header_end+1:] if header_end != -1 else tag
return tag[header_end + 1:] if header_end != -1 else tag

@classmethod
def field_tag(cls, field):
Expand Down