コード例 #1
0
 def test_dm_to_pd(self):
     obj = dm.Book(
         book_id=2,
         name='Test Book',
         created_at=self.aware_time,
     )
     ser = self.serializer_class(obj)
     data = ser.data
     assert data['book_id'] == 2
     assert data['name'] == 'Test Book'
     assert data['created_at'] == self.datetime_string
コード例 #2
0
ファイル: test_adaptor.py プロジェクト: altaurog/django-caspy
 def test_domain_to_orm(self):
     obj = domain.Book(
         name='Test Book',
         created_at=self.the_time,
     )
     instance = orm.domain_to_orm(obj)
     assert isinstance(instance, db.Book)
     assert instance.book_id is None
     assert instance.name == 'Test Book'
     assert instance.created_at == self.the_time
     obj.book_id = 1
     instance = orm.domain_to_orm(obj)
     assert instance.book_id == 1
コード例 #3
0
 def test_prepare_new_book(self):
     empty_book = models.Book()
     result = command.prepare_book(empty_book, 'now')
     assert isinstance(result, models.Book)
     assert result.created_at == 'now'
コード例 #4
0
 def test_prepare_old_book(self):
     dated_book = models.Book(created_at='last week')
     result = command.prepare_book(dated_book, 'now')
     assert isinstance(result, models.Book)
     assert result.created_at == 'last week'
コード例 #5
0
ファイル: test_adaptor.py プロジェクト: altaurog/django-caspy
 def test_domain_bad_field(self):
     o = domain.Book(book_id=1, name='1996')
     with pytest.raises(AttributeError):
         assert orm.get_field(o, 'bad')
コード例 #6
0
ファイル: test_adaptor.py プロジェクト: altaurog/django-caspy
 def test_domain_field_name(self):
     o = domain.Book(book_id=1, name='1996')
     assert orm.get_field(o, 'name') == '1996'
コード例 #7
0
ファイル: test_adaptor.py プロジェクト: altaurog/django-caspy
 def test_domain(self):
     o = domain.Book(book_id=1, name='1996')
     assert orm.get_field(o) == 1
コード例 #8
0
ファイル: test_adaptor.py プロジェクト: altaurog/django-caspy
class TestAccount:
    book = domain.Book(book_id=3, name='Test Book')
    currency = domain.Currency(cur_code='USD', symbol='$')
    account_type = domain.AccountType(account_type='Expense')

    def test_deep_domain_to_orm(self):
        obj = domain.Account(
            account_id=10,
            parent_id=2,
            path='Expense::Education',
            name='Education',
            book=self.book,
            account_type=self.account_type,
            currency=self.currency,
            description='Education Expense',
        )
        instance = orm.domain_to_orm(obj)
        assert isinstance(instance, db.Account)
        assert instance.book_id == 3
        assert instance.parent_id == 2
        assert instance.currency_id == 'USD'
        assert instance.account_type_id == 'Expense'
        assert instance.account_id == 10
        assert instance.name == 'Education'
        assert instance.path == 'Expense::Education'
        assert instance.description == 'Education Expense'

    def test_shallow_domain_to_orm(self):
        obj = domain.Account(
            account_id=10,
            name='Education',
            book=3,
            account_type='Expense',
            currency='USD',
            description='Education Expense',
        )
        instance = orm.domain_to_orm(obj)
        assert isinstance(instance, db.Account)
        assert instance.book_id == 3
        assert instance.currency_id == 'USD'
        assert instance.account_type_id == 'Expense'
        assert instance.account_id == 10
        assert instance.name == 'Education'
        assert instance.description == 'Education Expense'

    def test_shallow_orm_to_domain(self):
        instance = db.Account(
            account_id=11,
            name='Utilities',
            book_id=3,
            account_type_id='Expense',
            currency_id='USD',
            description='Utilities Expense',
        )
        obj = orm.orm_to_domain(instance)
        assert isinstance(obj, domain.Account)
        assert obj.account_id == 11
        assert obj.name == 'Utilities'
        assert obj.book == 3
        assert obj.account_type == 'Expense'
        assert obj.currency == 'USD'
        assert obj.description == 'Utilities Expense'

    def test_deep_orm_to_domain(self):
        book = db.Book(book_id=3, name='Test Book')
        account_type = db.AccountType(account_type='Expense')
        currency = db.Currency(cur_code='NIS')
        instance = db.Account(
            account_id=11,
            name='Utilities',
            book=book,
            account_type=account_type,
            currency=currency,
            description='Utilities Expense',
        )
        instance.parent_id = 2
        instance.path = 'Expense::Utilities'
        obj = orm.orm_to_domain(instance)
        assert isinstance(obj, domain.Account)
        assert obj.account_id == 11
        assert obj.name == 'Utilities'
        assert obj.book == 3
        assert obj.account_type == 'Expense'
        assert obj.currency == 'NIS'
        assert obj.description == 'Utilities Expense'
        assert obj.parent_id == 2
        assert obj.path == 'Expense::Utilities'
コード例 #9
0
 def test_str(self):
     book_obj = models.Book(name='שנת 2015')
     assert to_string(book_obj) == 'שנת 2015'