def test_get_validate_articles(self): # Start with 0 self.assertEqual(len(self.user1.get_validate_articles()), 0) # Create Tuto ! article = ArticleFactory() article.authors.add(self.user1.user) article.sha_validation = 'whatever' article.save() # Should be 1 articles = self.user1.get_validate_articles() self.assertEqual(len(articles), 1) self.assertEqual(article, articles[0])
def load_articles(cli, size, fake): """ Load articles """ articles = [] nb_arts = size * 10 percent_arts_in_validation = 0.4 percent_arts_with_validator = 0.2 percent_arts_public = 0.3 cli.stdout.write(u"Nombres d'articles à créer : {}".format(nb_arts)) cli.stdout.write(u"Nombres d'articles en validations : {}" .format(str(int(nb_arts * percent_arts_in_validation)))) cli.stdout.write(u"Nombres d'articles réservé en validations : {}" .format(str(int(nb_arts * percent_arts_with_validator)))) cli.stdout.write(u"Nombres d'articles publiés : {}" .format(str(int(nb_arts * percent_arts_public)))) tps1 = time.time() nb_users = User.objects.count() if nb_users == 0: cli.stdout.write(u"Il n'y a aucun membre actuellement." u"Vous devez rajouter les membre dans vos fixtures (member)") else: nb_sub_categories = SubCategory.objects.count() if nb_sub_categories == 0: cli.stdout.write(u"Il n'y a aucune catégories actuellement." u"Vous devez rajouter les membre dans vos fixtures (category_content)") else: sub_categories = list(SubCategory.objects.all()) profiles = list(Profile.objects.all()) perms = list(Permission.objects.filter(codename__startswith='change_').all()) staffs = list(User.objects.filter(groups__permissions__in=perms).all()) nb_staffs = len(staffs) if nb_staffs == 0: cli.stdout.write(u"Il n'y a aucun staff actuellement." u"Vous devez rajouter les staffs dans vos fixtures (staff)") else: for i in range(0, nb_arts): art = ArticleFactory(title=fake.text(max_nb_chars=80), description=fake.sentence(nb_words=15, variable_nb_words=True)) art.authors.add(profiles[i % nb_users].user) art.subcategory.add(sub_categories[random.randint(0, nb_sub_categories - 1)]) articles.append(art) if i < int(nb_arts * percent_arts_with_validator): validator = staffs[random.randint(0, nb_staffs - 1)] valid = AValidation(article=art, version=art.sha_draft, date_proposition=datetime.now(), date_reserve=datetime.now(), validator=validator, status="PENDING_V") valid.save() art.sha_validation = art.sha_draft art.save() elif i < int(nb_arts * (percent_arts_in_validation + percent_arts_with_validator)): valid = AValidation(article=art, version=art.sha_draft, date_proposition=datetime.now()) valid.save() art.sha_validation = art.sha_draft art.save() elif i < int(nb_arts * (percent_arts_in_validation + percent_arts_with_validator + percent_arts_public)): mep_art(art, art.sha_draft) valid = AValidation(article=art, version=art.sha_draft, date_proposition=datetime.now(), date_reserve=datetime.now(), validator=validator, status="ACCEPT", comment_validator=fake.text(max_nb_chars=200), date_validation=datetime.now()) valid.save() art.sha_public = art.sha_draft art.pubdate = datetime.now() art.save() sys.stdout.write(" Article {}/{} \r".format(i + 1, nb_arts)) sys.stdout.flush() tps2 = time.time() cli.stdout.write(u"\nFait en {} sec".format(tps2 - tps1))