def test_user_info_endpoint(self): User(id=777, email='*****@*****.**', domain_type='corporate').put() User(id=8675, email='*****@*****.**', domain_type='corporate').put() response = self.testapp.get( '/_/api/users/me', headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'}) self.assertEqual( json.loads(response.text), { 'email': '*****@*****.**', 'role': None, 'admin': False, 'notifications': {} }) response = self.testapp.get( '/_/api/users/me', headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'}) self.assertEqual( json.loads(response.text), { 'email': '*****@*****.**', 'role': None, 'admin': False, 'notifications': {} })
def test_get_user_thread_key(self): auth_user = User(key=ndb.Key('User', 1)) other_user = User(key=ndb.Key('User', 2)) thread = actions.get_two_user_thread(auth_user, other_user) assert len(thread.participants) == 2 assert type(thread.key) is str
def test_get_messages(self): user = User(first_name="me", full_name="me too", facebook_id=8766) user.initialise_new_token() user.put() parent_key = ndb.Key("some_kind3", "some_id3") self.api.add_message( messages.AuthChatMessage(body="hello!", recipients=[3452746], token=user.get_token(), parent_key=parent_key.urlsafe())) self.api.add_message( messages.AuthChatMessage(body="what's up?", recipients=[3452746], token=user.get_token(), parent_key=parent_key.urlsafe())) msg = self.api.get_messages( messages.ChatMessageRequest(token=user.get_token(), parent_key=parent_key.urlsafe())) assert msg.messages[0].body == "hello!" assert msg.messages[1].body == "what's up?"
def test_model_to_chat_message(): user = User(first_name="Adrian", full_name="Adrian Letchford") user.put() model = models.ChatMessage(body="hello", recipients="123,456", sender_id=3452, sender_first_name="Adrian", sender_last_name="Letchford", sender_profile_image="image") msg = actions.model_to_chat_message(model) assert msg.sender_id == 3452 assert msg.body == "hello" assert msg.recipients == [123, 456]
def _create_profile_user(first_name: str, last_name: str, email: str, salutation: str, job_title: str) -> User: """""" user = User() user.first_name = first_name user.last_name = last_name user.email = email profile = UserProfile() profile.salutation = salutation profile.job_title = job_title profile.user = user user.save() profile.save() return user
def test_chat_message_to_model(self): user = User(first_name="me", full_name="me too", facebook_id=976) user.initialise_new_token() user.put() msg = message.AuthChatMessage(body="hello", token=user.get_token(), recipients=[123, 456]) model = actions.auth_chat_message_to_model(msg, user) assert model.sender_id == user.key.id() assert model.body == "hello" assert model.recipients == "123,456"
def user_create(username, password, first_name, last_name, email, role=1): if email: email = email.lower() m = User(username=username, first_name=first_name, last_name=last_name, email=email) m.set_password(password) m.save() User.ROLES[role](m) return m
def _create_user(first_name: str, last_name: str, email: str) -> User: """Abstracting this allows us to test more scenarios than just passing the fixture around. Args: first_name (str): The user's first name last_name (str): The user's last name Returns: SectionPage: User """ user = User() user.first_name = first_name user.last_name = last_name user.email = email user.save() return user
def test_add_message(self): user = User(first_name="me", full_name="me too", facebook_id=87654) user.initialise_new_token() user.put() parent_key = ndb.Key("some_kind1", "some_id2") msg = message.AuthChatMessage(body="hello!", token=user.get_token(), recipients=[3452746], parent_key=parent_key.urlsafe()) actions.add_message(msg, user) thread = models.Thread.get_by_key(parent_key, 1) assert thread.messages[0].body == "hello!" assert thread.messages[0].sender_id == user.key.id()
def test_get_messages(self): user = User(first_name="me", full_name="me too", facebook_id=8765) user.initialise_new_token() user.put() parent_key = ndb.Key("some_kind3", "some_id3") actions.add_message( message.AuthChatMessage(body="hello!", recipients=[3452746], message_id="563", parent_key=parent_key.urlsafe()), user) actions.add_message( message.AuthChatMessage(body="what's up?", recipients=[3452746], message_id="08764", parent_key=parent_key.urlsafe()), user) msg = actions.get_messages(parent_key) assert msg.messages[0].body == "hello!" assert msg.messages[1].body == "what's up?"
def test_get_user_thread_key(self): user = User(first_name="Adrian", full_name="Adrian Letchford", facebook_id=8766) user.initialise_new_token() user.put() user2 = User(first_name="Benjamin", full_name="Benjamin Letchford", facebook_id=87668) user2.initialise_new_token() user2.put() msg = UserId(token=user.get_token(), user=user2.key.id()) thread = self.api.get_user_thread_key(msg) assert len(thread.participants) == 2 assert "Adrian Letchford" in [u.full_name for u in thread.participants] assert type(thread.key) is str assert len(thread.key) > 10