Exemple #1
0
    def test_update_profile(self):
        """
        ユーザーのProfileを更新したとき、profile_updated Activityが発行される
        """
        profile = ProfileFactory()

        # Profileを更新する
        fields = {"place": "ネルフ本部", "birthday": datetime.date(2112, 9, 21), "url": "http://nerv.com/", "remarks": "ねむい"}
        activities = Activity.objects.get_for_object(profile.user)
        self.assertEqual(len(activities), 1)
        for field, value in fields.items():
            setattr(profile, field, value)
        profile.save()

        # Personaに対して、profile_updatedが発行されている
        activities = Activity.objects.get_for_object(profile.user)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, "profile_updated")

        # contextにフラグを含んでいる
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self._test_render(activities[0])

        # contextにprofileを含んでいる
        self.assertEqual(context["profile"], profile)
Exemple #2
0
    def test_update_profile(self):
        """
        ユーザーのProfileを更新したとき、profile_updated Activityが発行される
        """
        profile = ProfileFactory()

        # Profileを更新する
        fields = {
            'place': 'ネルフ本部',
            'birthday': datetime.date(2112, 9, 21),
            'url': 'http://nerv.com/',
            'remarks': 'ねむい',
        }
        activities = Activity.objects.get_for_object(profile.user)
        self.assertEqual(len(activities), 1)
        for field, value in fields.items():
            setattr(profile, field, value)
        profile.save()

        # Personaに対して、profile_updatedが発行されている
        activities = Activity.objects.get_for_object(profile.user)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, 'profile_updated')

        # contextにフラグを含んでいる
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self._test_render(activities[0])

        # contextにprofileを含んでいる
        self.assertEqual(context['profile'], profile)
Exemple #3
0
 def translate_snapshot(self, snapshot):
     # 可能な限り対象モデルに合わせたスナップショットを作成する
     try:
         mediator = registry.get(snapshot)
     except KeyError:
         mediator = super()
     return mediator.translate_snapshot(snapshot)
Exemple #4
0
    def test_render_comment_added(self):
        """
         render_activityでcomment_addedが正しく表示できる
        """
        target_object = CommentTestArticleFactory()
        ct = ContentType.objects.get_for_model(CommentTestArticle)
        pk = target_object.pk
        activity = ActivityFactory(content_type=ct, object_id=pk, status='comment_added')
        mediator = registry.get(activity)

        self.assertTrue(mediator.render(activity, Context()))
Exemple #5
0
    def test_render_comment_added(self):
        """
         render_activityでcomment_addedが正しく表示できる
        """
        target_object = CommentTestArticleFactory()
        ct = ContentType.objects.get_for_model(CommentTestArticle)
        pk = target_object.pk
        activity = ActivityFactory(content_type=ct,
                                   object_id=pk,
                                   status='comment_added')
        mediator = registry.get(activity)

        self.assertTrue(mediator.render(activity, {}))
Exemple #6
0
    def test_entry_is_published(self):
        draft_entry = EntryFactory(pub_state='draft')

        # draftなエントリーはActivityが作られない
        activities = Activity.objects.get_for_object(draft_entry)
        self.assertEqual(len(activities), 0)

        draft_entry.pub_state = 'public'
        draft_entry.save()

        activities = Activity.objects.get_for_object(draft_entry)
        activity = activities[0]
        self.assertEqual(activity.status, 'updated')
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self.assertTrue(
            'published' in context,
            'context variable published is not contained'
        )
        mediator = registry.get(activity)
        rendered = mediator.render(activity, Context())
        self.assertTrue('公開されました' in rendered)
Exemple #7
0
    def test_entry_is_published(self):
        draft_entry = EntryFactory(pub_state='draft')

        # draftなエントリーはActivityが作られない
        activities = Activity.objects.get_for_object(draft_entry)
        self.assertEqual(len(activities), 0)

        draft_entry.pub_state = 'public'
        draft_entry.save()

        activities = Activity.objects.get_for_object(draft_entry)
        activity = activities[0]
        self.assertEqual(activity.status, 'updated')
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self.assertTrue(
            'published' in context,
            'context variable published is not contained'
        )
        mediator = registry.get(activity)
        rendered = mediator.render(activity, {})
        self.assertTrue('公開されました' in rendered)
