def test_create_url_with_shotened(self): url = Url() url.original = 'http://gshow.globo.com' url.shortened = 'iswhatIwantjustabitmore' self.user.urls.append(url) self.user.save() self.user.reload() self.assertEquals(self.user.urls[0].shortened, 'iswhatIwantjustabitmore')
def post(self, name=None): user = User.objects.get(name=name) data_dict = json.loads(request.data) new_url = Url() if 'shortened' in data_dict: shortened = data_dict['shortened'] url = user.get_url(shortened) if url is None: new_url.shortened = shortened else: return('{"error": "Shortened Pattern Conflict"}', 409) new_url.original = data_dict['original'] user.urls.append(new_url) try: user.save() return(new_url.to_json(), 201) except: return('{}', 500)