def test_unregister(self): """Tests that unregistering user is working""" # test not logged user can't unregister self.client.logout() result = self.client.post(reverse('zds.member.views.unregister'), follow=False) self.assertEqual(result.status_code, 302) user = ProfileFactory() login_check = self.client.login(username=user.user.username, password='******') self.assertEqual(login_check, True) result = self.client.post(reverse('zds.member.views.unregister'), follow=False) self.assertEqual(result.status_code, 302) self.assertEqual( User.objects.filter(username=user.user.username).count(), 0) user = ProfileFactory() user2 = ProfileFactory() aloneGallery = GalleryFactory() UserGalleryFactory(gallery=aloneGallery, user=user.user) sharedGallery = GalleryFactory() UserGalleryFactory(gallery=sharedGallery, user=user.user) UserGalleryFactory(gallery=sharedGallery, user=user2.user) # first case : a published tutorial with only one author publishedTutorialAlone = MiniTutorialFactory(light=True) publishedTutorialAlone.authors.add(user.user) publishedTutorialAlone.save() # second case : a published tutorial with two authors publishedTutorial2 = MiniTutorialFactory(light=True) publishedTutorial2.authors.add(user.user) publishedTutorial2.authors.add(user2.user) publishedTutorial2.save() # third case : a private tutorial with only one author writingTutorialAlone = MiniTutorialFactory(light=True) writingTutorialAlone.authors.add(user.user) writingTutorialAlone.save() writingTutorialAloneGallerPath = writingTutorialAlone.gallery.get_gallery_path( ) writingTutorialAlonePath = writingTutorialAlone.get_path() # fourth case : a private tutorial with at least two authors writingTutorial2 = MiniTutorialFactory(light=True) writingTutorial2.authors.add(user.user) writingTutorial2.authors.add(user2.user) writingTutorial2.save() self.client.login(username=self.staff.username, password="******") pub = self.client.post(reverse('zds.tutorial.views.ask_validation'), { 'tutorial': publishedTutorialAlone.pk, 'text': u'Ce tuto est excellent', 'version': publishedTutorialAlone.sha_draft, 'source': 'http://zestedesavoir.com', }, follow=False) self.assertEqual(pub.status_code, 302) # reserve tutorial validation = Validation.objects.get( tutorial__pk=publishedTutorialAlone.pk) pub = self.client.post(reverse('zds.tutorial.views.reservation', args=[validation.pk]), follow=False) self.assertEqual(pub.status_code, 302) # publish tutorial pub = self.client.post(reverse('zds.tutorial.views.valid_tutorial'), { 'tutorial': publishedTutorialAlone.pk, 'text': u'Ce tuto est excellent', 'is_major': True, 'source': 'http://zestedesavoir.com', }, follow=False) pub = self.client.post(reverse('zds.tutorial.views.ask_validation'), { 'tutorial': publishedTutorial2.pk, 'text': u'Ce tuto est excellent', 'version': publishedTutorial2.sha_draft, 'source': 'http://zestedesavoir.com', }, follow=False) self.assertEqual(pub.status_code, 302) # reserve tutorial validation = Validation.objects.get(tutorial__pk=publishedTutorial2.pk) pub = self.client.post(reverse('zds.tutorial.views.reservation', args=[validation.pk]), follow=False) self.assertEqual(pub.status_code, 302) # publish tutorial pub = self.client.post(reverse('zds.tutorial.views.valid_tutorial'), { 'tutorial': publishedTutorial2.pk, 'text': u'Ce tuto est excellent', 'is_major': True, 'source': 'http://zestedesavoir.com', }, follow=False) # same thing for articles publishedArticleAlone = ArticleFactory() publishedArticleAlone.authors.add(user.user) publishedArticleAlone.save() publishedArticle2 = ArticleFactory() publishedArticle2.authors.add(user.user) publishedArticle2.authors.add(user2.user) publishedArticle2.save() writingArticleAlone = ArticleFactory() writingArticleAlone.authors.add(user.user) writingArticleAlone.save() writingArticle2 = ArticleFactory() writingArticle2.authors.add(user.user) writingArticle2.authors.add(user2.user) writingArticle2.save() # ask public article pub = self.client.post(reverse('zds.article.views.modify'), { 'article': publishedArticleAlone.pk, 'comment': u'Valides moi ce bébé', 'pending': 'Demander validation', 'version': publishedArticleAlone.sha_draft, 'is_major': True }, follow=False) self.assertEqual(pub.status_code, 302) login_check = self.client.login(username=self.staff.username, password='******') self.assertEqual(login_check, True) # reserve article validation = ArticleValidation.objects.get( article__pk=publishedArticleAlone.pk) pub = self.client.post(reverse('zds.article.views.reservation', args=[validation.pk]), follow=False) self.assertEqual(pub.status_code, 302) # publish article pub = self.client.post(reverse('zds.article.views.modify'), { 'article': publishedArticleAlone.pk, 'comment-v': u'Cet article est excellent', 'valid-article': 'Demander validation', 'is_major': True }, follow=False) self.assertEqual(pub.status_code, 302) # ask public article pub = self.client.post(reverse('zds.article.views.modify'), { 'article': publishedArticle2.pk, 'comment': u'Valides moi ce bébé', 'pending': 'Demander validation', 'version': publishedArticle2.sha_draft, 'is_major': True }, follow=False) self.assertEqual(pub.status_code, 302) login_check = self.client.login(username=self.staff.username, password='******') self.assertEqual(login_check, True) # reserve article validation = ArticleValidation.objects.get( article__pk=publishedArticle2.pk) pub = self.client.post(reverse('zds.article.views.reservation', args=[validation.pk]), follow=False) self.assertEqual(pub.status_code, 302) # publish article pub = self.client.post(reverse('zds.article.views.modify'), { 'article': publishedArticle2.pk, 'comment-v': u'Cet article est excellent', 'valid-article': 'Demander validation', 'is_major': True }, follow=False) self.assertEqual(pub.status_code, 302) # about posts and topics authoredTopic = TopicFactory(author=user.user, forum=self.forum11) answeredTopic = TopicFactory(author=user2.user, forum=self.forum11) PostFactory(topic=answeredTopic, author=user.user, position=2) editedAnswer = PostFactory(topic=answeredTopic, author=user.user, position=3) editedAnswer.editor = user.user editedAnswer.save() privateTopic = PrivateTopicFactory(author=user.user) privateTopic.participants.add(user2.user) privateTopic.save() PrivatePostFactory(author=user.user, privatetopic=privateTopic, position_in_topic=1) login_check = self.client.login(username=user.user.username, password='******') self.assertEqual(login_check, True) result = self.client.post(reverse('zds.member.views.unregister'), follow=False) self.assertEqual(result.status_code, 302) self.assertEqual(publishedTutorialAlone.authors.count(), 1) self.assertEqual(publishedTutorialAlone.authors.first().username, settings.ZDS_APP["member"]["external_account"]) self.assertFalse(os.path.exists(writingTutorialAloneGallerPath)) self.assertEqual(publishedTutorial2.authors.count(), 1) self.assertEqual( publishedTutorial2.authors.filter( username=settings.ZDS_APP["member"] ["external_account"]).count(), 0) self.assertIsNotNone(publishedTutorial2.get_prod_path()) self.assertTrue(os.path.exists(publishedTutorial2.get_prod_path())) self.assertIsNotNone(publishedTutorialAlone.get_prod_path()) self.assertTrue(os.path.exists(publishedTutorialAlone.get_prod_path())) self.assertEqual( self.client.get(reverse( 'zds.tutorial.views.view_tutorial_online', args=[publishedTutorialAlone.pk, publishedTutorialAlone.slug]), follow=False).status_code, 200) self.assertEqual( self.client.get(reverse( 'zds.tutorial.views.view_tutorial_online', args=[publishedTutorial2.pk, publishedTutorial2.slug]), follow=False).status_code, 200) self.assertTrue(os.path.exists(publishedArticleAlone.get_path())) self.assertEqual( self.client.get(reverse( 'zds.article.views.view_online', args=[publishedArticleAlone.pk, publishedArticleAlone.slug]), follow=True).status_code, 200) self.assertEqual( self.client.get(reverse( 'zds.article.views.view_online', args=[publishedArticle2.pk, publishedArticle2.slug]), follow=True).status_code, 200) self.assertEqual( Tutorial.objects.filter(pk=writingTutorialAlone.pk).count(), 0) self.assertEqual(writingTutorial2.authors.count(), 1) self.assertEqual( writingTutorial2.authors.filter(username=settings.ZDS_APP["member"] ["external_account"]).count(), 0) self.assertEqual(publishedArticleAlone.authors.count(), 1) self.assertEqual(publishedArticleAlone.authors.first().username, settings.ZDS_APP["member"]["external_account"]) self.assertEqual(publishedArticle2.authors.count(), 1) self.assertEqual( publishedArticle2.authors.filter( username=settings.ZDS_APP["member"] ["external_account"]).count(), 0) self.assertEqual( Article.objects.filter(pk=writingArticleAlone.pk).count(), 0) self.assertEqual(writingArticle2.authors.count(), 1) self.assertEqual( writingArticle2.authors.filter(username=settings.ZDS_APP["member"] ["external_account"]).count(), 0) self.assertEqual( Topic.objects.filter(author__username=user.user.username).count(), 0) self.assertEqual( Post.objects.filter(author__username=user.user.username).count(), 0) self.assertEqual( Post.objects.filter(editor__username=user.user.username).count(), 0) self.assertEqual( PrivatePost.objects.filter( author__username=user.user.username).count(), 0) self.assertEqual( PrivateTopic.objects.filter( author__username=user.user.username).count(), 0) self.assertFalse(os.path.exists(writingTutorialAlonePath)) self.assertIsNotNone(Topic.objects.get(pk=authoredTopic.pk)) self.assertIsNotNone(PrivateTopic.objects.get(pk=privateTopic.pk)) self.assertIsNotNone(Gallery.objects.get(pk=aloneGallery.pk)) self.assertEquals(aloneGallery.get_users().count(), 1) self.assertEquals(sharedGallery.get_users().count(), 1) self.assertEquals( UserGallery.objects.filter(user=user.user).count(), 0)