def test_change_question_sets_contains_changes(self): self._add_question(self.app1.modules[0].forms[0], {'constraint': 'foo = bar'}) self._add_question(self.app2.modules[0].forms[0], {'constraint': 'foo != bar'}) first, second = get_app_diff(self.app1, self.app2) self.assertTrue(first[0]['forms'][0].changes.contains_changes) self.assertTrue(second[0]['forms'][0].changes.contains_changes)
def test_change_form_name(self): self.app2.modules[0].forms[0].name['en'] = "a new name" first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['changes']['name']['type'], CHANGED) self.assertEqual(first[0]['forms'][0]['changes']['name']['type'], CHANGED)
def test_add_form(self): self.factory2.new_form(self.app2.modules[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(second[0]['forms'][1]['changes']['form']['type'], ADDED) self.assertEqual(second[0]['forms'][1]['name'], self.app2.modules[0].forms[1].name)
def test_change_form_filter(self): self.app2.modules[0].forms[0].form_filter = "foo = 'bar'" first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['changes']['form_filter']['type'], CHANGED) self.assertEqual( first[0]['forms'][0]['changes']['form_filter']['type'], CHANGED)
def test_remove_then_add_module(self): self.factory1.new_basic_module('module_2', 'case') self.factory2.new_basic_module('module_3', 'case') first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[1]['changes']['module']['type'], REMOVED) self.assertEqual(first[1]['unique_id'], self.app1.modules[1].unique_id) self.assertEqual(second[1]['changes']['module']['type'], ADDED) self.assertEqual(second[1]['unique_id'], self.app2.modules[1].unique_id)
def test_remove_then_add_module(self): self.factory1.new_basic_module('module_2', 'case') self.factory2.new_basic_module('module_3', 'case') first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[1]['changes']['module'], REMOVED) self.assertEqual(first[1]['unique_id'], self.app1.modules[1].unique_id) self.assertEqual(second[1]['changes']['module'], ADDED) self.assertEqual(second[1]['unique_id'], self.app2.modules[1].unique_id)
def test_remove_question_from_group(self): self._add_question_to_group(self.app1.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Q in a group', 'group': 'agroup', }) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['questions'][0]['children'][0]['changes']['question'], REMOVED)
def test_add_question_constraint(self): self._add_question(self.app1.modules[0].forms[0], {'constraint': ''}) self._add_question(self.app2.modules[0].forms[0], {'constraint': 'foo = bar'}) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( second[0]['forms'][0]['questions'][0]['changes']['constraint'] ['type'], ADDED)
def test_add_question_translation(self): self.app1.langs = ['en', 'it'] self.app2.langs = ['en', 'it'] self._add_question(self.app1.modules[0].forms[0], {'label': {'en': 'food'}}) self._add_question(self.app2.modules[0].forms[0], {'label': {'en': 'food', 'it': 'cibo'}}) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['questions'][0]['changes']['translations']['type'], CHANGED) self.assertEqual(second[0]['forms'][0]['questions'][0]['changes']['translations']['type'], CHANGED)
def test_change_question_label(self): self._add_question(self.app1.modules[0].forms[0], {'label': 'foo'}) self._add_question(self.app2.modules[0].forms[0], {'label': 'bar'}) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['label']['type'], CHANGED) self.assertEqual( second[0]['forms'][0]['questions'][0]['changes']['label']['type'], CHANGED)
def test_remove_save_property(self): self._add_question(self.app1.modules[0].forms[0]) self._add_question(self.app2.modules[0].forms[0]) self.factory1.form_requires_case(self.app1.modules[0].forms[0], update={'foo': '/data/name'}) self.app1.save() first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['save_properties']['case']['foo'], REMOVED )
def test_remove_question_from_group(self): self._add_question_to_group( self.app1.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Q in a group', 'group': 'agroup', }) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['children'][0]['changes'] ['question']['type'], REMOVED)
def test_remove_save_property(self): self._add_question(self.app1.modules[0].forms[0]) self._add_question(self.app2.modules[0].forms[0]) self.factory1.form_requires_case(self.app1.modules[0].forms[0], update={'foo': '/data/name'}) self.app1.save() first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['save_properties'] ['case']['foo']['type'], REMOVED)
def test_change_question_in_group(self): self._add_question_to_group(self.app1.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Q in a group', 'group': 'agroup', }) self._add_question_to_group(self.app2.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Foo in a group', 'group': 'agroup' }) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(second[0]['forms'][0]['questions'][0]['children'][0]['changes']['label'], CHANGED)
def test_change_question_in_group(self): self._add_question_to_group(self.app1.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Q in a group', 'group': 'agroup', }) self._add_question_to_group(self.app2.modules[0].forms[0], { 'name': 'question_in_group', 'label': 'Foo in a group', 'group': 'agroup' }) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(second[0]['forms'][0]['questions'][0]['children'][0]['changes']['label']['type'], CHANGED)
def test_remove_then_add_question(self): self._add_question(self.app1.modules[0].forms[0], { 'name': 'foo', 'label': 'foo' }) self._add_question(self.app2.modules[0].forms[0], { 'name': 'bar', 'label': 'bar' }) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['question'] ['type'], REMOVED) self.assertEqual( second[0]['forms'][0]['questions'][0]['changes']['question'] ['type'], ADDED)
def test_move_form(self): # A moved form should show up as deleted and re-added self.factory1.new_form(self.app1.modules[0]) self.factory1.new_basic_module('module_2', 'case') self.factory2.new_form(self.app2.modules[0]) self.factory2.new_basic_module('module_2', 'case') self.app2.rearrange_forms( from_module_uid=self.app2.modules[0].unique_id, to_module_uid=self.app2.modules[1].unique_id, from_index=1, to_index=1, ) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][1]['changes']['form']['type'], REMOVED) self.assertEqual(second[1]['forms'][1]['changes']['form']['type'], ADDED)
def page_context(self): context = super(FormSummaryDiffView, self).page_context if self.first_app.master_id != self.second_app.master_id: # This restriction is somewhat arbitrary, as you might want to # compare versions between two different apps on the same domain. # However, it breaks a bunch of assumptions in the UI raise Http404() first = self._app_dict(self.first_app) second = self._app_dict(self.second_app) first['modules'], second['modules'] = get_app_diff(self.first_app, self.second_app) context.update({ 'page_type': 'form_diff', 'app_id': self.app.master_id, 'first': first, 'second': second, }) return context
def test_change_save_property(self): self._add_question(self.app1.modules[0].forms[0]) self._add_question(self.app2.modules[0].forms[0]) self.factory1.form_requires_case(self.app1.modules[0].forms[0], update={"foo": "/data/name"}) self.factory2.form_requires_case(self.app2.modules[0].forms[0], update={"bar": "/data/name"}) self.app1.save() self.app2.save() first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['save_properties'] ['case']['foo']['type'], REMOVED, ) self.assertEqual( second[0]['forms'][0]['questions'][0]['changes']['save_properties'] ['case']['bar']['type'], ADDED, )
def test_add_question(self): self._add_question(self.app2.modules[0].forms[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(second[0]['forms'][0]['questions'][0]['changes']['question'], ADDED)
def test_change_question_constraint(self): self._add_question(self.app1.modules[0].forms[0], {'constraint': 'foo = bar'}) self._add_question(self.app2.modules[0].forms[0], {'constraint': 'foo != bar'}) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['questions'][0]['changes']['constraint'], CHANGED) self.assertEqual(second[0]['forms'][0]['questions'][0]['changes']['constraint'], CHANGED)
def test_remove_form_sets_contains_changes(self): self.factory1.new_form(self.app1.modules[0]) first, second = get_app_diff(self.app1, self.app2) self.assertTrue(first[0]['forms'][1].changes.contains_changes)
def test_add_form(self): self.factory2.new_form(self.app2.modules[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(second[0]['forms'][1]['changes']['form'], ADDED) self.assertEqual(second[0]['forms'][1]['name'], self.app2.modules[0].forms[1].name)
def test_remove_question(self): self._add_question(self.app1.modules[0].forms[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( first[0]['forms'][0]['questions'][0]['changes']['question'] ['type'], REMOVED)
def test_add_question(self): self._add_question(self.app2.modules[0].forms[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual( second[0]['forms'][0]['questions'][0]['changes']['question'] ['type'], ADDED)
def test_remove_form(self): self.factory1.new_form(self.app1.modules[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][1]['changes']['form']['type'], REMOVED)
def test_change_form_name(self): self.app2.modules[0].forms[0].name['en'] = "a new name" first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['changes']['name'], CHANGED) self.assertEqual(first[0]['forms'][0]['changes']['name'], CHANGED)
def test_change_form_filter(self): self.app2.modules[0].forms[0].form_filter = "foo = 'bar'" first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['changes']['form_filter'], CHANGED) self.assertEqual(first[0]['forms'][0]['changes']['form_filter'], CHANGED)
def test_remove_then_add_question(self): self._add_question(self.app1.modules[0].forms[0], {'name': 'foo', 'label': 'foo'}) self._add_question(self.app2.modules[0].forms[0], {'name': 'bar', 'label': 'bar'}) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['questions'][0]['changes']['question'], REMOVED) self.assertEqual(second[0]['forms'][0]['questions'][0]['changes']['question'], ADDED)
def test_remove_form(self): self.factory1.new_form(self.app1.modules[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][1]['changes']['form'], REMOVED)
def test_remove_question(self): self._add_question(self.app1.modules[0].forms[0]) first, second = get_app_diff(self.app1, self.app2) self.assertEqual(first[0]['forms'][0]['questions'][0]['changes']['question'], REMOVED)