def test_get_message_return_correct_json_data(self): user = User.objects.create_user('new_tester', '*****@*****.**', 'johnpassword') last_primary_key = Message.objects.last().id request = HttpRequest() request.method = 'POST' request.user = user request.POST['issue_name'] = Issue.objects.first().issue_name request.POST['content'] = 'test contest' create_message(request) request = HttpRequest() request.method = 'GET' request.GET['last_primary_key'] = last_primary_key request.GET['issue_name'] = Issue.objects.first().issue_name response = get_message(request) messages = json.loads(response.content.decode()) time_regex_str = "([1]|[0-9]):[0-5][0-9](\\s)?(?i)(am|pm)" received_message = messages[0] self.assertEqual(received_message['user_id'], user.id) self.assertEqual(received_message['username'], user.get_username()) self.assertEqual(received_message['content'], 'test contest') self.assertRegex(received_message['time'], time_regex_str)
def test_create_message_from_POST_data(self): user = User.objects.create_user('testing_goat', '*****@*****.**', 'johnpassword') request = HttpRequest() request.method = 'POST' request.user = user request.POST['issue_name'] = Issue.objects.first().issue_name request.POST['content'] = 'wow_wow' create_message(request) self.assertEqual(Message.objects.count(), fixtures_data_count + 1) new_message = Message.objects.last() self.assertEqual(new_message.user.get_username(), 'testing_goat') self.assertEqual(new_message.content, 'wow_wow')
def test_create_message_from_POST_data(self): user = User.objects.create_user('testing_goat', '*****@*****.**', 'johnpassword') request = HttpRequest() request.method = 'POST' request.user = user request.POST['issue_name'] = Issue.objects.first().issue_name request.POST['content'] = 'wow_wow' engine = import_module(settings.SESSION_ENGINE) session_key = None request.session = engine.SessionStore(session_key) request.session['cur_team'] = 'mario' create_message(request) self.assertEqual(Message.objects.count(), fixtures_data_count + 1) new_message = Message.objects.last() self.assertEqual(new_message.user.get_username(), 'testing_goat') self.assertEqual(new_message.content, 'wow_wow')