Ejemplo n.º 1
0
 def test_strings(self):
     unicode_username = u"åß∂ƒ©˙∆˚"
     self.user.username = unicode_username
     self.user.save()
     score = UserScore(user=self.user, score=10)
     self.assertIsNotNone(unicode(score))
     self.assertIsNotNone(str(score))
     self.assertIsNotNone(repr(score))
     score.save()
     self.assertIsNotNone(unicode(score))
     self.assertIsNotNone(str(score))
     self.assertIsNotNone(repr(score))
Ejemplo n.º 2
0
 def test_defaults(self):
     score = UserScore(user=self.user)
     self.assertEqual(score.user, self.user)
     self.assertEqual(score.timestamp, None)
     self.assertEqual(score.score, -1)
     self.assertEqual(score.reason, "")
     self.assertEqual(score.source, "")
     self.assertEqual(score.group, UserScore.GROUP_UNKNOWN)
     score.save()
     self.assertIsNotNone(score.timestamp)
     # confirm that the group is recalculated correctly
     score.score = 1
     score.save()
     self.assertEqual(score.group, UserScore.GROUP_DETRACTOR)
Ejemplo n.º 3
0
class FunctionTests(TransactionTestCase):

    """Test suite for misc functions."""

    def setUp(self):
        self.factory = RequestFactory()
        self.user = get_user_model().objects.create_user('zoidberg')
        self.score = UserScore(user=self.user, score=10).save()

    def test_display_to_user(self):
        request = self.factory.get('/')
        request.user = self.user
        with mock.patch('net_promoter_score.settings.NPS_DISPLAY_FUNCTION', lambda r: True):
            self.assertTrue(show_nps(request))
        with mock.patch('net_promoter_score.settings.NPS_DISPLAY_FUNCTION', lambda r: False):
            self.assertFalse(show_nps(request))

    def test_default_display_function(self):
        # test that the default function behaves as expected
        request = self.factory.get('/')
        request.user = self.user
        interval_func = UserScore.objects.days_since_user_score
        self.assertEqual(interval_func(self.user), 0)
        self.assertEqual(NPS_DISPLAY_INTERVAL, 30)

        # 0 days since survey - don't show
        self.assertFalse(default_display_function(request))

        # 30 days since survey - don't show
        self.score.timestamp = self.score.timestamp - datetime.timedelta(days=30)
        self.score.save()
        self.assertFalse(interval_func(self.user) > NPS_DISPLAY_INTERVAL)
        self.assertFalse(default_display_function(request))

        # 31 days since survey - *do* show
        self.score.timestamp = self.score.timestamp - datetime.timedelta(days=31)
        self.score.save()
        self.assertTrue(interval_func(self.user) > NPS_DISPLAY_INTERVAL)
        self.assertTrue(default_display_function(request))

        # never been surveyed - *do* show
        self.score.delete()
        self.assertEqual(interval_func(self.user), -1)
        self.assertTrue(default_display_function(request))