I am trying to get data from a fake URL. In the process, the method some_method
is called and that is where it fails because the url is not valid.
I am using Pytest. How can I achieve this?
Here's my code:
models.py
class AModel(models.Model):
name = models.CharField(max_length=233, default='default')
url = models.URLField(blank=True, null=True)
def some_method(self, data):
return requests.post(url=self.url, data=data)
tests.py
def test_amodel(self, mock):
url = 'http://www.dummyurl.com/23'
res = self.client.post(reverse(url))
assert res.status_code == 200