예제 #1
0
파일: test_forms.py 프로젝트: ox1230/capl
    def test_form_validation_for_blank(self):
        cate = Category.objects.create()
        form = HistoryForm(
            data={
                'name': '',
                'category': cate.id,
                'price': 1000,
                'written_date': date.today()
            })
        self.assertTrue(form.is_valid())

        form = HistoryForm(
            data={
                'name': '',
                'category': None,
                'price': 1000,
                'written_date': date.today()
            })
        self.assertFalse(form.is_valid())

        form = HistoryForm(
            data={
                'name': '',
                'category': cate.id,
                'price': None,
                'written_date': date.today()
            })
        self.assertFalse(form.is_valid())
예제 #2
0
    def test_can_process_halbu_for_total_and_each_category_residual(self):
        cate1 = Category.objects.create(name="c1", assigned=10000)

        form = HistoryForm(
            data={
                'category': cate1.id,
                'price': 2400,
                'written_date': date.today(),
                'name': 'h1',
                'halbu_week': 2
            })
        form.save()

        form2 = HistoryForm(
            data={
                'category': cate1.id,
                'price': 3200,
                'written_date': date.today() + timedelta(days=-7),
                'name': 'h1',
                'halbu_week': 2
            })
        # 1주일 전것 추가\
        form2.save()

        cateinfo = CategoryInfo(cate1)
        self.assertEqual(cateinfo.resid, 10000 - 1200 - 1600)
        self.assertEqual(cateinfo.for_day, (10000 - 1600) //
                         (7 - WeekAndDay.my_week_day()) - 1200)

        infos_main = Processing.get_informations_for_main()
        self.assertEqual(infos_main['total_assigned'], 10000)
        self.assertEqual(infos_main['total_sum'], 2800)
        self.assertEqual(infos_main['total_residual'], 10000 - 1200 - 1600)
예제 #3
0
파일: test_forms.py 프로젝트: ox1230/capl
    def test_form_save_handles_saving_to_a_list(self):
        cate = Category.objects.create()

        form = HistoryForm(
            data={
                'name': 'hihi',
                'category': cate.id,
                'price': 1000,
                'written_date': date.today()
            })
        new_history = form.save()
        self.assertEqual(new_history, History.objects.first())
        self.assertEqual(new_history.name, 'hihi')
        self.assertEqual(new_history.category, cate)
        self.assertEqual(new_history.price, 1000)
        self.assertEqual(new_history.written_date, date.today())
예제 #4
0
파일: test_forms.py 프로젝트: ox1230/capl
    def test_form_save_history_and_halbu_well(self):
        cate = Category.objects.create()

        form = HistoryForm(
            data={
                'name': 'hihi',
                'category': cate.id,
                'price': 2400,
                'written_date': date.today(),
                'halbu_week': 3
            })

        new_history = form.save()
        halbu = HalbuHistory.objects.first()

        self.assertEqual(new_history, History.objects.first())
        self.assertEqual(new_history.name, 'hihi')
        self.assertEqual(new_history.category, cate)
        self.assertEqual(new_history.price, 2400)
        self.assertEqual(new_history.written_date, date.today())

        self.assertEqual(halbu.category, cate)
        self.assertEqual(halbu.history, new_history)
        self.assertEqual(halbu.depre, 800)
예제 #5
0
파일: views.py 프로젝트: ox1230/capl
def add_history(request: HttpRequest):
    form = HistoryForm()
    if request.method == 'POST':
        form = HistoryForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('main')

    return render(
        request, 'add_history.html', {
            'add_history_form': form,
            'category_json':
            Processing.get_informations_for_add_history()['json']
        })
예제 #6
0
파일: test_forms.py 프로젝트: ox1230/capl
    def test_form_item_input_has_css_classes(self):
        form = HistoryForm()

        self.assertIn('class="form-control input"', form.as_p())
        self.assertIn('select', form.as_p())
예제 #7
0
파일: test_forms.py 프로젝트: ox1230/capl
 def test_form_html(self):
     form = HistoryForm()
     self.fail(form.as_p())
예제 #8
0
    def test_data_for_add_history_visualization(self):
        """add_history를 위한 data rendering 하기:   {category이름: [assign,[20주치 residual 데이터]]순으로  }으로 되어야 한다. """
        cate1 = Category.objects.create(name="c1", assigned=10000)

        #이번주 순수 금액 추가
        form = HistoryForm(
            data={
                'category': cate1.id,
                'price': 2000,
                'written_date': date.today(),
                'name': 'h1'
            })
        form.save()

        form2 = HistoryForm(
            data={
                'category': cate1.id,
                'price': 21000,
                'written_date': date.today() + timedelta(days=-7),
                'name': 'h2',
                'halbu_week': 21
            })
        # 1주일 전것 추가\(할부 21주:   각주당 1000원)
        form2.save()

        form3 = HistoryForm(
            data={
                'category': cate1.id,
                'price': 10000,
                'written_date': date.today(),
                'name': 'h3',
                'halbu_week': 10
            })
        # (할부 10주:   각주당 1000원)
        form3.save()

        # show_history를 위한 데이터 얻기
        data = Processing.get_informations_for_add_history(today=date.today())

        json_data = data['json']

        expected_list = [6000]
        for i in range(9):
            expected_list.append(8000)
        for i in range(10):
            expected_list.append(9000)

        self.assertJSONEqual(json_data, {'c1': [10000, expected_list]})