Example #1
0
 def test_slug_line_creation(self):
     """ slug_line_creation expects a category to be given an appropriate
         slug. Eg: "Random Category String" -> "random-category-string"
     """
     cat = Category(name="Random Category String")
     cat.save()
     self.assertEqual(cat.slug, "random-category-string")
Example #2
0
 def test_ensure_views_are_positive(self):
     """ ensure_views_are_positive expects a category initiated with
         negative views to still have non-negative views after saving
     """
     cat = Category(name='test', views=-1, likes=0)
     cat.save()
     self.assertEqual((cat.views >= 0), True)
Example #3
0
	def test_ensure_last_visit_equal_after_first_visit(self):
		cat = Category(name='test')
		cat.save()
		t1 = timezone.now()
		t2 = timezone.now() + datetime.timedelta(days=30)
		pag = Page(category=cat, first_visit=t1, last_visit=t2)
		self.assertEqual(pag.is_last_visit_equal_after_first_visit(), True)
Example #4
0
 def test_ensure_views_are_positive(self):
     '''
     ensure_views_are_positive should results True for categories where views are zero or positive
     '''
     cat = Category(name='test', views=-1, likes=0)
     cat.save()
     self.assertEqual((cat.views>=0), True)
Example #5
0
    def test_create_pages_for_categories(self):
        cat = Category(name="Python")
        cat.save()

        # create 2 pages for category python
        python_page = Page()
        python_page.category = cat
        python_page.title="Official Python Tutorial"
        python_page.url="http://docs.python.org/2/tutorial/"
        python_page.save()

        django_page = Page()
        django_page.category = cat
        django_page.title="Django"
        django_page.url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/"
        django_page.save()

        # Check if they both were saved
        python_pages = cat.page_set.all()
        self.assertEquals(python_pages.count(), 2)

        #Check if they were saved properly
        first_page = python_pages[0]
        self.assertEquals(first_page, python_page)
        self.assertEquals(first_page.title , "Official Python Tutorial")
        self.assertEquals(first_page.url, "http://docs.python.org/2/tutorial/")
Example #6
0
    def test_add_category_that_already_exists(self):
        # Create a category in database
        new_category = Category(name="New Category")
        new_category.save()

        # Access index page
        self.browser.get(self.live_server_url + reverse('index'))

        # Check if is there link to add categories
        categories_link = self.browser.find_elements_by_partial_link_text('Add a New Category')
        categories_link[0].click()

        # Types new category name
        username_field = self.browser.find_element_by_name('name')
        username_field.send_keys('New Category')

        # Click on Create Category
        self.browser.find_element_by_css_selector(
            "input[type='submit']"
        ).click()

        body = self.browser.find_element_by_tag_name('body')

        # Check if there is an error message
        self.assertIn('Category with this Name already exists.', body.text)
Example #7
0
 def test_first_visit_before_last_visit(self):
     cat = Category(name='test')
     cat.save()
     firstdate = datetime.date.today() + datetime.timedelta(days=-3)
     lastdate = datetime.date.today() + datetime.timedelta(days=-5)
     p=add_page (cat, 'first_future', 'www.exemple.it', first_visit=firstdate, last_visit = lastdate)
     self.assertEqual(p.first_visit, p.last_visit)
Example #8
0
 def test_ensure_views_are_positive(self):
     """
     category.view number is zero or positive, it shall never be negative
     """
     cat = Category(name='test', views=-1, likes=0)
     cat.save()
     self.assertEqual((cat.views >= 0), True)
Example #9
0
 def test_first_visit_not_future(self):
     cat = Category(name='test')
     cat.save()
     futuredate = datetime.date.today() + datetime.timedelta(days=30)
     p=add_page (cat, 'first_future', 'www.exemple.it', first_visit=futuredate, last_visit = futuredate)
     self.assertEqual(p.first_visit, datetime.date.today())
     self.assertEqual(p.last_visit, datetime.date.today())
Example #10
0
    def test_page_views_should_be_nonnegative(self):

        category = Category()
        category.save()
        page = Page(category=category, title='test page', views=-100)
        page.save()
        self.assertTrue(page.views >= 0)
Example #11
0
    def test_ensure_views_are_positive(self):

        cat = Category(name='test',views=-1,likes=0)
        cat.save()
        print 'views', cat.views

        self.assertEqual((cat.views>=0), True)
Example #12
0
 def test_ensure_views_are_positive(self):
     """
     ensure_views_are_positive should return True for categories
     where views are zero or positive
     """
     cat = Category(name="test", views=-1, likes=0)
     cat.save()
     self.assertEqual((cat.views >= 0), True)
Example #13
0
 def test_slug_line_creation(self):
     """
     slug_line_creation checks to make sure that when we add a category an appropiate slug line is created
     i.e. "Random Category String" -> "random-category-string"
     """
     cat = Category(name="Random Category String", views=0, likes=0)
     cat.save()
     self.assertEqual(cat.slug, 'random-category-string')
Example #14
0
    def test_ensure_views_are_positive(self):

        """
                функция ensure_views_are_positive должна возвращать True для категорий, у которых число просмотров равно нулю или положительное
        """
        cat = Category(name='test',views=-1, likes=0)
        cat.save()
        self.assertEqual((cat.views >= 0), False)
