Exemplo n.º 1
0
    def handle(self, *args, **options):
        for dish_count in DISH_COUNTS:

            pub_date = fake.date_time_this_year(before_now=True,
                                                after_now=False,
                                                tzinfo=tzinfo)
            mod_date = pub_date
            if random.random() < 0.4:
                mod_date = fake.date_time_between(start_date=pub_date,
                                                  end_date='now',
                                                  tzinfo=tzinfo)

            card = MenuCardFactory(pub_date=pub_date, mod_date=mod_date)
            DishFactory.create_batch(dish_count, menucard=card)
Exemplo n.º 2
0
    def test_index_view_with_no_menucards(self):
        m = MenuCardFactory()
        for x in range(5):
            DishFactory(menucard=m)

        response = client.get(m.get_absolute_url())

        self.assertEqual(response.status_code, 200)
Exemplo n.º 3
0
    def test_dish_objects_are_created(self):
        """
        Test that calling factory results in new objects.
        """
        for x in range(13):
            DishFactory()

        self.assertEqual(Dish.objects.all().count(), 13)
Exemplo n.º 4
0
    def test_index_view_with_two_normal_menucards(self):
        """
        If there are two non-empty menucards, both are displayed.
        """
        m = MenuCardFactory(name='menu 1')
        n = MenuCardFactory(name='menu 2')
        for x in range(5):
            DishFactory(menucard=m)
        for x in range(5):
            DishFactory(menucard=n)

        response = self.client.get(reverse('karty:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, m.name)
        self.assertContains(response, n.name)
        self.assertQuerysetEqual(response.context['page'],
                                 ['<MenuCard: menu 1>', '<MenuCard: menu 2>'])
        self.assertEqual(response.context['prev_qstring'], '')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 5
0
    def test_ordering_index_by_name(self):
        """
        Check that menucards are ordered by name when 'name' is passed in query
        """
        m = MenuCardFactory(name='menu 3')
        n = MenuCardFactory(name='menu 2')
        o = MenuCardFactory(name='menu 1')
        for x in range(2):
            DishFactory(menucard=m)
        DishFactory(menucard=n)
        for x in range(3):
            DishFactory(menucard=o)

        response = self.client.get(reverse('karty:index') + '?ordering=name')
        self.assertEqual(response.status_code, 200)
        self.assertQuerysetEqual(
            response.context['page'],
            ['<MenuCard: menu 1>', '<MenuCard: menu 2>', '<MenuCard: menu 3>'])
        self.assertEqual(response.context['prev_qstring'], '')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 6
0
    def test_index_pagination_last_page_many_menucards(self):
        """
        On last page with many menucards there should be:
        * previous page link
        * no next page link
        """
        for x in range(25):
            m = MenuCardFactory()
            DishFactory(menucard=m)

        response = self.client.get(reverse('karty:index') + '?page=3')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['prev_qstring'], '?page=2')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 7
0
    def test_index_view_with_one_normal_menucard(self):
        """
        If there's one menucard with dishes, it is displayed.
        """
        m = MenuCardFactory()
        for x in range(5):
            DishFactory(menucard=m)

        response = self.client.get(reverse('karty:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, m.name)
        self.assertQuerysetEqual(response.context['page'],
                                 ['<MenuCard: %s>' % m.name])
        self.assertEqual(response.context['prev_qstring'], '')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 8
0
    def test_index_view_with_one_normal_one_empty_menucard(self):
        """
        If two menucards exist, only the one with dishes is displayed.
        """
        m = MenuCardFactory(name='menu 1')
        n = MenuCardFactory(name='menu 2')
        for x in range(5):
            DishFactory(menucard=m)

        response = self.client.get(reverse('karty:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, m.name)
        self.assertNotContains(response, n.name)
        self.assertQuerysetEqual(response.context['page'],
                                 ['<MenuCard: menu 1>'])
        self.assertEqual(response.context['prev_qstring'], '')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 9
0
    def test_destroy_app_data(self):
        """
        All objects from the 'karty' app should be gone.
        """
        for x in range(4):
            MenuCardFactory()

        self.assertEqual(MenuCard.objects.all().count(), 4)

        for y in range(7):
            DishFactory()

        self.assertEqual(Dish.objects.all().count(), 7)

        args = []
        kwargs = {}
        call_command('destroy_app_data', *args, **kwargs)

        self.assertEqual(MenuCard.objects.all().count(), 0)
        self.assertEqual(Dish.objects.all().count(), 0)