コード例 #1
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
 def test_next_url(self):
     """
     Verifies that the tour manager's next url method works
     """
     self.assertIsNone(Tour.objects.get_next_url(self.test_user))
     MockTour.add_user(self.test_user)
     self.assertEqual("mock1", Tour.objects.get_next_url(self.test_user))
コード例 #2
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
 def test_nested_tour(self):
     """
     Verifies that records get created properly for nested tours
     """
     MockTour.create()
     MockTour2.create()
     self.assertEqual(4, Step.objects.all().count())
     steps = list(Step.objects.all().order_by("id"))
     self.assertEqual(steps[0].parent_step, None)
     self.assertEqual(steps[1].parent_step, None)
     self.assertEqual(steps[2].parent_step, steps[0])
     self.assertEqual(steps[3].parent_step, steps[0])
コード例 #3
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
    def test_delete(self):
        """
        Verifies that a tour and its steps get deleted
        """
        MockTour.create()
        MockTour2.create()
        self.assertEqual(1, Tour.objects.count())
        self.assertEqual(4, Step.objects.count())

        MockTour2.delete()
        self.assertEqual(1, Tour.objects.count())
        self.assertEqual(2, Step.objects.count())

        MockTour.delete()
        self.assertEqual(0, Tour.objects.count())
        self.assertEqual(0, Step.objects.count())
コード例 #4
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
    def test_url_list(self):
        """
        Verifies that the tour builds the url list correctly
        """
        # Create the tours
        MockTour.create()
        MockTour2.create()

        # Add a user
        MockTour.add_user(self.test_user)

        # Fetch the tour
        tour_class = Tour.objects.get_for_user(self.test_user)

        urls = tour_class.get_url_list()
        expected_urls = ["mock1", "mock3", "mock4", "mock2"]
        self.assertEqual(expected_urls, urls)
コード例 #5
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
    def test_url(self):
        """
        Verifies that the tour returns the correct next url
        """
        # Create the tours
        MockTour.create()
        MockTour2.create()

        # Add a user
        MockTour.add_user(self.test_user)

        # Fetch the tour
        tour_class = Tour.objects.get_for_user(self.test_user)

        # Get the url
        url = tour_class.get_next_url()
        self.assertEqual("mock1", url)

        MockStep1.complete = True
        tour_class = Tour.objects.get_for_user(self.test_user)
        url = tour_class.get_next_url()
        self.assertEqual("mock3", url)

        MockStep3.complete = True
        tour_class = Tour.objects.get_for_user(self.test_user)
        url = tour_class.get_next_url()
        self.assertEqual("mock4", url)

        MockStep4.complete = True
        tour_class = Tour.objects.get_for_user(self.test_user)
        url = tour_class.get_next_url()
        self.assertEqual("mock2", url)

        MockStep2.complete = True
        tour_class = Tour.objects.get_for_user(self.test_user)
        self.assertIsNone(tour_class)

        # Check that no url is returned for a complete tour
        Tour.objects.all().delete()
        Step.objects.all().delete()
        CompleteTour.add_user(self.test_user)
        tour_class = Tour.objects.get().load_tour_class()
        self.assertTrue(tour_class.is_complete())
        url = tour_class.get_next_url()
        self.assertIsNone(url)
コード例 #6
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
    def test_create(self):
        """
        Verifies that the tour gets created only once
        """
        # Create a single tour
        MockTour.create()
        self.assertEqual(1, Tour.objects.all().count())
        self.assertEqual(len(MockTour.steps), Step.objects.all().count())

        # Try to create a duplicate
        MockTour.create()
        self.assertEqual(1, Tour.objects.all().count())
        self.assertEqual(len(MockTour.steps), Step.objects.all().count())

        # Create a tour with a parent and make sure only the steps get added to the parent tour
        MockTour2.create()
        self.assertEqual(1, Tour.objects.count())
        self.assertEqual(4, Step.objects.count())