Example #15
0
    def test_category_contains(self):
        """
        test_category_contains tests whether the save() function is working correctly.
        """

        category = Category(name='test', views=21, likes=21)
        category.save()
        self.assertEqual(Category.objects.filter(pk=category.pk).exists(), True)
Example #16
0
 def test_ensure_likes_are_positive(self):
     """
     ensure_likes_are_positive should results True for categories
     where likes are zero or positive
     """
     cat = Category(name='test', views=0, likes=-1)
     cat.save()
     self.assertEqual((cat.likes >= 0), True)
Example #17
0
    def test_create_a_new_category(self):
        cat = Category(name="Python")
        cat.save()

        # Check category is in database
        categories_in_database = Category.objects.all()
        self.assertEquals(len(categories_in_database), 1)
        only_poll_in_database = categories_in_database[0]
        self.assertEquals(only_poll_in_database, cat)
 def test_ensure_views_are_positive(self):
     """
     确保views是正数或0
     :return:
     """
     from rango.models import Category
     cat = Category(name='test', views=-1, likes=0)
     cat.save()
     self.assertEqual((cat.views >= 0), True)
 def test_slug_line_createion(self):
     """
     测试slug
     :return:
     """
     from rango.models import Category
     cat = Category(name='Random Category String')
     cat.save()
     self.assertEqual(cat.slug, 'random-category-string')
Example #20
0
    def test_number_of_likes_is_nonnegative(self):
        """
        The test number_of_views_is_nonnegative should results True for categories where views 
        are zero or positive.
        """

        category = Category(name='test', views=-1, likes=-1)
        category.save()
        self.assertEqual((category.likes >= 0), True)
Example #21
0
    def test_slug_line_creation(self):
        """
        slug_line_creation checks to make sure that when we add a category, and approriate slug
        line is created
        """

        cat = Category(name='Random Category String')
        cat.save()
        self.assertEqual(cat.slug, 'random-category-string')
Example #22
0
 def test_slug_line_creation(self):
     """
     Checks to make sure that when category is added, appropriate
     slug line is created i.e.
     "Random Category String" -> "random-category-string"
     """
     cat = Category(name='Random Category String')
     cat.save()
     self.assertEqual(cat.slug, 'random-category-string')
Example #23
0
    def test_slug_line_creation(self):
        '''
        slug_line_creation checks to make sure that when we add a category an appropriate slug line is created
        i.e. "Random Category String" -> "random-category-string"
        '''

        cat = Category(name='Random Category String')
        cat.save()
        self.assertEqual(cat.slug, 'random-category-string')
Example #24
0
    def test_slug_line_creation(self):
        """
        When adding a category, a proper slug line is created.
        i.e. "Random Category String" -> "random-cateogry-string"
        """

        cat = Category(name='Random Category String')
        cat.save()
        self.assertEqual(cat.slug, 'random-category-string')
Example #25
0
 def test_last_visit_not_in_the_future(self):
     """
     Test to ensure the last_visit is not in the future
     """
     cat = Category(name='test',views=1, likes=0)
     cat.save()
     page, created = Page.objects.get_or_create(category=cat, title='test', 
             url="www.test.test", views=1, first_visit=timezone.now(), last_visit=timezone.now() - timezone.timedelta(hours=1))       
     page.save()
     self.assertTrue(page.last_visit < timezone.now(), "Last_visit is in the future")
Example #26
0
    def test_page_contains(self):
        """
        test_category_contains tests whether the save() function is working correctly.
        """

        category = Category()
        category.save()
        page = Page(category=category, title='test page', views=21)
        page.save()
        self.assertEqual(Page.objects.filter(pk=page.pk).exists(), True)
Example #27
0
	def test_last_visit_and_first_visit_validation(self):

		"""
		last_visit_and_first_visit_validation check both last_visit and first_visit are not in the future
		"""
		now = datetime.datetime.now()
		time_in_the_future = now + datetime.timedelta(hours=1)
		cat = Category(name='test')
		cat.save()
		page = Page(category=cat, title="test", url="http://www.test.com", last_visit=time_in_the_future, first_visit=time_in_the_future+datetime.timedelta(hours=2))
		page.save()
Example #28
0
def create_categories():
    # List of categories
    categories = []

    # Create categories from 0 to 7
    for i in xrange(1, 11):
        cat = Category(name="Category " + str(i), likes=i)
        cat.save()
        categories.append(cat)

    return categories
Example #29
0
    def test_category_with_no_pages(self):
        """
        This test checks that rango displays the correct message
        when no pages are present in a category with no pages.
        """

        category = Category(name='test')
        category.save()

        response = self.client.get(reverse('category', args=(category.slug,)))

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No pages currently in category.")
        
Example #30
0
def ajax(request):

    if request.method == "POST":
        category = Category()
        category.name = request.POST["name"]
        category.save()

    category_list = list(Category.objects.all())

    test_list = []
    for ii in category_list:
        test_list.append({
            "name":ii.name,
            })

    return HttpResponse(dumps(test_list), content_type='application/json')
Example #31
0
 def test_ensure_views_are_positive(self):
     cat = Category(name='test', views=-1, like=-1)
     cat.save()
     self.assertEqual((cat.views >= 0), True)