コード例 #1
0
    def test_set_leitner_record(self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '2')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category.id,
            'grasped_hanzi': json.dumps([u'东', u'西', u'冬']),   # 东 -> deck 1, 西 -> deck R, 冬 -> deck R
            'new_hanzi': json.dumps([u'李', u'南'])        # 南 -> deck C, new Hanzi, 李 -> deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).count, 2)
        self.assertEqual(Hanzi.objects.all().count(), 9)  # including 王 added during Setup
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, '1')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'西')).leitner_deck, 'R')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'李')).leitner_deck, 'C')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'南')).leitner_deck, 'C')
        for h in retired_hanzis:
            self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=h)).leitner_deck, 'R')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'南')).forget_count, 1)
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'东')).repeat_count, 1)
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'西')).repeat_count, 1)
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'李')).repeat_count, 0)  # 北 is new
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'南')).repeat_count, 1)
コード例 #2
0
    def test_set_leitner_record_add_existing_hanzi_to_another_category(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', '3')
        util.create_one_leitner_record(self.user, self.category, u'北', 'R')
        count = 12
        util.create_one_HanziStudyCount_instance(
            self.user, self.category2,
            count)  # 2 is the last number in deck '3'

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category2.id,
            'grasped_hanzi': json.dumps([]),
            'new_hanzi': json.dumps([u'东'])
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            HanziStudyCount.objects.get(user=self.user).count, count)
        self.assertEqual(Hanzi.objects.all().count(),
                         3)  # including 王 added during Setup
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                category=self.category,
                hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, '3')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                category=self.category2,
                hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, 'C')
コード例 #3
0
    def test_set_leitner_record_existing_hanzi_move_from_deck_C_to_progress_deck(
            self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'北', 'C')
        count = 12
        util.create_one_HanziStudyCount_instance(self.user, self.category,
                                                 count)  # irrelate setting

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category.id,
            'grasped_hanzi': json.dumps([]),
            'new_hanzi': json.dumps([u'东'])  # 东 stay deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            HanziStudyCount.objects.get(user=self.user).count, count)
        self.assertEqual(Hanzi.objects.all().count(),
                         3)  # including 王 added during Setup
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, 'C')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'北')).leitner_deck, 'C')
コード例 #4
0
    def test_set_leitner_record_response_404_when_without_category_parameter(
            self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '2')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'grasped_hanzi':
            json.dumps([u'东', u'西',
                        u'冬']),  # 东 -> deck 1, 西 -> deck R, 冬 -> deck R
            'new_hanzi':
            json.dumps([u'李', u'南'])  # 南 -> deck C, new Hanzi, 李 -> deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #5
0
    def setUp(self):
        self.username = '******'
        self.user = util.create_one_User_instance(self.username)
        self.client.force_authenticate(user=self.user)

        self.card = util.create_one_Card_instance()
        self.category = util.create_one_Category_instance(self.user, self.card.id, 'category')

        another_user = util.create_one_User_instance('another_user')
        another_category = util.create_one_Category_instance(another_user, self.card.id, 'another_category')
        util.create_one_HanziStudyCount_instance(another_user, another_category, 10)
コード例 #6
0
    def test_get_leitner_record_response_404_without_category_parameter(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #7
0
    def test_get_leitner_record_response_404_without_category_parameter(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #8
0
    def test_list(self):
        # arrange
        count = 3
        util.create_one_HanziStudyCount_instance(self.user, self.category, count)

        # act
        url = reverse('hanzistudycount-list')
        url += '?category_id={category_id}'.format(category_id=self.category.id)
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 1)
        self.assertEqual(response.data['results'][0]['count'], count)
コード例 #9
0
ファイル: testUserView.py プロジェクト: pz325/hornbook
    def test_get_one_User(self):
        # arrange
        count = 3
        util.create_one_HanziStudyCount_instance(self.user, self.category, count)
        hanzi = u'风'
        util.create_one_HanziStudyRecord_instance(self.user, self.category, hanzi)

        # act
        url = reverse('user-detail', args=[1])
        response = self.client.get(url)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['study_records']), 1)
        self.assertEqual(response.data['study_records'][0], 'http://testserver' + reverse('hanzistudyrecord-detail', args=[2]))
