def setUp(self): self.user_token = api.post_user({ 'username': '******' }).json()['token'] self.other_user_token = api.post_user({ 'username': '******' }).json()['token'] contact_init_token = api.get_contact_init_token( self.user_token).json()['contact_init_token'] get_pin_response = api.get_contact_pin(contact_init_token, self.other_user_token).json() self.contact_token = api.post_contact_pin( get_pin_response['pin']).json()['contact_token'] self.socket = Socket() def connect(): self.socket.introduce_yourself(self.user_token) self.socket.on_connect(connect) self.other_socket = Socket() def connect(): self.other_socket.introduce_yourself(self.other_user_token) self.other_socket.on_connect(connect)
def test_creating_user_returns_a_token_and_username(self): data = {'username': '******'} json = api.post_user(data).json() self.assertNotEmptyString(json['token']) self.assertEqual(json['username'], 'foo')
def test_username_cannot_be_longer_than_80_characters(self): response = api.post_user({'username': '******' * 81}) self.assertEqual(400, response.status_code) json = response.json() self.assertEqual("This value must have 80 characters or less", json['message']['username'])
def test_username_cannot_be_blank(self): response = api.post_user({'username': '******'}) self.assertEqual(400, response.status_code) json = response.json() self.assertEqual("This value cannot be blank", json['message']['username'])
def test_correct_token_causes_authorized_event(self): socket = Socket() result = {'event_emmited': False} token = api.post_user({ 'username': '******' }).json()['token'] def connect(): socket.introduce_yourself(token) socket.on_connect(connect) def on_authorized(data): result['event_emmited'] = True socket.disconnect() socket.on('authorized', on_authorized) socket.connect() self.assertTrue(result['event_emmited'])
def setUp(self): self.user_token = api.post_user( {'username': '******'}).json()['token'] self.other_user_token = api.post_user( {'username': '******'}).json()['token']
def test_creating_user_returns_different_token_each_time(self): first_response = api.post_user({'username': '******'}).json() second_response = api.post_user({'username': '******'}).json() self.assertNotEqual(first_response['token'], second_response['token'])