Exemplo n.º 1
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.º 2
0
    def test_was_modified_in_near_future(self):
        """
        was_modifed() should return False for MenuCard
        whose mod_date is in the near future.
        """
        pub_date = timezone.now()
        mod_date = timezone.now() + datetime.timedelta(minutes=3)
        future_menucard = MenuCardFactory(pub_date=pub_date, mod_date=mod_date)

        self.assertIs(future_menucard.was_modified(), False)
Exemplo n.º 3
0
    def test_was_modified_few_minutes_after_publication(self):
        """
        was_modifed() should return False for MenuCard
        whose mod_date is within trivial period after publication.
        """
        pub_date = timezone.now() - datetime.timedelta(days=15)
        mod_date = pub_date + datetime.timedelta(minutes=3)

        past_menucard = MenuCardFactory(pub_date=pub_date, mod_date=mod_date)

        self.assertIs(past_menucard.was_modified(), False)
Exemplo n.º 4
0
    def test_was_modified_long_after_publication(self):
        """
        was_modifed() should return True for MenuCard
        whose mod_date is meanigful amount of time after publication.
        """
        pub_date = timezone.now() - datetime.timedelta(days=15)
        mod_date = pub_date + datetime.timedelta(minutes=36)

        past_menucard = MenuCardFactory(pub_date=pub_date, mod_date=mod_date)

        self.assertIs(past_menucard.was_modified(), True)
Exemplo n.º 5
0
    def test_index_view_with_two_empty_menucards(self):
        """
        If all menucards have no dishes, neither is displayed.
        """
        MenuCardFactory()
        MenuCardFactory()

        response = self.client.get(reverse('karty:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No menu cards are available")
        self.assertQuerysetEqual(response.context['page'], [])
        self.assertEqual(response.context['prev_qstring'], '')
        self.assertEqual(response.context['next_qstring'], '')
Exemplo n.º 6
0
    def test_menucard_objects_are_created(self):
        """
        Test that calling factory results in new objects.
        """
        for x in range(13):
            MenuCardFactory()

        self.assertEqual(MenuCard.objects.all().count(), 13)
Exemplo n.º 7
0
    def test_mod_date_is_assigned(self):
        """
        mod_date passed to the factory should be assigned to the object.
        """
        date = fake.date_time(tzinfo=tzinfo)
        menucard = MenuCardFactory(mod_date=date)

        self.assertEqual(menucard.mod_date, date) 
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_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.º 10
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.º 11
0
    def test_dish_name_is_unique(self):
        """
        Name field should be generated unique.
        """
        names = set()
        num_dishes = 800
        for x in range(num_dishes):
            dish = MenuCardFactory()
            names.add(dish.name)

        self.assertEqual(len(names), num_dishes)
Exemplo n.º 12
0
    def test_menucard_name_is_unique(self):
        """
        Name field should be generated unique.
        """
        names = set()
        num_menucards = 800
        for x in range(num_menucards):
            menucard = MenuCardFactory()
            names.add(menucard.name)

        self.assertEqual(len(names), num_menucards)
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
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)
Exemplo n.º 17
0
 def test_serializer_can_be_instantiated(self):
     for x in range(18):
         MenuCardFactory()