예제 #1
0
    def test_success(self):
        self.config.add_route('admin_expense', '/')
        appstruct = {'expenses':[
            {'label':u"Restauration", "code":u"0001", "id":None},
            {'label':u"Déplacement", "code":u"0002", "id":None}],
                    'expenseskm':[
            {'label':u"Scooter", "code":u"0003", "amount":"0.852", "id":None}],
                    'expensestel':[
            {'label':u"Adsl-Téléphone", "code":u"0004", "percentage":"80",
                "id":None}]}
        view = AdminExpense(self.get_csrf_request())
        view.submit_success(appstruct)

        form = DummyForm()
        view.before(form)
        self.assertEqual(len(form.appstruct['expenses']), 2)
        self.assertEqual(form.appstruct['expenses'][0]['label'], u"Restauration")
        self.assertEqual(form.appstruct['expenses'][0]['code'], u"0001")
        self.assertEqual(form.appstruct['expenseskm'][0]['label'], u"Scooter")
        self.assertEqual(form.appstruct['expenseskm'][0]['amount'], 0.852)
        self.assertEqual(form.appstruct['expensestel'][0]['percentage'], 80)
예제 #2
0
def test_success_id_preservation(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {'expenses':[
        {'label':u"Restauration", "code":u"0001", "id":None}],
                'expenseskm':[],
                'expensestel':[]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    expense = ExpenseType.query().filter(ExpenseType.code=="0001").first()

    appstruct['expenses'][0]['id'] = expense.id
    appstruct['expenses'][0]['code'] = u"00002"
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)
    expense = ExpenseType.query().filter(ExpenseType.id==expense.id).first()
    assert expense.code == u"00002"
예제 #3
0
    def test_success_id_preservation(self):
        self.config.add_route('admin_expense', '/')
        appstruct = {'expenses':[
            {'label':u"Restauration", "code":u"0001", "id":None}],
                    'expenseskm':[],
                    'expensestel':[]}
        view = AdminExpense(self.get_csrf_request())
        view.submit_success(appstruct)

        expense = ExpenseType.query().filter(ExpenseType.code=="0001").first()
        appstruct['expenses'][0]['id'] = expense.id
        appstruct['expenses'][0]['code'] = u"00002"
        view = AdminExpense(self.get_csrf_request())
        view.submit_success(appstruct)
        expense = ExpenseType.query().filter(ExpenseType.id==expense.id).first()
        self.assertEqual(expense.code, u"00002")
예제 #4
0
def test_expense_config_success(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {
            "code_journal": "JOURNAL01",
            'compte_cg': "DOE548",
            'expenses':[
{'label':u"Restauration", "code":u"0001", "id":None, 'compte_tva':"CTVA" },

{'label':u"Déplacement", "code":u"0002", "id":None, 'code_tva':"TVA"}
        ],
                'expenseskm':[
{'label':u"Scooter", "code":u"0003", "amount":"0.852", "id":None,
    'code_tva':"TVA1"}],
                'expensestel':[
{'label':u"Adsl-Téléphone", "code":u"0004", "percentage":"80",
    "id":None, "code_tva": "TVA2", 'contribution': True}]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    assert "DOE548" == Config.get('compte_cg_ndf').value
    assert "JOURNAL01" == Config.get('code_journal_ndf').value

    form = DummyForm()
    view.before(form)
    assert len(form.appstruct['expenses']) == 2
    assert form.appstruct['expenses'][0]['label'] == u"Restauration"
    assert form.appstruct['expenses'][0]['code'] == u"0001"
    assert form.appstruct['expenses'][0]['compte_tva'] == "CTVA"
    assert form.appstruct['expenses'][1]['code_tva'] == "TVA"

    assert form.appstruct['expenseskm'][0]['label'] == u"Scooter"
    assert form.appstruct['expenseskm'][0]['amount'] == 0.852
    assert form.appstruct['expenseskm'][0]['code_tva'] == 'TVA1'
    assert form.appstruct['expensestel'][0]['percentage'] == 80
    assert form.appstruct['expensestel'][0]['code_tva'] == 'TVA2'
    assert form.appstruct['expensestel'][0]['contribution'] == True