def get(self, request, *args, **kwargs): # 全データ all_data = Data.get_all_data() # 支払い方法リスト methods = Method.list() # 支払い方法ごとの残高 methods_bd = [] for m in methods: d = Data.get_method_data(all_data, m.pk) # 銀行はチェック済みだけ if m.pk == Method.get_bank().pk: d = Data.get_checked_data(d) methods_bd.append({ 'pk': m.pk, 'name': m.name, 'balance': Data.get_income_sum(d) - Data.get_outgo_sum(d), 'year': CheckedDate.get(m.pk).date.year, 'month': CheckedDate.get(m.pk).date.month, 'day': CheckedDate.get(m.pk).date.day }) return HttpResponse(json.dumps(methods_bd))
def test_post_guest(self): self.assertEqual(CheckedDate.get(2).date, date(2000, 1, 5)) unchecked_data = Data.get_unchecked_data(Data.get_all_data()) expects = [ '必需品1', 'スーパー', '計算外', '貯金', 'PayPayチャージ', '立替分1', '内部移動1', '内部移動2' ] self._assert_list(unchecked_data, expects) response = self.client.post(reverse('moneybook:checked_date'), { 'year': 2001, 'month': 2, 'day': 20, 'method': 2 }) self.assertEqual(response.status_code, 403) self.assertEqual(CheckedDate.get(2).date, date(2000, 1, 5)) unchecked_data = Data.get_unchecked_data(Data.get_all_data()) self._assert_list(unchecked_data, expects)
def test_post_missing_method(self): self.client.force_login(User.objects.create_user(self.username)) self.assertEqual(CheckedDate.get(2).date, date(2000, 1, 5)) unchecked_data = Data.get_unchecked_data(Data.get_all_data()) expects = [ '必需品1', 'スーパー', '計算外', '貯金', 'PayPayチャージ', '立替分1', '内部移動1', '内部移動2' ] self._assert_list(unchecked_data, expects) response = self.client.post(reverse('moneybook:checked_date'), { 'year': 2000, 'month': 1, 'day': 20 }) self.assertEqual(response.status_code, 400) self.assertEqual(CheckedDate.get(2).date, date(2000, 1, 5)) unchecked_data = Data.get_unchecked_data(Data.get_all_data()) self._assert_list(unchecked_data, expects)
def test_set(self): CheckedDate.set(1, date(2001, 1, 1)) self.assertEqual(CheckedDate.get(1).date, date(2001, 1, 1))
def test_get(self): self.assertEqual(CheckedDate.get(1).date, date(2000, 1, 2)) self.assertEqual(CheckedDate.get(2).date, date(2000, 1, 5)) self.assertEqual(CheckedDate.get(3).date, date(2000, 2, 2))