예제 #1
0
 def get_repr(self):
     return {
         "calc": [actions.get_action_repr(a) for a in self.calc],
         "stored": [actions.get_action_repr(a) for a in self.stored],
         "undo": [actions.get_action_repr(a) for a in self.undo],
         "direct": self.direct,
         "retValues": self.retValues
     }
예제 #2
0
 def to_json_obj(self):
     return {
         "envelopes": [e.to_json_obj() for e in self.envelopes],
         "stored":
         [(env, actions.get_action_repr(a)) for (env, a) in self.stored],
         "calc":
         [(env, actions.get_action_repr(a)) for (env, a) in self.calc],
         "undo": [(env, actions.get_action_repr(a))
                  for (env, a) in self.undo],
         "retValues":
         self.retValues,
         "rules":
         sorted(self.rules)
     }
예제 #3
0
 def create_migrations(all_tables, metadata_only=False):
     doc_actions = migrations.create_migrations(
         {
             t: table_data_from_db(t, data)
             for t, data in six.iteritems(all_tables)
         }, metadata_only)
     return [actions.get_action_repr(action) for action in doc_actions]
예제 #4
0
    def test_convert(self):
        self.assertEqual(actions.get_action_repr(self.action_obj1),
                         self.doc_action1)
        self.assertEqual(actions.action_from_repr(self.doc_action1),
                         self.action_obj1)

        with self.assertRaises(ValueError) as err:
            actions.action_from_repr(["Foo", "bar"])
        self.assertTrue("Foo" in str(err.exception))
예제 #5
0
 def apply_undo_actions(self, undo_actions):
     """
 Applies all doc_actions together (as happens e.g. for undo).
 """
     action = [
         "ApplyUndoActions",
         [actions.get_action_repr(a) for a in undo_actions]
     ]
     return self.apply_user_action(action, is_undo=True)
예제 #6
0
  def assertEqualActionGroups(self, observed, expected):
    """
    Compare grouped doc actions, reporting differences with a customized diff
    (a bit more readable than unittest's usual diff).
    """
    # Do some clean up on the observed data.
    observed = testutil.replace_nans(observed)

    # Convert expected actions into a comparable form.
    for k in self.action_group_action_fields:
      if k in observed:
        observed[k] = map(actions.get_action_repr, observed[k])
      if k in expected:
        expected[k] = [actions.get_action_repr(a) if not isinstance(a, list) else a
                       for a in expected[k]]

    if observed != expected:
      o_lines = self._formatActionGroup(observed)
      e_lines = self._formatActionGroup(expected)
      self.fail(("Observed out actions not as expected:\n") +
                "\n".join(difflib.unified_diff(e_lines, o_lines, n=3, lineterm="",
                                               fromfile="expected", tofile="observed")))
예제 #7
0
 def fetch_meta_tables(formulas=True):
     return {
         table_id: actions.get_action_repr(table_data)
         for (table_id,
              table_data) in six.iteritems(eng.fetch_meta_tables(formulas))
     }
예제 #8
0
 def fetch_table(table_id, formulas=True, query=None):
     return actions.get_action_repr(
         eng.fetch_table(table_id, formulas=formulas, query=query))
예제 #9
0
  def test_meta_tables(self):
    """
    Test changes to records accessed via lookup.
    """
    self.load_sample(testsamples.sample_students)
    self.assertPartialData("_grist_Tables", ["id", "columns"], [
      [1,   [1,2,4,5,6]],
      [2,   [10,12]],
      [3,   [21]],
    ])

    # Test that adding a column produces a change to 'columns' without emitting an action.
    out_actions = self.add_column('Students', 'test', type='Text', isFormula=False)
    self.assertPartialData("_grist_Tables", ["id", "columns"], [
      [1,   [1,2,4,5,6,22]],
      [2,   [10,12]],
      [3,   [21]],
    ])
    self.assertPartialOutActions(out_actions, {
      "calc": [],
      "stored": [
        ["AddColumn", "Students", "test",
         {"formula": "", "isFormula": False, "type": "Text"}
        ],
        ["AddRecord", "_grist_Tables_column", 22,
         {"colId": "test", "formula": "", "isFormula": False, "label": "test",
          "parentId": 1, "parentPos": 6.0, "type": "Text", "widgetOptions": ""}
        ],
      ],
      "undo": [
        ["RemoveColumn", "Students", "test"],
        ["RemoveRecord", "_grist_Tables_column", 22],
      ]
    })

    # Undo the AddColumn action. Check that actions are in correct order, and still produce undos.
    out_actions = self.apply_user_action(
      ['ApplyUndoActions', [actions.get_action_repr(a) for a in out_actions.undo]])
    self.assertPartialOutActions(out_actions, {
      "calc": [],
      "stored": [
        ["RemoveRecord", "_grist_Tables_column", 22],
        ["RemoveColumn", "Students", "test"],
      ],
      "undo": [
        ["AddRecord", "_grist_Tables_column", 22, {"colId": "test", "label": "test",
         "parentId": 1, "parentPos": 6.0, "type": "Text"}],
        ["AddColumn", "Students", "test", {"formula": "", "isFormula": False, "type": "Text"}],
      ]
    })

    # Test that when we add a table, .column is set correctly.
    out_actions = self.apply_user_action(['AddTable', 'Test2', [
      {'id': 'A', 'type': 'Text'},
      {'id': 'B', 'type': 'Numeric'},
      {'id': 'C', 'type': 'Numeric', 'formula': 'len($A)', 'isFormula': True}
    ]])
    self.assertPartialData("_grist_Tables", ["id", "columns"], [
      [1,   [1,2,4,5,6]],
      [2,   [10,12]],
      [3,   [21]],
      [4,   [22,23,24,25]],
    ])
    self.assertPartialData("_grist_Tables_column", ["id", "colId", "parentId"], [
      [1, "firstName",    1],
      [2, "lastName",     1],
      [4, "schoolName",   1],
      [5, "schoolIds",    1],
      [6, "schoolCities", 1],
      [10, "name",        2],
      [12, "address",     2],
      [21, "city",        3],
      # Newly added columns:
      [22,  'manualSort', 4],
      [23,  'A',          4],
      [24,  'B',          4],
      [25,  'C',          4],
    ])
예제 #10
0
def get_comparable_repr(a):
    if isinstance(a, (list, int)):
        return a
    return actions.get_action_repr(a)