Esempio n. 1
0
 def test_achievement_post_image(self):
     # 画像を投稿した時に実績が追加されている事を確認
     image = open(self.absolute_pathname_src)
     sc.access_timeline_post_view(self.client, lecture_id=1, image=image)
     j_achieve = get_achevements_from_db()
     self.assertDictEqual({a['name']: a['point'] for a in j_achieve},
                          {'upload_image': 10, 'one_post': 1})
Esempio n. 2
0
 def test_post_to_latest(self):
     # 最新のタイムラインに投稿
     sc.access_timeline_post_view(
         self.client, lecture_id=1, body=u'3rd post')
     timeline = get_timeline_from_db(lecture_id=1)
     # NOTE: タイムラインは仮想タイムスタンプの順にソートされる
     self.assertListSorted(timeline[0]['id'],
                           timeline[1]['id'],
                           timeline[2]['id'])
Esempio n. 3
0
    def test_achievement_self_insert(self):
        # 自分で投稿を挿入した場合はpost_inserted実績はつかない
        sc.access_timeline_post_view(self.client_self, lecture_id=1,
                                     body='1.5th post',
                                     before_virtual_ts=135044899528200600,
                                     after_virtual_ts=135044902317511100)

        j_achieve = get_achevements_from_db(user_pk=1)
        self.assertDictEqual(
            {a['name']: a['point'] for a in j_achieve},
            {'one_post': 1})
Esempio n. 4
0
 def test_post_to_between_posts(self):
     # 2つのPOSTの中間の仮想タイムスタンプを指定
     sc.access_timeline_post_view(
         self.client, lecture_id=1, body=u'1.5th post',
         before_virtual_ts=135044899528200600,
         after_virtual_ts=135044902317511100)
     timeline = get_timeline_from_db(lecture_id=1)
     # 仮想タイムスタンプと投稿ID(通し番号)の順番が異なる
     self.assertListSorted(timeline[0]['id'],
                           timeline[2]['id'],
                           timeline[1]['id'])
Esempio n. 5
0
    def test_achievement_post_inserted(self):
        # 投稿が挿入された時に実績が追加されている事を確認
        sc.access_timeline_post_view(self.client, lecture_id=1,
                                     body='1.5th post',
                                     before_virtual_ts=135044899528200600,
                                     after_virtual_ts=135044902317511100)

        # 挿入された側
        j_achieve = get_achevements_from_db(user_pk=1)
        self.assertDictEqual(
            {a['name']: a['point'] for a in j_achieve},
            {'post_inserted': 10})
Esempio n. 6
0
    def test_achievement_consecutive_post(self):
        # make a post just now
        testuser = User.objects.get(pk=1)
        lecture = Lecture.objects.get(pk=1)
        Post.objects.create(body='First Post', added_by=testuser,
                            lecture=lecture, virtual_ts=135044899528200600)

        # post to timeline
        sc.access_timeline_post_view(self.client, lecture_id=1,
                                     body='Second Post')
        # there is achievement 'consecutive_post'
        j_after = get_achevements_from_db()
        self.assertSetEqual(set([a['name'] for a in j_after]),
                            set(['consecutive_post', 'one_post']))
Esempio n. 7
0
 def test_post_invalid_vts(self):
     # 整数値でなければBad Request
     j_invalid_vts = sc.access_timeline_post_view(
         self.client, lecture_id=1, body=u'投稿できないよ!',
         before_virtual_ts='invalid vts',
         after_virtual_ts='invalid vts')
     self.assertEqual(j_invalid_vts['status'], 'Bad Request')
Esempio n. 8
0
    def test_achievement_not_consecutive_post(self):
        # make a post before 5 minutes
        testuser = User.objects.get(pk=1)
        lecture = Lecture.objects.get(pk=1)
        post_before = Post.objects.create(
            body='First Post', added_by=testuser, lecture=lecture,
            virtual_ts=135044899528200600)
        before_5 = datetime.datetime.now() - datetime.timedelta(minutes=5)
        post_before.posted_at = before_5
        post_before.save()

        # post to timeline
        sc.access_timeline_post_view(self.client, lecture_id=1,
                                     body='Second Post')
        # there is not achievement 'consecutive_post'
        j_after = get_achevements_from_db()
        self.assertListEqual([a['name'] for a in j_after], ['one_post'])
Esempio n. 9
0
    def test_get_invalid_lecture_id(self):
        # 整数値でなければBad Request
        j_invalid_lecture_id_get = sc.access_timeline_get_view(
            self.client, lecture_id='invalid lecture_id')
        self.assertEqual(j_invalid_lecture_id_get['status'], 'Bad Request')

        j_invalid_lecture_id_post = sc.access_timeline_post_view(
            self.client, lecture_id='invalid lecture_id',
            body=u'投稿できないよ!')
        self.assertEqual(j_invalid_lecture_id_post['status'], 'Bad Request')
Esempio n. 10
0
    def test_post_image(self):
        image = open(self.absolute_pathname_src)
        j_post_image = sc.access_timeline_post_view(
            self.client, lecture_id=1, image=image)

        # image_urlが適切に設定されていることを確認
        image_url = j_post_image['post']['image_url']
        ptn = re.compile('http://.+/site_media/uploads/img_(\d)')
        img_id = int(ptn.match(image_url).group(1))
        self.assertEqual(img_id, j_post_image['post']['id'])

        # 画像がちゃんと保存されていることを確認
        self.assertTrue(os.path.exists(self.absolute_pathname))
Esempio n. 11
0
 def test_achievement_easter_egg(self):
     sc.access_timeline_post_view(self.client, lecture_id=1,
         body=u'՞ਊ ՞')
     j_after = get_achevements_from_db()
     self.assertDictEqual({a['name']: a['point'] for a in j_after},
                          {'one_post': 1, 'easter_egg': 3})
Esempio n. 12
0
 def test_achievement_upload_url(self):
     sc.access_timeline_post_view(self.client, lecture_id=1,
         body='Google it: https://www.google.com/')
     j_after = get_achevements_from_db()
     self.assertDictEqual({a['name']: a['point'] for a in j_after},
                          {'one_post': 1, 'upload_url': 2})
Esempio n. 13
0
 def test_achievement_one_post(self):
     sc.access_timeline_post_view(self.client, lecture_id=1, body='Hello')
     j_after = get_achevements_from_db()[0]
     self.assertEqual(j_after['point'], 1)
Esempio n. 14
0
 def test_timeline_post__not_found(self):
     j_post_not = sc.access_timeline_post_view(self.client, lecture_id=42,
         body=u'チャドの授業が・・・消えた・・・?')
     self.assertEqual(j_post_not['status'], 'Not Found')
Esempio n. 15
0
 def test_timeline_post_without_auth(self):
     j_post_fbd = sc.access_timeline_post_view(self.client, lecture_id=1,
         body=u'認証が切れたら、俺は投稿もできないのかよ')
     self.assertEqual(j_post_fbd['status'], 'Forbidden')
Esempio n. 16
0
 def test_post_only_after_vts(self):
     j_only_after = sc.access_timeline_post_view(self.client, lecture_id=1,
         body=u'投稿できないよ!', after_virtual_ts=65536)
     self.assertEqual(j_only_after['status'], 'Bad Request')
Esempio n. 17
0
 def test_post_only_before_vts(self):
     # before_virtual_ts, after_virtual_ts 片方だけだと Bad Request
     j_only_before = sc.access_timeline_post_view(self.client, lecture_id=1,
         body=u'投稿できないよ!', before_virtual_ts=65536)
     self.assertEqual(j_only_before['status'], 'Bad Request')