A parser inspired by the django orm.
all tests work
3 files changed, +36 -1
+1-1parsers/manager.py
| @@ -50,6 +50,6 @@ class Manager: | ||
| 50 | 50 | unique_together_violation = False |
| 51 | 51 | break |
| 52 | 52 | else: |
| 53 | - vals.append(o[key]) | |
| 53 | + vals.append(o.__dict__[key]) | |
| 54 | 54 | if unique_together_violation: |
| 55 | 55 | raise UniqueTogetherParseError(self.cls, unique_together, vals) |
+8-0tests/test_create.py
| @@ -0,0 +1,8 @@ | ||
| 1 | +import parsers | |
| 2 | +import unittest | |
| 3 | + | |
| 4 | + | |
| 5 | +class TestCreate(unittest.TestCase): | |
| 6 | + | |
| 7 | + def test_nullable(self): | |
| 8 | + pass |
+27-0tests/test_exceptions.py
| @@ -21,7 +21,21 @@ def raise_unique_error(): | ||
| 21 | 21 | |
| 22 | 22 | def raise_unique_together(): |
| 23 | 23 | t1 = Test(a='a', b='b', c='c', d='d1') |
| 24 | + t1.save() | |
| 24 | 25 | t2 = Test(a='a', b='b', c='c', d='d2') |
| 26 | + t2.save() | |
| 27 | + | |
| 28 | + | |
| 29 | +def raise_missing_keys(): | |
| 30 | + Test(a='sdf') | |
| 31 | + | |
| 32 | + | |
| 33 | +def raise_extra_fields(): | |
| 34 | + Test(a='asdf', b='b', c='c', d='d', e='e') | |
| 35 | + | |
| 36 | + | |
| 37 | +def raise_with_id(): | |
| 38 | + Test(id='1', a='a', b='b', c='c', d='d') | |
| 25 | 39 | |
| 26 | 40 | |
| 27 | 41 | class TestExceptions(unittest.TestCase): |
| @@ -29,3 +43,16 @@ class TestExceptions(unittest.TestCase): | ||
| 29 | 43 | def test_unique(self): |
| 30 | 44 | self.assertRaises( |
| 31 | 45 | parsers.exceptions.UniqueFieldParseError, raise_unique_error) |
| 46 | + | |
| 47 | + def test_unique_together(self): | |
| 48 | + self.assertRaises(parsers.UniqueTogetherParseError, | |
| 49 | + raise_unique_together) | |
| 50 | + | |
| 51 | + def test_missing_keys(self): | |
| 52 | + self.assertRaises(parsers.MissingFieldsParseError, raise_missing_keys) | |
| 53 | + | |
| 54 | + def test_extra_fields(self): | |
| 55 | + self.assertRaises(parsers.ExtraFieldsParseError, raise_extra_fields) | |
| 56 | + | |
| 57 | + def test_with_id(self): | |
| 58 | + self.assertRaises(parsers.CreateWithIdParseError, raise_with_id) |