Exemple #8
0
    def _test_comment_added(self):
        """
        commentしたときに、comment_addedが発行される
        """
        nactivities = Activity.objects.get_for_object(self.object).count()

        # コメントをする
        comment = CommentFactory(content_object=self.object)

        mediator = registry.get(self.object)
        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(nactivities + 1, activities.count())

        activity = activities[0]
        self.assertEqual(activity.status, 'comment_added')
        self.assertEqual(activity.snapshot, self.object)
        # remarksにコメントのpkが入る
        self.assertEqual(activity.remarks, str(comment.pk))

        self._test_render(activity)
        mediator = registry.get(activity)
        context = mediator.prepare_context(activity, Context())
        self.assertTrue('comment' in context,
                        "context doesn't contain 'comment'")
Exemple #9
0
    def _test_partial_update(self, context_names=(), **fields):
        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(len(activities), 1)
        for field, value in fields.items():
            setattr(self.object, field, value)
        self.object.save()

        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, 'updated')
        mediator = registry.get(activity)
        context = {}
        context = mediator.prepare_context(activity, context)
        for name in context_names:
            self.assertTrue(
                name in context,
                'context variable {} is not contained'.format(name))

        self._test_render(activities[0])
Exemple #10
0
    def _test_partial_update(self, context_names = (), **fields):
        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(len(activities), 1)
        for field, value in fields.items():
            setattr(self.object, field, value)
        self.object.save()

        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, 'updated')
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        for name in context_names:
            self.assertTrue(
                name in context,
                'context variable {} is not contained'.format(name)
            )

        self._test_render(activities[0])
Exemple #11
0
    def test_url_release_added(self):
        """
        URLReleaseを追加したときに、release_addedが発行される
        """
        nactivities = Activity.objects.get_for_object(self.object).count()

        # URLReleaseを作る
        release = URLReleaseFactory(product=self.object)

        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(nactivities + 1, activities.count())

        activity = activities[0]
        self.assertEqual(activity.status, 'release_added')
        self.assertEqual(activity.snapshot, self.object)
        # remarksにリリースのapp_label,model,pkが入る
        remarks = 'products,urlrelease,{}'.format(release.pk)
        self.assertEqual(activity.remarks, remarks)

        self._test_render(activity)
        mediator = registry.get(activity)
        context = mediator.prepare_context(activity, Context())
        self.assertIn('release', context, "context doesn't contain 'release'")
Exemple #12
0
    def test_account_added(self):
        """
        アカウントを作成したとき、ユーザーに対してaccount_added Activityが
        発行される
        """

        # アカウントを作る
        account = AccountFactory()

        # Personaに対して、profile_updatedが発行されている
        activities = Activity.objects.get_for_object(account.profile.user)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, "account_added")

        # activityのremarksにアカウントのpkが設定されている
        self.assertEqual(activity.remarks, str(account.pk))

        # contextにaccount, serviceを含んでいる
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self.assertEqual(context["account"], account)
        self.assertEqual(context["service"], account.service)
Exemple #13
0
    def test_screenshot_added(self):
        """
        Screenshotを追加したときに、screenshot_addedが発行される
        """
        nactivities = Activity.objects.get_for_object(self.object).count()

        # Screenshotを作る
        ss = ScreenshotFactory(product=self.object)

        activities = Activity.objects.get_for_object(self.object)
        self.assertEqual(nactivities + 1, activities.count())

        activity = activities[0]
        self.assertEqual(activity.status, 'screenshot_added')
        self.assertEqual(activity.snapshot, self.object)
        # remarksにスクリーンショットのpkが入る
        remarks = str(ss.pk)
        self.assertEqual(activity.remarks, remarks)

        self._test_render(activity)
        mediator = registry.get(activity)
        context = mediator.prepare_context(activity, Context())
        self.assertIn('screenshot', context,
                      "context doesn't contain 'screenshot'")
Exemple #14
0
    def test_account_added(self):
        """
        アカウントを作成したとき、ユーザーに対してaccount_added Activityが
        発行される
        """

        # アカウントを作る
        account = AccountFactory()

        # Personaに対して、profile_updatedが発行されている
        activities = Activity.objects.get_for_object(account.profile.user)
        self.assertEqual(len(activities), 2)
        activity = activities[0]
        self.assertEqual(activity.status, 'account_added')

        # activityのremarksにアカウントのpkが設定されている
        self.assertEqual(activity.remarks, str(account.pk))

        # contextにaccount, serviceを含んでいる
        mediator = registry.get(activity)
        context = Context()
        context = mediator.prepare_context(activity, context)
        self.assertEqual(context['account'], account)
        self.assertEqual(context['service'], account.service)
Exemple #15
0
 def _test_render(self, activity):
     mediator = registry.get(activity)
     self.assertTrue(mediator.render(activity, Context()))