Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
chore: add unit tests for 'translating' code (hedyorg#439)
Browse files Browse the repository at this point in the history
I should have added these before, but better late than never?

Co-authored-by: Felienne <[email protected]>
  • Loading branch information
rix0rrr and Felienne authored May 23, 2021
1 parent ebbc09d commit cc06400
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_translating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest
import utils
import translating

class TestTranslating(unittest.TestCase):
def test_change_nested_records(self):
data = {}
translating.apply_form_change(data, 'adventures.dice.name', 'x')
self.assertEqual(data, {
'adventures': { 'dice': { 'name': 'x' }}
})

def test_record_with_int_keys(self):
data = {}
translating.apply_form_change(data, 'adventures.3.name', 'x')
self.assertEqual(data, {
'adventures': { 3: { 'name': 'x' }}
})

def test_array_with_index(self):
data = {}
translating.apply_form_change(data, 'adventures.a:0.name', 'x')
self.assertEqual(data, {
'adventures': [{ 'name': 'x' }]
})

def test_array_with_nonfirst_index(self):
data = {}
translating.apply_form_change(data, 'adventures.a:1.name', 'x')
self.assertEqual(data, {
'adventures': [{}, { 'name': 'x' }]
})

def test_array_with_nonfirst_index_and_two_changes(self):
data = {}
translating.apply_form_change(data, 'adventures.a:0.name', 'y')
translating.apply_form_change(data, 'adventures.a:1.name', 'x')
self.assertEqual(data, {
'adventures': [{ 'name': 'y' }, { 'name': 'x' }]
})

0 comments on commit cc06400

Please sign in to comment.