Custom Search

Tuesday, October 25, 2011

howto django uploading files to dynamic path

def get_upload_path(instance, filename):
        Get upload path
        eg: upload/1/2011/10/16/09/00/12/oauth_application.png
    today = datetime.utcnow()
    date_time_str = today.strftime("%Y/%m/%d/%H/%M/%S")
    path = "%s/%s/%s/%s" %(storage,, date_time_str, filename)
#    print "---------", path
    return path

class MultiuploaderImage(models.Model):
    """Model for storing uploaded photos"""
    filename = models.CharField(max_length=60, blank=True, null=True)
    image = models.FileField(upload_to=get_upload_path)
    key_data = models.CharField(max_length=90, unique=True, blank=True, null=True)
    upload_date = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(User)

Wednesday, October 5, 2011

Python Selenium WebDriver GUI Tests using PyVirtualDisplay Xvfb and without X-server

Python Selenium WebDriver GUI Tests using PyVirtualDisplay, Xvfb and
without X-server

I need to integrate my functional UI tests (Selenium/WebDriver) with
my Jenkins CI system. The problem is that my Jenkins CI server has no
display, so I must run my GUI tests in a headless X-server.

A colleague pointed me to PyVirtualDisplay, a Python wrapper for Xvfb
and Xephyr.

This makes running headless Python Selenium/WebDriver tests very easy.

Here is some Python code showing WebDriver with a virtual display
provided by Xvfb:

#!/usr/bin/env python

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))

# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
print browser.title

install PyVirtualDisplay on Ubuntu/Debian:
$ sudo apt-get install xvfb xserver-xephyr python-pip
$ sudo pip install pyvirtualdisplay