def create_busline(self): busline = Busline() busline.line_number = "001" busline.description = "description" busline.via = "via" busline.route_size = 2.5 busline.fee = 2.0 terminal = Terminal(description="terminal") terminal.save() busline.save() busline.terminals.add(terminal) return busline
def create_busline(self): Busline.objects.all().delete() self.busline = Busline() self.busline.id = 1 self.busline.line_number = "0.001" self.busline.description = "description" self.busline.via = "via" self.busline.route_size = 2.5 self.busline.fee = 2.0 self.busline.save() Terminal.objects.all().delete() terminal = Terminal(description="terminal") terminal.save() self.busline.terminals.add(terminal)
def advanced_search_busline(request): r""" Perform an advanced search for bus lines which contain the input values\ entered by the user then returns the result page and the list of results. """ if ((len(request.GET['busline_advanced']) < 2) and (len(request.GET['description']) < 2)): response = modal_message( "Erro :(", "Entrada inválida.", "Os campos preenchidos da busca avançada devem possuir \ no mínimo 2 dígitos.", "search_result_page.html", request) else: buslines = Busline.filter_by_multiple( line_number=request.GET['busline_advanced'], description=request.GET['description'], terminal__description='') count_busline = len(buslines) line_number = request.GET['busline_advanced'] response = render_to_response("search_result_page.html", { 'buslines': buslines, 'count_busline': count_busline, 'searched_number': line_number, 'description': request.GET['description'] }, context_instance=RequestContext(request)) return response
def advanced_search_busline(request): r""" Perform an advanced search for bus lines which contain the input values\ entered by the user then returns the result page and the list of results. """ if ((len(request.GET['busline_advanced']) < 2) and (len(request.GET['description']) < 2)): response = modal_message( "Erro :(", "Entrada inválida.", "Os campos preenchidos da busca avançada devem possuir \ no mínimo 2 dígitos.", "search_result_page.html", request) else: buslines = Busline.filter_by_multiple( line_number=request.GET['busline_advanced'], description=request.GET['description'], terminal__description='' ) count_busline = len(buslines) line_number = request.GET['busline_advanced'] response = render_to_response( "search_result_page.html", {'buslines': buslines, 'count_busline': count_busline, 'searched_number': line_number, 'description': request.GET['description']}, context_instance=RequestContext(request)) return response
def busline_profile(request, line_number): """Return the profle page from a line number when requested.""" busline = Busline.filter_by_line_equals(line_number) posts = Post.objects.filter(busline__id=busline.id) posts = sorted(posts, key=lambda post: (post.time), reverse=True) return render_to_response("busline_profile.html", {'busline': busline, 'posts': posts}, context_instance=RequestContext(request))
def main(): """Load main page.""" busline = Busline.filter_by_line_equals(line_number) posts = Post.objects.filter(busline__id=busline.id) posts = sorted(posts, key=lambda post: (post.time), reverse=True) return render_to_response("main.html", {'busline': busline, 'posts': posts, }, context_instance=RequestContext(request))
def busline_profile(request, line_number): """Return the profle page from a line number when requested.""" busline = Busline.get_by_line_equals(line_number) posts = Post.objects.filter(busline__id=busline.id) posts = sorted(posts, key=lambda post: (post.time), reverse=True) return render_to_response("busline_profile.html", { 'busline': busline, 'posts': posts, }, context_instance=RequestContext(request))
def create_busline(self): busline = Busline() busline.line_number = "001" busline.description = "description" busline.via = "via" busline.route_size = 2.5 busline.fee = 2.0 terminal = Terminal(description="terminal") terminal.save() busline.save() busline.terminals.add(terminal) return busline
def search_line(request): r""" Perform a search for bus lines that contain the input value entered\ by the user then returns the result page and the list of results. """ line_number = request.GET['busline'] buslines = Busline.filter_by_line_number(line_number) count_busline = len(buslines) response = render_to_response("search_result_page.html", {'buslines': buslines, 'count_busline': count_busline, 'searched_number': line_number}, context_instance=RequestContext(request)) return response
def search_line(request): r""" Perform a search for bus lines that contain the input value entered\ by the user then returns the result page and the list of results. """ line_number = request.GET['busline'] buslines = Busline.filter_by_line_number(line_number) count_busline = len(buslines) response = render_to_response("search_result_page.html", { 'buslines': buslines, 'count_busline': count_busline, 'searched_number': line_number }, context_instance=RequestContext(request)) return response
def make_post_page(request): """Return the post page when requested. """ line_number = request.GET['line_number'] busline = Busline.get_by_line_equals(line_number) busline_id = busline.id terminals = busline.terminals try: last_post = Post.last(busline_id) except LineWithoutPostError: last_post = None if request.user.is_authenticated(): return render_to_response("make_post_page.html", { 'line_number': line_number, 'last_post': last_post, 'terminals': terminals }, context_instance=RequestContext(request)) else: return modal_message( "Erro :(", "Usuário não logado.", "Para realizar esta ação.\ você deve estar logado.", "login_page.html", request)
def test_busline_by_description(self): self.create_busline() buslines = Busline.filter_by_description("description") self.assertEquals(1, len(buslines))
def test_busline_filter_by_description_invalid_description(self): self.create_busline() buslines = Busline.filter_by_description("aeiou") self.assertEquals(0, len(buslines))
def test_busline_by_description(self): self.create_busline() buslines = Busline.filter_by_description("description") self.assertEquals(1, len(buslines))
def test_busline_filter_invalid_line_number(self): buslines = Busline.filter_by_line_number("003") self.assertEquals(0, len(buslines))
def test_busline_instance(self): busline = Busline() self.assertIsNotNone(busline)
def test_filter_by_multiple_exception(self): Busline.filter_by_multiple('001', 'description', 'terminal_description') self.assertRaises(ApiException)
def test_all_exception(self): Busline.all() self.assertRaises(ApiException)
def test_filter_by_description_exception(self): Busline.filter_by_description('description') self.assertRaises(ApiException)
def test_filter_by_description_exception(self): Busline.filter_by_description('description') self.assertRaises(ApiException)
def test_busline_filter_by_multiple(self): self.create_busline() buslines = Busline.filter_by_multiple( "001", "description", "terminal_description") self.assertEquals(1, len(buslines))
def test_filter_by_line_number_exception(self): Busline.filter_by_line_number('001') self.assertRaises(ApiException)
def test_all_exception(self): Busline.all() self.assertRaises(ApiException)
def test_busline_filter_by_multiple_invalid_both(self): self.create_busline() buslines = Busline.filter_by_multiple("000", "invalid", "terminal_description") self.assertEquals(0, len(buslines))
def test_busline_filter_by_multiple(self): self.create_busline() buslines = Busline.filter_by_multiple("001", "description", "terminal_description") self.assertEquals(1, len(buslines))
def test_busline_filter_by_description_invalid_description(self): self.create_busline() buslines = Busline.filter_by_description("aeiou") self.assertEquals(0, len(buslines))
def test_busline_filter_by_multiple_invalid_both(self): self.create_busline() buslines = Busline.filter_by_multiple( "000", "invalid", "terminal_description") self.assertEquals(0, len(buslines))
def test_busline_filter_line_number(self): self.create_busline() buslines = Busline.filter_by_line_number("001") self.assertEquals(1, len(buslines))
def test_filter_by_line_number_exception(self): Busline.filter_by_line_number('001') self.assertRaises(ApiException)
def test_busline_all_empty(self): buslines = Busline.all() self.assertEquals(0, len(buslines))
def test_busline_all(self): self.create_busline() buslines = Busline.all() self.assertEquals(1, len(buslines))
def test_busline_all(self): self.create_busline() buslines = Busline.all() self.assertEquals(1, len(buslines))
def test_busline_all_empty(self): buslines = Busline.all() self.assertEquals(0, len(buslines))
def test_busline_filter_line_number(self): self.create_busline() buslines = Busline.filter_by_line_number("001") self.assertEquals(1, len(buslines))
def make_post_action(request): """Perform the action of saving the post. """ post = Post() post.capacity = request.POST['capacity'] post.traffic = request.POST['traffic'] post.comment = request.POST['description'] post.latitude = request.POST['codigo_latitude'] post.longitude = request.POST['codigo_longitude'] post.user_id = request.user.id try: post.terminal_id = request.POST["terminal"] except: return call_feed_page(request, alert_title='Erro :(', error_lead='Campo não preenchido.', modal_message='O campo de terminal deve ser \ preenchido para realizar uma businada.') pontuation = 0 if request.POST['review'] == '': pontuation = 0 else: pontuation = int(request.POST['review']) try: busline = Busline.get_by_line_equals(request.POST['line_number']) post.busline_id = busline.id try: last_post = Post.last(post.busline_id) last_post.user.pontuation = last_post.user.pontuation + \ pontuation last_post.user.save() except LineWithoutPostError: pass if post.latitude == "" or post.longitude == "": return call_feed_page(request, alert_title='Erro :(', error_lead='Serviço não disponível', modal_message='Não conseguimos obter sua\ geolocalização.') post.save() response = call_feed_page(request, alert_title='Sucesso', error_lead='Post realizado', modal_message='Post realizado com sucesso!') except ApiException: response = call_feed_page(request, alert_title='Erro :(', error_lead='Servidor não disponível', modal_message='O acesso ao servidor está \ indisponível no momento, verifique sua \ conexão.') if post.latitude == "" or post.longitude == "": return call_feed_page(request, alert_title='Erro :(', error_lead='Servidor não disponível', modal_message='Não conseguimos obter sua \ geolocalização') post.save() return response
def test_busline_filter_invalid_line_number(self): buslines = Busline.filter_by_line_number("003") self.assertEquals(0, len(buslines))
def test_filter_by_multiple_exception(self): Busline.filter_by_multiple( '001', 'description', 'terminal_description') self.assertRaises(ApiException)
class PostControllerTest (SimpleTestCase): def setUp(self): self.client = Client() def create_user(self): User.objects.all().delete() self.user = User() self.user.id = 1 self.user.username = '******' self.user.set_password('test_password') self.user.name = 'test_name' self.user.email = '*****@*****.**' self.user.save() def create_busline(self): Busline.objects.all().delete() self.busline = Busline() self.busline.id = 1 self.busline.line_number = "0.001" self.busline.description = "description" self.busline.via = "via" self.busline.route_size = 2.5 self.busline.fee = 2.0 self.busline.save() Terminal.objects.all().delete() terminal = Terminal(description="terminal") terminal.save() self.busline.terminals.add(terminal) def post_data(self, review): data = {'capacity': '5', 'traffic': '5', 'description': 'comment', 'codigo_latitude': '0', 'codigo_longitude': '0', 'line_number': '0.001', 'terminal': '1', 'review': review} return data def twitter_data(self): data_twitter = {'capacity': '5', 'traffic': '5', 'line_number': '205' } return data_twitter def test_make_post_page(self): response = self.client.get( "/realizar_post/?line_number=0.001&busline_id=1") self.assertEquals(response.status_code, STATUS_OK) def test_make_post_twitter(self): try: urllib2.urlopen('http://whatismyip.org').read() tweet_data = self.twitter_data() tweet = self._post_twitter( tweet_data['line_number'], tweet_data['capacity'], tweet_data['traffic']) self.assertTrue(tweet) except Exception: self.assertRaises(Exception) def test_make_post_action_with_user(self): self.create_user() self.client.login(username='******', password='******') response = self.client.post( "/realizar_post/", self.post_data('0')) self.assertEquals(response.status_code, STATUS_OK) self.client.logout() self.user.delete() def test_make_post_action_with_user_and_line(self): self.create_busline() self.create_user() self.client.login(username='******', password='******') response = self.client.post( "/realizar_post/", self.post_data('0')) self.assertEquals(response.status_code, STATUS_OK) self.client.logout() def test_make_post_action_page_no_review(self): self.create_user() self.client.login(username='******', password='******') response = self.client.post( "/realizar_post/", self.post_data('')) self.assertEquals(response.status_code, STATUS_OK) self.client.logout() def test_make_post_action_page_no_geolocation(self): self.create_user() self.client.login(username='******', password='******') response = self.client.post( "/realizar_post/", self.post_data('0')) self.assertEquals(response.status_code, STATUS_OK) self.client.logout()