Re: Run manage.py test app_name command from view

2017-11-26 Thread Matemática A3K
On Mon, Nov 27, 2017 at 3:21 AM, Joshua O. Morales <
joshuao.morale...@gmail.com> wrote:

> I tried it out, but I'm still getting 400 error.
>

400 means "Bad Request", if was something wrong inside the view, the server
should return a 500 (Internal Server Error). I think probably it isn't
executing at all...
If you remove the call_command does it works?


> I attached a copy of the tests.py of the app. Maybe you'll find something
> I can't.
>

Nope, I'm not into Selenium nor I can dedicate the time to learn it for
that. If it runs via a regular "python manage.py test seleniumapp" then
it's alright :)

>
> views.py:
>
> from django.shortcuts import render
> from django.core.management import call_command
>
>
> def start_scraping(request):
> call_command('test','seleniumapp')
> return render(request, 'seleniumapp/selenium.html')
>
> On Monday, November 27, 2017 at 3:40:58 AM UTC+8, Matemática A3K wrote:
>>
>>
>>
>> On Sun, Nov 26, 2017 at 11:03 AM, Joshua O. Morales <
>> joshuao@gmail.com> wrote:
>>
>>>  What I would like to do is to execute the tests.py by clicking a
>>> certain button.  I am trying to run the tests.py via views.py, but it gives
>>> me a 400 Bad Request error. Is there any other solution?
>>> Your help would be very much appreciated.
>>> Here's a snippet of the code:
>>>
>>> from django.core.management import call_command
>>>
>>> def start(request):
>>> call_command('test appname')
>>>
>>> It should be:
>>
>> call_command('test', 'appname')
>>
>> Don't know why is your 400, how are you requesting your view? Also, note
>> that you are not returning any HttpResponse nor redirect in the snippet (It
>> will give you other error)
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/90dee471-a65b-404f-aa9f-b19223471944%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhLHWcA1_66EkES3NioX_0G8%3D7yQPVYv_zJkLtxBz_DR4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Run manage.py test app_name command from view

2017-11-26 Thread Joshua O. Morales
I tried it out, but I'm still getting 400 error. I attached a copy of the 
tests.py of the app. Maybe you'll find something I can't. 
views.py:

from django.shortcuts import render
from django.core.management import call_command


def start_scraping(request):
call_command('test','seleniumapp')
return render(request, 'seleniumapp/selenium.html')

On Monday, November 27, 2017 at 3:40:58 AM UTC+8, Matemática A3K wrote:
>
>
>
> On Sun, Nov 26, 2017 at 11:03 AM, Joshua O. Morales  > wrote:
>
>>  What I would like to do is to execute the tests.py by clicking a certain 
>> button.  I am trying to run the tests.py via views.py, but it gives me a 
>> 400 Bad Request error. Is there any other solution?
>> Your help would be very much appreciated.
>> Here's a snippet of the code:
>>
>> from django.core.management import call_command
>>
>> def start(request):
>> call_command('test appname')
>>
>> It should be:
>
> call_command('test', 'appname')
>
> Don't know why is your 400, how are you requesting your view? Also, note 
> that you are not returning any HttpResponse nor redirect in the snippet (It 
> will give you other error)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90dee471-a65b-404f-aa9f-b19223471944%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException

## get the Firefox profile object
firefoxProfile = FirefoxProfile()

# 1=enabled, 2=disabled ; True=enabled, False=disabled
## CSS
firefoxProfile.set_preference('permissions.default.stylesheet', 1)

## images
firefoxProfile.set_preference('permissions.default.image', 2)

## JavaScript
firefoxProfile.set_preference('javascript.enabled', True)

## Flash
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','False')

## Use the driver
browser = webdriver.Firefox(firefoxProfile, executable_path=r'./driver/geckodriver.exe')
#browser.set_window_size(200,400)
browser_wait = WebDriverWait(browser, 120)

agoda_revtitle_element = ".Review-comment-bodyTitle"
agoda_revcomment_element = ".Review-comment-bodyText"
agoda_revscore_element = ".Review-comment-score"
agoda_revdate_element = ".Review-statusBar-date "

max_page_num = 5


class Review:
def __init__(self, review_site, title, comment, score, review_date):
self.review_site = review_site
self.review_title = title
self.review_comment = comment
self.review_score = score
self.review_date = review_date


def parse_reviews(website_name, review_title_element, review_comment_element, review_score_element,
  review_date_element):

review_titles = browser.find_elements_by_css_selector(review_title_element)
review_comments = browser.find_elements_by_css_selector(review_comment_element)
review_scores = browser.find_elements_by_css_selector(review_score_element)
review_dates = browser.find_elements_by_css_selector(review_date_element)

review_list = []
for idx in range(len(review_titles)):
review_list.append(idx)

rev_dates = []
rev_scores = []

if website_name == "agoda":
for idx in review_dates:
rev_dates.append(idx.text)
review_dates.clear()
for idx in rev_dates:
review_dates.append(idx)

for idx in review_scores:
rev_scores.append(idx.text)
review_scores.clear()
for idx in rev_scores:
review_scores.append(idx)

if website_name == "agoda":
agoda_dates = []
for idx in review_dates:
agoda_dates.append(idx[9:])

review_dates.clear()

for idx in agoda_dates:
review_dates.append(idx)

for idx in range(len(review_list)):
review_list[idx] = Review(website_name, review_titles[idx], review_comments[idx], review_scores[idx],
  review_dates[idx])

for idx in range(len(review_list)):
print("Review: " + str(idx + 1)
  + "\nTitle: " + review_list[idx].review_title.text
  + "\nComment: " + review_list[idx].review_c

Re: Run manage.py test app_name command from view

2017-11-26 Thread Matemática A3K
On Sun, Nov 26, 2017 at 11:03 AM, Joshua O. Morales <
joshuao.morale...@gmail.com> wrote:

>  What I would like to do is to execute the tests.py by clicking a certain
> button.  I am trying to run the tests.py via views.py, but it gives me a
> 400 Bad Request error. Is there any other solution?
> Your help would be very much appreciated.
> Here's a snippet of the code:
>
> from django.core.management import call_command
>
> def start(request):
> call_command('test appname')
>
> It should be:

call_command('test', 'appname')

Don't know why is your 400, how are you requesting your view? Also, note
that you are not returning any HttpResponse nor redirect in the snippet (It
will give you other error)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnh%2BotG8uAGPzb57Pix_g%3DLManuNL9%3DFwg7ObacK6%3DEA9Zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Run manage.py test app_name command from view

2017-11-26 Thread Joshua O. Morales
 What I would like to do is to execute the tests.py by clicking a certain 
button.  I am trying to run the tests.py via views.py, but it gives me a 
400 Bad Request error. Is there any other solution?
Your help would be very much appreciated.
Here's a snippet of the code:

from django.core.management import call_command

def start(request):
call_command('test appname')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5eb9d74-d290-4f6c-9c2b-82d184f0945e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.