def test_delete_new(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости ++' news.text = 'Текст первой новости!!!' news.pub_date = timezone.now() news.category = category news.save() all_news = News.objects.all() self.assertEquals(len(all_news), 1) self.client.login(username='******', password='******') response = self.client.post('/admin/news/news/' + str(news.id) + '/delete/', { 'post':'yes' }, follow=True ) self.assertContains(response, 'успешно удален', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 0)
def test_edit_news(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости ++' news.text = 'Текст первой новости!!!' news.pub_date = timezone.now() news.category = category news.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/news/' + str(news.id) + '/', { 'title': 'Моя вторая новость', 'announcement': 'Анонс второй новости', 'text': 'Текст второй новости', 'pub_date_0': '2014-10-15', 'pub_date_1': '16:07:00', 'category': str(category.id) }, follow=True) self.assertContains(response, 'успешно изменен', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 1) only_news = all_news[0] self.assertEquals(only_news.title, 'Моя вторая новость') self.assertEquals(only_news.announcement, 'Анонс второй новости') self.assertEquals(only_news.text, 'Текст второй новости')
def test_create_news(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.get('/admin/news/news/add/') self.assertEquals(response.status_code, 200) response = self.client.post('/admin/news/news/add/', { 'title': 'Моя первая новость', 'announcement': 'Анонс первой новости', 'text': 'Плюс текст первой новости', 'pub_date_0': '2014-10-15', 'pub_date_1': '15:35:00', 'category': str(category.id) }, follow=True) self.assertContains(response, 'успешно добавлен', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 1)
def test_category_page(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости' news.pub_date = timezone.now() news.category = category news.save() all_news = News.objects.all() self.assertEquals(len(all_news), 1) only_news = all_news[0] self.assertEquals(only_news, news) category_url = news.category.get_absolute_url() response = self.client.get(category_url) self.assertContains(response, news.category.name, status_code=200) #проверяем атрибуты self.assertEquals(only_news.title, 'Моя первая новость') self.assertEquals(only_news.announcement, 'Анонс первой новости') self.assertEquals(only_news.pub_date.day, news.pub_date.day) self.assertEquals(only_news.pub_date.year, news.pub_date.year)
def test_create_news(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.get('/admin/news/news/add/') self.assertEquals(response.status_code, 200) response = self.client.post('/admin/news/news/add/', { 'title': 'Моя первая новость', 'announcement': 'Анонс первой новости', 'text': 'Плюс текст первой новости', 'pub_date_0': '2014-10-15', 'pub_date_1': '15:35:00', 'category': str(category.id) }, follow=True ) self.assertContains(response, 'успешно добавлен', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 1)
def test_delete_new(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости ++' news.text = 'Текст первой новости!!!' news.pub_date = timezone.now() news.category = category news.save() all_news = News.objects.all() self.assertEquals(len(all_news), 1) self.client.login(username='******', password='******') response = self.client.post('/admin/news/news/' + str(news.id) + '/delete/', {'post': 'yes'}, follow=True) self.assertContains(response, 'успешно удален', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 0)
def test_create_category(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category, category) self.assertEquals(only_category.name, 'Экономика') self.assertEquals(only_category.description, 'Новости экономики')
def test_delete_category(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/category/' + str(category.id) + '/delete/', {'post': 'yes'}, follow=True) self.assertContains(response, 'успешно удален', status_code=200) all_categories = Category.objects.all() self.assertEquals(len(all_categories), 0)
def test_delete_category(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/category/' + str(category.id) + '/delete/', { 'post': 'yes' }, follow=True ) self.assertContains(response, 'успешно удален', status_code=200) all_categories = Category.objects.all() self.assertEquals(len(all_categories), 0)
def test_create_news(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() #создаем новость и заполняем поля news = News() #устанавливаем атрибуты news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости ++' news.text = 'Текст первой новости!!!' news.pub_date = timezone.now() news.category = category #сохраняем в бд news.save() #проверяем что новость доавбилась в базу all_news = News.objects.all() self.assertEquals(len(all_news), 1) only_news = all_news[0] self.assertEquals(only_news, news) #проверяем атрибуты self.assertEquals(only_news.title, 'Моя первая новость') self.assertEquals(only_news.announcement, 'Анонс первой новости ++') self.assertEquals(only_news.text, 'Текст первой новости!!!') self.assertEquals(only_news.pub_date.day, news.pub_date.day) self.assertEquals(only_news.pub_date.month, news.pub_date.month) self.assertEquals(only_news.pub_date.year, news.pub_date.year) self.assertEquals(only_news.pub_date.hour, news.pub_date.hour) self.assertEquals(only_news.pub_date.minute, news.pub_date.minute) self.assertEquals(only_news.pub_date.second, news.pub_date.second) self.assertEquals(only_news.category.name, 'Экономика') self.assertEquals(only_news.category.description, 'Новости экономики')
def test_edit_category(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/category/' + str(category.id) + '/', { 'name': 'Политика', 'description': 'Новости политики', 'slug': 'politics' }, follow=True) self.assertContains(response, 'успешно изменен', status_code=200) all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category.name, 'Политика') self.assertEquals(only_category.description, 'Новости политики')
def test_edit_category(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/category/' + str(category.id) + '/', { 'name': 'Политика', 'description': 'Новости политики', 'slug': 'politics' }, follow=True ) self.assertContains(response, 'успешно изменен', status_code=200) all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category.name, 'Политика') self.assertEquals(only_category.description, 'Новости политики')
def test_news_page(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.text = 'Текст первой новости' news.pub_date = timezone.now() news.category = category news.save() all_news = News.objects.all() self.assertEquals(len(all_news), 1) response = self.client.get('/news/' + str(news.id) + '/') self.assertContains(response, news.title, status_code=200) self.assertContains(response, news.text) self.assertContains(response, news.pub_date.year) # выдает на англ и сравнивает с русским - не отрабатывает self.assertContains(response, news.pub_date.strftime('%b')) self.assertContains(response, news.pub_date.day) self.assertContains(response, news.category.name)
def test_edit_news(self): category = Category() category.name = 'Экономика' category.description = 'Новости экономики' category.slug = 'economy' category.save() news = News() news.title = 'Моя первая новость' news.announcement = 'Анонс первой новости ++' news.text = 'Текст первой новости!!!' news.pub_date = timezone.now() news.category = category news.save() self.client.login(username='******', password='******') response = self.client.post('/admin/news/news/' + str(news.id) + '/', { 'title': 'Моя вторая новость', 'announcement': 'Анонс второй новости', 'text': 'Текст второй новости', 'pub_date_0': '2014-10-15', 'pub_date_1': '16:07:00', 'category': str(category.id) }, follow=True ) self.assertContains(response, 'успешно изменен', status_code=200) all_news = News.objects.all() self.assertEquals(len(all_news), 1) only_news = all_news[0] self.assertEquals(only_news.title, 'Моя вторая новость') self.assertEquals(only_news.announcement, 'Анонс второй новости') self.assertEquals(only_news.text, 'Текст второй новости')