コード例 #7
0
    def test_tour_tag(self):
        """
        Verifies that a tour gets displayed when a user has a tour
        """
        # Verifies that the tour template does not get rendered without a user
        MockTour.create()
        test_template = Template('{% load tour_tags %}{% tour_navigation %}')
        context = Context({
            'request': MockRequest(User(), '/mock/path'),
        })
        self.assertEqual('', test_template.render(context))

        # Verifies that the tour template does not get rendered if a user doesn't have a tour
        self.login_user1()
        context = Context({
            'request': MockRequest(self.test_user, '/mock/path'),
        })
        self.assertEqual('', test_template.render(context).strip())

        # Verifies that the tour template does get rendered if a user has a tour
        MockTour.add_user(self.test_user)
        test_template = Template('{% load tour_tags %}{% tour_navigation %}')
        context = Context({
            'request': MockRequest(self.test_user, '/mock/path'),
        })
        self.assertTrue('tour-wrap' in test_template.render(context))

        # Verify that the current class gets applied
        context = Context({
            'request': MockRequest(self.test_user, 'mock1'),
        })
        self.assertTrue('current' in test_template.render(context))

        # Verify that the complete class gets applied
        MockStep1.complete = True
        context = Context({
            'request': MockRequest(self.test_user, 'mock2'),
        })
        self.assertTrue('complete' in test_template.render(context))

        # Verify no errors for missing request object
        context = Context({})
        self.assertEqual('', test_template.render(context))
コード例 #8
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
    def test_user_functions(self):
        """
        Makes sure a tour is created when adding a user to a tour that doesn't exist
        Verifies that a user can be assigned a tour only once
        Tests fetching an active tour for a user
        """
        self.assertIsNone(Tour.objects.get_for_user(self.test_user))

        # Create a single tour
        MockTour.create()

        # Add a user
        MockTour.add_user(self.test_user)
        self.assertEqual(1, TourStatus.objects.all().count())

        # Delete all tours and make sure a tour is created when adding a user
        Tour.objects.all().delete()
        self.assertEqual(0, TourStatus.objects.all().count())
        MockTour.add_user(self.test_user)
        self.assertEqual(1, TourStatus.objects.all().count())

        # Try to add the user again
        MockTour.add_user(self.test_user)
        self.assertEqual(1, TourStatus.objects.all().count())

        # Fetch the tour
        tour_class = Tour.objects.get_for_user(self.test_user)
        self.assertIsNotNone(tour_class)

        # Set the tours as complete
        MockStep1.complete = True
        MockStep2.complete = True

        # Check if MockTour is complete
        tour_class = Tour.objects.get_for_user(self.test_user)
        self.assertIsNone(tour_class)

        # Make sure a second tour will be added
        MockTour.add_user(self.test_user)
        self.assertEqual(2, TourStatus.objects.all().count())
        self.assertEqual(1, TourStatus.objects.filter(complete=False).count())
コード例 #9
0
ファイル: api_tests.py プロジェクト: jmcriffey/django-tour
    def test_fetch_tour(self):
        self.login_user1()
        url = reverse('tour:api_dispatch_list', kwargs={'resource_name': 'tour', 'api_name': 'api'})
        MockTour.create()

        # Make sure there are no tour objects returned
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(0, len(objects))

        # Make sure there is one tour object returned
        MockTour.add_user(self.test_user)
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(1, len(objects))

        # Create a tour for a second user and make sure only the one tour is returned
        MockTour.add_user(self.test_user2)
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(1, len(objects))

        # Complete the tour for user 1
        MockStep1.complete = True
        MockStep2.complete = True
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(0, len(objects))

        # Log in as user 2 and make sure there is still a tour
        self.login_user2()
        MockStep1.complete = False
        MockStep2.complete = False
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(1, len(objects))

        # Make sure a step with no url is ignored
        tour = Tour.objects.get()
        NoUrlStep.create(tour)
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        json_response = json.loads(response.content)
        objects = json_response.get('objects')
        self.assertEqual(len(MockTour.steps), len(objects[0].get('steps')))
コード例 #10
0
ファイル: tour_tests.py プロジェクト: jmcriffey/django-tour
 def test_mark_complete(self):
     """
     Verifies that tours get marked as complete per user or for all users
     """
     MockTour.add_user(self.test_user)
     MockTour.add_user(self.test_user2)
     self.assertEqual(2, TourStatus.objects.filter(complete=False).count())
     tour_class = Tour.objects.get_for_user(self.test_user)
     tour_class.mark_complete(user=self.test_user)
     self.assertEqual(1, TourStatus.objects.filter(complete=False).count())
     MockTour.add_user(self.test_user)
     self.assertEqual(2, TourStatus.objects.filter(complete=False).count())
     tour_class = Tour.objects.get().load_tour_class()
     tour_class.mark_complete()
     self.assertEqual(0, TourStatus.objects.filter(complete=False).count())