Exemplo n.º 1
0
 def test_create_from_github_existing_user(self, m):
     m.return_value = {
         'login': USERNAME,
         'avatar_url': 'http://example.com/av.png',
     }
     token = generate_token()
     user = User.objects.create(github_username=USERNAME, token=token)
     result = User.objects.create_from_github(USERNAME, PASSWORD)
     self.assertEqual(user, result)
     self.assertEqual(result.token, token)
Exemplo n.º 2
0
 def test_login_with_valid_data(self):
     user = User.objects.create(
         github_username='******',
         avatar_url='http://example.com/av.png',
         token=generate_token()
     )
     with mock.patch('detector.accounts.models.User.objects.create_from_github') as m:
         m.return_value = user
         resp = self.client.post(
             '/login',
             json.dumps({ 'login': username, 'password': password }),
             content_type='application/json'
         )
         data = json.loads(resp.content)
         data['login'] = user.github_username
         data['avatar'] = user.avatar_url
         data['token'] = user.token
Exemplo n.º 3
0
 def test_generate_token(self):
     token = generate_token()
     self.assertEqual(len(token), UUID_LENGTH)
     another_token = generate_token()
     self.assertNotEqual(token, another_token)
Exemplo n.º 4
0
def create_user():
    params = {'github_username': '******', 'token': generate_token()}
    return User.objects.create(**params)