def test_should_post_changelog_using_netrc(self, mock_token):
        with NamedTemporaryFile("w") as netrc_file:
            netrc_file.write("machine gitea.com\n")
            netrc_file.write("login username\n")
            netrc_file.write("password password\n")

            netrc_file.flush()

            def request_callback(request):
                payload = json.loads(request.body)
                self.assertEqual(payload["tag_name"], "v1.0.0")
                self.assertEqual(payload["body"], "text")
                self.assertEqual(payload["draft"], False)
                self.assertEqual(payload["prerelease"], False)
                self.assertEqual(
                    "Basic "
                    + base64.encodebytes(b"username:password").decode("ascii").strip(),
                    request.headers.get("Authorization"),
                )

                return 201, {}, json.dumps({})

            responses.add_callback(
                responses.POST,
                self.url,
                callback=request_callback,
                content_type="application/json",
            )

            with mock.patch.dict(os.environ, {"NETRC": netrc_file.name}):
                status = Gitea.post_release_changelog("gitea", "tea", "1.0.0", "text")
                self.assertTrue(status)
 def test_should_return_false_status_if_it_failed(self):
     responses.add(
         responses.POST,
         self.url,
         status=400,
         body="{}",
         content_type="application/json",
     )
     responses.add(
         responses.GET,
         self.get_url,
         status=200,
         body='{"id": 1}',
         content_type="application/json",
     )
     responses.add(
         responses.POST,
         self.edit_url,
         status=400,
         body="{}",
         content_type="application/json",
     )
     self.assertFalse(Gitea.post_release_changelog("gitea", "tea", "1.0.0", "text"))