django.contrib.auth.models.User.DoesNotExist: User matching query does not existWhat does ** (double star/asterisk) and * (star/asterisk) do for parameters?How do I check whether a file exists without exceptions?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?Does Django scale?Check if a given key already exists in a dictionaryDjango's self.client.login(…) does not work in unit testsDoes Python have a string 'contains' substring method?correct way to setup teardown login logout in django

What is game ban VS VAC ban in steam?

Mother abusing my finances

Thousands and thousands of words

Can non-English-speaking characters use wordplay specific to English?

Preserving culinary oils

Mapping a function f[xi_,xj_] over a list x1, ...., xn with the i < j restriction

Can you move on your turn, and then use the Ready Action to move again on another creature's turn?

Chord symbol and Roman numeral for naming an Augmented 6th chord

Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?

How can I include a header file that contains `>` in its name?

Is the world in Game of Thrones spherical or flat?

The qvolume of an integer

US entry in Atlanta airport (ATL) together with a US citizen

count number of files in directory with a certain name

Why teaching kids Torah is the only forbidden profession for singles Yihud-wise?

how do I test for a unique string with multiple possibilities?

chmod would set file permission to 000 no matter what permission i try to set

Is it possible to change original filename of an exe?

How do I spend money in the US?

How to properly maintain eye contact with people that have distinctive facial features?

In what episode of TOS did a character on the bridge make a comment about raising the number 1 to some power?

What caused the tendency for conservatives to not support climate change regulations?

Can a non-EU citizen travel within the Schengen area without identity documents?

Can an old DSLR be upgraded to match modern smartphone image quality



django.contrib.auth.models.User.DoesNotExist: User matching query does not exist


What does ** (double star/asterisk) and * (star/asterisk) do for parameters?How do I check whether a file exists without exceptions?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?Does Django scale?Check if a given key already exists in a dictionaryDjango's self.client.login(…) does not work in unit testsDoes Python have a string 'contains' substring method?correct way to setup teardown login logout in django






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have error like in title when I'm trying to run test, I dont know whats going on but my testUser doesn't work properly, It's funny because i have identical test user in another project and there everything is ok.



test_api.py



class TaskDetailViewAPI(APITestCase):
def setUp(self):
self.client = APIClient()
self.user = User.objects.create_user(username='test', password='test123')
self.user.save()

@classmethod
def setUpTestData(cls):
user = User.objects.get(id=1)
Task.objects.create(name='TestTask', user=user, status='NEW', date=date(2019, 4, 9), description='This is test')

def test_access_to_view_logged(self):
task= Task.objects.get(id=1)
login = self.client.login(username='test', password='test123')
self.assertTrue(login)


And this is test from another project where everything works fine



class CreateCommentAPI(APITestCase):
def setUp(self):
self.client = APIClient()
self.user = User.objects.create_user(username='test', password='test123')
self.user.save()

@classmethod
def setUpTestData(cls):
Category.objects.create(name='PC', slug='pc')
Product.objects.create(
category=Category.objects.get(id=1),
name='Laptop', slug='laptop',
description='here is description',
photo=SimpleUploadedFile("file.jpeg", b"file_content", content_type="image/jpeg"),
price=1999, available='available'
)

def test_access_to_view_logged(self):
product = Product.objects.get(id=1)
login = self.client.login(username='test', password='test123')
response = self.client.get(reverse('add_comments', kwargs='id': product.id))
self.assertTrue(login)
self.assertEqual(response.status_code, 200, f'expected Response code 200, instead get response.status_code')









