Пример #1
0
    def test_post_user_with_name_when_user_already_exist(self):
        UserFactory.create()

        post_data = {
            'name': 'hugo',
            'password': '******'
        }
        response = self.client.post(
            "/user/",
            data=json.dumps(post_data),
            content_type='application/json; charset=utf-8'
        )

        self.assertEquals(response.status_code, 409)
Пример #2
0
    def test_put_user_should_return_200(self):
        UserFactory.create()
        password = u'321'

        post_data = {
            'name': 'manoel',
            'password': password
        }

        dk = hashlib.pbkdf2_hmac('sha256', b'%s' % password, b'salt', 100000)
        encrypted_passowrd = binascii.hexlify(dk)

        response = self.client.put(
            "/user/hugo",
            data=json.dumps(post_data),
            content_type='application/json; charset=utf-8'
        )
        self.assertEquals(response.status_code, 200)

        content = json.loads(response.data)
        self.assertEquals('manoel', content['name'])
        self.assertEquals(encrypted_passowrd, content['password'])
Пример #3
0
    def test_post_url_with_shorten(self):
        user = UserFactory.create()
        my_shortened = u'myurl'
        post_data = {
            'original': 'http://testtest.com',
            'shortened': my_shortened,
        }

        response = self.client.post(
            "/user/hugo/url",
            data=json.dumps(post_data),
            content_type='application/json; charset=utf-8')
        self.assertEquals(response.status_code, 201)
        user.reload()

        self.assertEquals(user.urls.count(), 1)
        self.assertEquals(user.urls[0].shortened, my_shortened)
Пример #4
0
 def test_delete_url_should_return_204_when_url_does_not_exist(self):
     UserFactory.create()
     response = self.client.delete("/user/hugo/url/myurl")
     self.assertEquals(response.status_code, 204)
Пример #5
0
 def test_delete_user_should_return_200_when_user_exist(self):
     UserFactory.create()
     response = self.client.delete("/user/hugo")
     self.assertEquals(response.status_code, 200)
Пример #6
0
 def test_get_user_should_return_404_when_user_does_not_exist(self):
     UserFactory.create()
     response = self.client.get("/user/manoel")
     self.assertEquals(response.status_code, 404)