コード例 #10
0
    def test_get_leitner_record(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        url += '?category_id={category_id}'.format(category_id=self.category.id)
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
コード例 #11
0
    def test_list_without_category_parameter(self):
        # arrange
        count = 3
        categoryA = util.create_one_Category_instance(self.user, self.card.id, 'categoryA')
        categoryB = util.create_one_Category_instance(self.user, self.card.id, 'categoryB')

        util.create_one_HanziStudyCount_instance(self.user, categoryA, count)
        util.create_one_HanziStudyCount_instance(self.user, categoryB, count)

        # act
        url = reverse('hanzistudycount-list')
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 2)
コード例 #12
0
    def test_get_leitner_record(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        url += '?category_id={category_id}'.format(
            category_id=self.category.id)
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
コード例 #13
0
    def test_get_leitner_record_with_num_retired(self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        num_retired = 2
        url = reverse('hanzistudyrecord-list') + '/leitner_record?num_retired={num_retired}'.format(num_retired=num_retired)
        url += '&category_id={category_id}'.format(category_id=self.category.id)
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 4)  # two from deck R
コード例 #14
0
    def test_set_leitner_record_response_404_when_without_category_parameter(self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '2')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'grasped_hanzi': json.dumps([u'东', u'西', u'冬']),   # 东 -> deck 1, 西 -> deck R, 冬 -> deck R
            'new_hanzi': json.dumps([u'李', u'南'])        # 南 -> deck C, new Hanzi, 李 -> deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #15
0
    def test_set_leitner_record_existing_hanzi_move_from_deck_C_to_progress_deck(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'北', 'C')
        count = 12
        util.create_one_HanziStudyCount_instance(self.user, self.category, count)  # irrelate setting

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category.id,
            'grasped_hanzi': json.dumps([]),
            'new_hanzi': json.dumps([u'东'])  # 东 stay deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).count, count)
        self.assertEqual(Hanzi.objects.all().count(), 3)  # including 王 added during Setup
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, 'C')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, hanzi=Hanzi.objects.get(content=u'北')).leitner_deck, 'C')
コード例 #16
0
    def test_get_leitner_record_with_num_retired(self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '3')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        num_retired = 2
        url = reverse('hanzistudyrecord-list'
                      ) + '/leitner_record?num_retired={num_retired}'.format(
                          num_retired=num_retired)
        url += '&category_id={category_id}'.format(
            category_id=self.category.id)
        response = self.client.get(url, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 4)  # two from deck R
コード例 #17
0
    def test_set_leitner_record_add_existing_hanzi_to_another_category(self):
        # arrange
        util.create_one_leitner_record(self.user, self.category, u'东', '3')
        util.create_one_leitner_record(self.user, self.category, u'北', 'R')
        count = 12
        util.create_one_HanziStudyCount_instance(self.user, self.category2, count)   # 2 is the last number in deck '3'

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category2.id,
            'grasped_hanzi': json.dumps([]),
            'new_hanzi': json.dumps([u'东'])
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).count, count)
        self.assertEqual(Hanzi.objects.all().count(), 3)  # including 王 added during Setup
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, category=self.category, hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, '3')
        self.assertEqual(HanziStudyRecord.objects.get(user=self.user, category=self.category2, hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, 'C')
コード例 #18
0
    def test_delete_one(self):
        '''
        pk -- HanziStudyCount id
        '''
        # arrange
        count = 3
        study_count = util.create_one_HanziStudyCount_instance(self.user, self.category, count)

        # act
        url = reverse('hanzistudycount-detail', args=[study_count.id])
        response = self.client.delete(url)

        # assert
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(HanziStudyCount.objects.filter(user=self.user).count(), 0)
コード例 #19
0
    def test_get_one(self):
        '''
        pk -- HanziStudyCount id
        '''
        # arrange
        count = 3
        study_count = util.create_one_HanziStudyCount_instance(self.user, self.category, count)

        # act
        url = reverse('hanzistudycount-detail', args=[study_count.id])
        response = self.client.get(url)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], count)
        self.assertEqual(response.data['category'], self.category.id)
コード例 #20
0
    def test_put_one(self):
        '''
        pk -- HanziStudyCount id
        '''
        # arrange
        count = 3
        study_count = util.create_one_HanziStudyCount_instance(self.user, self.category, count)

        # act
        count = 6
        data = {'count': count}
        url = reverse('hanzistudycount-detail', args=[study_count.id])
        response = self.client.put(url, data=data, format='json')

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(HanziStudyCount.objects.filter(user=self.user).count(), 1)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).count, count)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).category.id, self.category.id)
コード例 #21
0
    def test_set_leitner_record(self):
        # arrange
        retired_hanzis = [u'北', u'春', u'夏', u'冬']
        util.create_one_leitner_record(self.user, self.category, u'东', 'C')
        util.create_one_leitner_record(self.user, self.category, u'南', '1')
        util.create_one_leitner_record(self.user, self.category, u'西', '2')
        for h in retired_hanzis:
            util.create_one_leitner_record(self.user, self.category, h, 'R')
        util.create_one_HanziStudyCount_instance(self.user, self.category, 1)

        # act
        url = reverse('hanzistudyrecord-list') + '/leitner_record'
        data = {
            'category_id': self.category.id,
            'grasped_hanzi':
            json.dumps([u'东', u'西',
                        u'冬']),  # 东 -> deck 1, 西 -> deck R, 冬 -> deck R
            'new_hanzi':
            json.dumps([u'李', u'南'])  # 南 -> deck C, new Hanzi, 李 -> deck C
        }

        response = self.client.post(url, data)

        # assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(HanziStudyCount.objects.get(user=self.user).count, 2)
        self.assertEqual(Hanzi.objects.all().count(),
                         9)  # including 王 added during Setup
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'东')).leitner_deck, '1')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'西')).leitner_deck, 'R')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'李')).leitner_deck, 'C')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'南')).leitner_deck, 'C')
        for h in retired_hanzis:
            self.assertEqual(
                HanziStudyRecord.objects.get(
                    user=self.user,
                    hanzi=Hanzi.objects.get(content=h)).leitner_deck, 'R')
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'南')).forget_count, 1)
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'东')).repeat_count, 1)
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'西')).repeat_count, 1)
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'李')).repeat_count,
            0)  # 北 is new
        self.assertEqual(
            HanziStudyRecord.objects.get(
                user=self.user,
                hanzi=Hanzi.objects.get(content=u'南')).repeat_count, 1)