share|improve this question






























    0















    I have error like in title when I'm trying to run test, I dont know whats going on but my testUser doesn't work properly, It's funny because i have identical test user in another project and there everything is ok.



    test_api.py



    class TaskDetailViewAPI(APITestCase):
    def setUp(self):
    self.client = APIClient()
    self.user = User.objects.create_user(username='test', password='test123')
    self.user.save()

    @classmethod
    def setUpTestData(cls):
    user = User.objects.get(id=1)
    Task.objects.create(name='TestTask', user=user, status='NEW', date=date(2019, 4, 9), description='This is test')

    def test_access_to_view_logged(self):
    task= Task.objects.get(id=1)
    login = self.client.login(username='test', password='test123')
    self.assertTrue(login)


    And this is test from another project where everything works fine



    class CreateCommentAPI(APITestCase):
    def setUp(self):
    self.client = APIClient()
    self.user = User.objects.create_user(username='test', password='test123')
    self.user.save()

    @classmethod
    def setUpTestData(cls):
    Category.objects.create(name='PC', slug='pc')
    Product.objects.create(
    category=Category.objects.get(id=1),
    name='Laptop', slug='laptop',
    description='here is description',
    photo=SimpleUploadedFile("file.jpeg", b"file_content", content_type="image/jpeg"),
    price=1999, available='available'
    )

    def test_access_to_view_logged(self):
    product = Product.objects.get(id=1)
    login = self.client.login(username='test', password='test123')
    response = self.client.get(reverse('add_comments', kwargs='id': product.id))
    self.assertTrue(login)
    self.assertEqual(response.status_code, 200, f'expected Response code 200, instead get response.status_code')









    share|improve this question


























      0












      0








      0








      I have error like in title when I'm trying to run test, I dont know whats going on but my testUser doesn't work properly, It's funny because i have identical test user in another project and there everything is ok.



      test_api.py



      class TaskDetailViewAPI(APITestCase):
      def setUp(self):
      self.client = APIClient()
      self.user = User.objects.create_user(username='test', password='test123')
      self.user.save()

      @classmethod
      def setUpTestData(cls):
      user = User.objects.get(id=1)
      Task.objects.create(name='TestTask', user=user, status='NEW', date=date(2019, 4, 9), description='This is test')

      def test_access_to_view_logged(self):
      task= Task.objects.get(id=1)
      login = self.client.login(username='test', password='test123')
      self.assertTrue(login)


      And this is test from another project where everything works fine



      class CreateCommentAPI(APITestCase):
      def setUp(self):
      self.client = APIClient()
      self.user = User.objects.create_user(username='test', password='test123')
      self.user.save()

      @classmethod
      def setUpTestData(cls):
      Category.objects.create(name='PC', slug='pc')
      Product.objects.create(
      category=Category.objects.get(id=1),
      name='Laptop', slug='laptop',
      description='here is description',
      photo=SimpleUploadedFile("file.jpeg", b"file_content", content_type="image/jpeg"),
      price=1999, available='available'
      )

      def test_access_to_view_logged(self):
      product = Product.objects.get(id=1)
      login = self.client.login(username='test', password='test123')
      response = self.client.get(reverse('add_comments', kwargs='id': product.id))
      self.assertTrue(login)
      self.assertEqual(response.status_code, 200, f'expected Response code 200, instead get response.status_code')









      share|improve this question
















      I have error like in title when I'm trying to run test, I dont know whats going on but my testUser doesn't work properly, It's funny because i have identical test user in another project and there everything is ok.



      test_api.py



      class TaskDetailViewAPI(APITestCase):
      def setUp(self):
      self.client = APIClient()
      self.user = User.objects.create_user(username='test', password='test123')
      self.user.save()

      @classmethod
      def setUpTestData(cls):
      user = User.objects.get(id=1)
      Task.objects.create(name='TestTask', user=user, status='NEW', date=date(2019, 4, 9), description='This is test')

      def test_access_to_view_logged(self):
      task= Task.objects.get(id=1)
      login = self.client.login(username='test', password='test123')
      self.assertTrue(login)


      And this is test from another project where everything works fine



      class CreateCommentAPI(APITestCase):
      def setUp(self):
      self.client = APIClient()
      self.user = User.objects.create_user(username='test', password='test123')
      self.user.save()

      @classmethod
      def setUpTestData(cls):
      Category.objects.create(name='PC', slug='pc')
      Product.objects.create(
      category=Category.objects.get(id=1),
      name='Laptop', slug='laptop',
      description='here is description',
      photo=SimpleUploadedFile("file.jpeg", b"file_content", content_type="image/jpeg"),
      price=1999, available='available'
      )

      def test_access_to_view_logged(self):
      product = Product.objects.get(id=1)
      login = self.client.login(username='test', password='test123')
      response = self.client.get(reverse('add_comments', kwargs='id': product.id))
      self.assertTrue(login)
      self.assertEqual(response.status_code, 200, f'expected Response code 200, instead get response.status_code')






      python django testing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 10:05







      Kuracha

















      asked Mar 24 at 9:59









      KurachaKuracha

      627




      627






















          2 Answers
          2






          active

          oldest

          votes


















          4














          setUpTestData is called only once for the whole test class, but more importantly it is called before setUp.



          Your working code doesn't have anything inside setUpTestData that depends on data in setUp, which is correct. But your non-working code does; it tries to access the User, which hasn't been created yet. You need to refactor things so that the User is either created inside setUpTestData, or the Task is created inside setUp.






          share|improve this answer























          • Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

            – Kuracha
            Mar 24 at 10:23











          • But, thanks for explaining why it is like this

            – Kuracha
            Mar 24 at 10:24



















          1














          Your test user's id might not be 1, instead of using the id, you could use the username in your setUpTestData method:



          user = User.objects.get(username='test')





          share|improve this answer























          • Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

            – Kuracha
            Mar 24 at 10:10







          • 1





            The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

            – damores
            Mar 24 at 10:14











          • Change not helped but I see that when i delete def setUpTestData(cls): then login == True

            – Kuracha
            Mar 24 at 10:15






          • 1





            Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

            – Kuracha
            Mar 24 at 10:18











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322587%2fdjango-contrib-auth-models-user-doesnotexist-user-matching-query-does-not-exist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          setUpTestData is called only once for the whole test class, but more importantly it is called before setUp.



          Your working code doesn't have anything inside setUpTestData that depends on data in setUp, which is correct. But your non-working code does; it tries to access the User, which hasn't been created yet. You need to refactor things so that the User is either created inside setUpTestData, or the Task is created inside setUp.






          share|improve this answer























          • Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

            – Kuracha
            Mar 24 at 10:23











          • But, thanks for explaining why it is like this

            – Kuracha
            Mar 24 at 10:24
















          4














          setUpTestData is called only once for the whole test class, but more importantly it is called before setUp.



          Your working code doesn't have anything inside setUpTestData that depends on data in setUp, which is correct. But your non-working code does; it tries to access the User, which hasn't been created yet. You need to refactor things so that the User is either created inside setUpTestData, or the Task is created inside setUp.






          share|improve this answer























          • Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

            – Kuracha
            Mar 24 at 10:23











          • But, thanks for explaining why it is like this

            – Kuracha
            Mar 24 at 10:24














          4












          4








          4







          setUpTestData is called only once for the whole test class, but more importantly it is called before setUp.



          Your working code doesn't have anything inside setUpTestData that depends on data in setUp, which is correct. But your non-working code does; it tries to access the User, which hasn't been created yet. You need to refactor things so that the User is either created inside setUpTestData, or the Task is created inside setUp.






          share|improve this answer













          setUpTestData is called only once for the whole test class, but more importantly it is called before setUp.



          Your working code doesn't have anything inside setUpTestData that depends on data in setUp, which is correct. But your non-working code does; it tries to access the User, which hasn't been created yet. You need to refactor things so that the User is either created inside setUpTestData, or the Task is created inside setUp.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 10:21









          Daniel RosemanDaniel Roseman

          467k42606663




          467k42606663












          • Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

            – Kuracha
            Mar 24 at 10:23











          • But, thanks for explaining why it is like this

            – Kuracha
            Mar 24 at 10:24


















          • Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

            – Kuracha
            Mar 24 at 10:23











          • But, thanks for explaining why it is like this

            – Kuracha
            Mar 24 at 10:24

















          Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

          – Kuracha
          Mar 24 at 10:23





          Yes, I already noticed that creating user inside setUpTestData works, This is correct answer so I will accept this.

          – Kuracha
          Mar 24 at 10:23













          But, thanks for explaining why it is like this

          – Kuracha
          Mar 24 at 10:24






          But, thanks for explaining why it is like this

          – Kuracha
          Mar 24 at 10:24














          1














          Your test user's id might not be 1, instead of using the id, you could use the username in your setUpTestData method:



          user = User.objects.get(username='test')





          share|improve this answer























          • Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

            – Kuracha
            Mar 24 at 10:10







          • 1





            The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

            – damores
            Mar 24 at 10:14











          • Change not helped but I see that when i delete def setUpTestData(cls): then login == True

            – Kuracha
            Mar 24 at 10:15






          • 1





            Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

            – Kuracha
            Mar 24 at 10:18















          1














          Your test user's id might not be 1, instead of using the id, you could use the username in your setUpTestData method:



          user = User.objects.get(username='test')





          share|improve this answer























          • Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

            – Kuracha
            Mar 24 at 10:10







          • 1





            The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

            – damores
            Mar 24 at 10:14











          • Change not helped but I see that when i delete def setUpTestData(cls): then login == True

            – Kuracha
            Mar 24 at 10:15






          • 1





            Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

            – Kuracha
            Mar 24 at 10:18













          1












          1








          1







          Your test user's id might not be 1, instead of using the id, you could use the username in your setUpTestData method:



          user = User.objects.get(username='test')





          share|improve this answer













          Your test user's id might not be 1, instead of using the id, you could use the username in your setUpTestData method:



          user = User.objects.get(username='test')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 10:07









          damoresdamores

          1,5412921




          1,5412921












          • Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

            – Kuracha
            Mar 24 at 10:10







          • 1





            The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

            – damores
            Mar 24 at 10:14











          • Change not helped but I see that when i delete def setUpTestData(cls): then login == True

            – Kuracha
            Mar 24 at 10:15






          • 1





            Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

            – Kuracha
            Mar 24 at 10:18

















          • Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

            – Kuracha
            Mar 24 at 10:10







          • 1





            The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

            – damores
            Mar 24 at 10:14











          • Change not helped but I see that when i delete def setUpTestData(cls): then login == True

            – Kuracha
            Mar 24 at 10:15






          • 1





            Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

            – Kuracha
            Mar 24 at 10:18
















          Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

          – Kuracha
          Mar 24 at 10:10






          Yes, but this fragment isnt for login purpose, and in my code i have problem that login = self.client.login(username='test', password='test123') != True

          – Kuracha
          Mar 24 at 10:10





          1




          1





          The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

          – damores
          Mar 24 at 10:14





          The DoesNotExist exception in your title is most likely to come from a get() call. If your code failed the test then it should throw an AssertionError or simply get a failed test message.

          – damores
          Mar 24 at 10:14













          Change not helped but I see that when i delete def setUpTestData(cls): then login == True

          – Kuracha
          Mar 24 at 10:15





          Change not helped but I see that when i delete def setUpTestData(cls): then login == True

          – Kuracha
          Mar 24 at 10:15




          1




          1





          Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

          – Kuracha
          Mar 24 at 10:18





          Now, I'm sure that problem is with setUpTestData, but change user to user = User.objects.get(username='test') didn't help, ok I will look whats is wrong with my test object, thanks for help

          – Kuracha
          Mar 24 at 10:18

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322587%2fdjango-contrib-auth-models-user-doesnotexist-user-matching-query-does-not-exist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해