Esempio n. 1
0
 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))
Esempio n. 2
0
    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')))
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
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))
Esempio n. 6
0
    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())
Esempio n. 7
0
 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())