Custmo field numpyarray - why does this even work?

2015-12-02 Thread Joakim Hove
Hello;

I want to create a custom model field for storing a numpy array. It has 
currently been so simple that I fear I am overrlooking something and 
getting a very false positive?


class NumpyArrayField(BinaryField):
dtype = numpy.float32

@classmethod
def load_numpy_array(cls , blob):
return numpy.fromstring(blob , NumpyArrayField.dtype)

def __init__(self , *args , **kwargs):
kwargs['default'] = None
super(NumpyArrayField , self).__init__(*args , **kwargs)


def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return self.load_numpy_array( value )


def to_python(self, value):
if isinstance(value, numpy.ndarray):
return value

if value is None:
return value

return self.load_numpy_array( value )


As I see it this has (essenially two versions) of code for deserializing 
from a database value to a numpy array, but no method for the opposite 
operation. However it seemingly works?

I have created a small model with one of these fields:



class TimeSeries(Model):
start = DateTimeField( )
step = IntegerField( )
data = NumpyArrayField( )


@classmethod
def createArray(cls , size = 0):
return numpy.ndarray( shape = [size] , dtype = 
NumpyArrayField.dtype)

def __getitem__(self , index):
if self.data is None:
raise IndexError
else:
return self.data[index]

def __setitem__(self , index , value):
if self.data is None:
raise IndexError
else:
self.data[index] = value


def __len__(self):
if self.data is None:
return 0
else:
shape = self.data.shape
return shape[0]



And a test:


class TimeSeriesTest(TestCase):

def test_create(self):
ts = TimeSeries.objects.create( start = timezone.now(),
step = 100 ,
data = TimeSeries.createArray( ))
self.assertEqual( len(ts) , 0 )
with self.assertRaises(IndexError):
ts[0]

ts.addValue( 1 )

self.assertEqual( len(ts) , 1 )
with self.assertRaises(IndexError):
ts[1]

self.assertEqual( ts[0] , 1 )
 
# How on earth does the NumpyArrayField know how to save itself to 
the db?
ts.save()

ts2 = TimeSeries.objects.get( pk = 1 )
self.assertEqual( ts2[0] , 1)
self.assertEqual( len(ts2) , 1 )


I was expecting the test to fail spectacularly when calling ts.save() - 
however it seems to work, and I can even get the instance back from db - 
what gives?  I am using sqlite and have tried to force the db to create a 
file.

I was excpecting to implement the get_prep_db_value() method - but now when 
things seemingly work without it I get quite uncertain? Is there some magic 
trickery involved which says that this should indeed work - or am I seeing 
a completely false positive?

Joakim





-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09fa67a5-70b6-40c4-a600-13ea9cbbd97c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custmo field numpyarray - why does this even work?

2015-12-02 Thread Joakim Hove
Sorry;

how do you get the nice code formatting - I thought it was through the use 
of   ...  blocks?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e70d787-3484-43e0-9414-e7252113de69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Tests not passing in suite but pass individually

2015-12-02 Thread Siddhi Divekar
Hi,

Am seeing that test case in suite are failing but passing when ran 
individually.
I have gone through most of the thread on the internet but did not find any 
solution.

Below is the snip of what am trying to do.

class A(TestCase):
  def test_a():
   create an obj in db
   retrive obj list from db and check the length of the list (should be 1)
   update same obj in db
   delte same obj in db

 def b():
  create an obj in db and check the length.

When ran in suite test_a fails as the length of the list is 2.
test_b() runs before test_a and leave the object in the database.

>From various threads suggested using 'django.test import TestCase' 
instead of 'from django.unittest import TestCase' which am already doing.

Is there anything else i need to do here ?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a142d7fb-7865-4d6c-9a96-671a4c62a550%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Turn off migrations completely in Django 1.7

2015-12-02 Thread john . rg . orr
+1 for disabling migrations completely - for several reasons.

1. Right now, I'm trying to run tests against a production database with 
runserver, in *read-only* mode - but it fails because it can't create the 
django_migrations table.  (I'm in the process of upgrading from Django 1.4 
to 1.8, so the table doesn't yet exist in production.)

2. Our mysql database is 3TB, with some tables of up to 500GB - and I 
assume that migrating them with Django - without taking the system down for 
days - is not possible.  Instead, we use Percona's pt-online-schema-change, 
which does an excellent job of migrating big tables, whilst keeping them 
fully usable with no downtime.

Point 2 is covered, I think, by setting all models to unmanged, as we do - 
but that doesn't help me with the upgrade process in point 1 - unless I'm 
missing something?

(Yes, perhaps I could jump through hoops and make a second, writable 
database, with appropriate routers etc, to enable creation of the 
django_migrations table, to get past point 1 - but if django migrations are 
useless to us anyway... disabling migrations entirely seems far more 
logical.)


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/de1ad2dc-10e5-4f95-8f7b-1075c268e2ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to save a table in a cell in django models.

2015-12-02 Thread Billu
What I want to do is generate a HTML table (alongwith other data viz. 
images, text) when somebody opens a page.

So how would I *save *a table, i.e, what would be the keyword for it eg. 
CharField, IntegerField. 

I've googled and people have written that you need to save XML data in the 
database cell. If so how to do that? 

Or should I just save comma separated text and work with that, although I 
guess that may be a little difficult as there are bullets and sub-bullets 
in one of the columns. 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/241aee75-ad5a-4580-be92-84de386b4764%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save a table in a cell in django models.

2015-12-02 Thread Timothy W. Cook
On Wed, Dec 2, 2015 at 2:27 AM, Billu  wrote:

> What I want to do is generate a HTML table (alongwith other data viz.
> images, text) when somebody opens a page.
>
> So how would I *save *a table, i.e, what would be the keyword for it eg.
> CharField, IntegerField.
>
> I've googled and people have written that you need to save XML data in the
> database cell. If so how to do that?
>
> Or should I just save comma separated text and work with that, although I
> guess that may be a little difficult as there are bullets and sub-bullets
> in one of the columns.
>
>
​If you are just generating a table to be included later in a web page, I
would store them in a  TextField.  If you are generating complete web pages
that you want to serve statically then you can use a ​FileField.


-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3Va-Tu4OTLnvOjK0am2cEdTOTzmOHmxR5kijDSCs9eCDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django 1.9 released

2015-12-02 Thread Mike

>
> pip install django
> Downloading/unpacking django
>   Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
> Installing collected packages: django
> Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py 
> ...
>   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py", 
> line 4
> class {{ camel_case_app_name }}Config(AppConfig):
>   ^
> SyntaxError: invalid syntax
> Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py 
> ...
>   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py",
>  
> line 1
> {{ unicode_literals }}from django.db import models
>  ^
> SyntaxError: invalid syntax
> Successfully installed django
> Cleaning up...


Anyone else see this error? This was in an new virtualenv.


On Tuesday, December 1, 2015 at 7:10:41 PM UTC-5, Tim Graham wrote:
>
> Django 1.9 is now available:
>
> https://www.djangoproject.com/weblog/2015/dec/01/django-19-released/ 
> 
>
> With the release of Django 1.9, Django 1.7 has reached end-of-life. Django 
> 1.7.11 is the final release of the 1.7 series and all users are encouraged 
> to upgrade to Django 1.8+ as soon as possible so they can continue to 
> receive security updates. Django 1.8 LTS will receive security updates 
> until April 2018. Django 1.4 (the previous LTS) reached end of life on 
> October 1, 2015. See the downloads page [1] for a table of supported 
> versions and the future release schedule.
>
> [1] https://www.djangoproject.com/download/#supported-versions
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04e0e7cb-250a-4eae-8745-4832c8f5eb2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Recursion error after upgrading from 1.8 to 1.9

2015-12-02 Thread Gergely Polonkai
I have upgraded Django from 1.8.5 to 1.9. Running my tests fails with this:

RuntimeError: maximum recursion depth exceeded while calling a Python object

My INSTALLED_APPS:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'form_utils',
'django_fsm',
'django_fsm_log',
'compressor',
'rest_framework',
'rest_framework.authtoken',
'django_js_reverse',
'bootstrap3',
'timezone_field',
'builds',
'accounts',
'api',
'process',
)

I’m in the process of filtering this, but if anyone has some idea, don’t
hesitate to share :)

Best,
Gergely

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBU%2BcWuScjjBjFu-L%3Dzx_v%2BEGJ6pQ2NhDKayNXUrTOieFKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transitioning existing login portal to Django

2015-12-02 Thread 'Alan Hicks' via Django users

Hi,

I treat them as a straightforward migration (not Django's btw). Create 
the models and functionality to replicate existing then write sql if 
necessary to convert to the new schema.  Depending on the complexity, 
the migration should not try to change much until it's in a (Django) 
form you are comfortable with, as the Django framework handles changes well.


There are all sorts of errors that could surface, by keeping the 
data/functionality as close to the original you minimise any impact.  By 
scripting everything, it's easy to test and repeat until it goes live.


Usernames and passwords are just fields in a database so I would either 
replicate the credentials to Django's if possible or create a User model 
that replicates existing followed by a transition phase to Django if 
required.


Django's great for running different templates (I use Django's and 
Jinja2's) so you could use the existing ones until you have translated 
them into your preferred format.


Regards,
Alan

On 01/12/2015 22:15, Evan Palmer wrote:

Hello,

Does anyone have experience with transitioning an existing database 
/including user login data/ to Django?


I am about to begin work on a startup's hand-written web portal that 
consists of about 2000 lines of custom Python code (hashing passwords, 
managing user accounts, DB connections, etc.), some Mako templates, 
and a Postgresql database. A hand-written web framework makes me 
nervous for many reasons. I don't have access to the source code or 
the database yet, but my plan is to transition it to Django 1.8. I'd 
like to use /inspectdb/ to help generate the models, but I doubt 
/inspectdb/ will be smart enough to handle usernames and password 
hashes properly. How can I make sure this data gets transferred correctly?


I'm looking for ideas about how to proceed and/or what to expect 
during the transition. Thanks.


-EP
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5fc8e870-68ef-4012-91e5-2467c7d0394f%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Persistent Objects Ltd
128 Lilleshall Road
London SM4 6DR

Lifting brand value by using all means at my disposal
including technological, motivational and best practice.

Proud sponsor of TEDx Wandsworth 2015

Registered in England and Wales 03538717

+44/0 79 3030 5004
+44/0 20 8544 5292
http://p-o.co.uk
https://plus.google.com/+AlanHicksLondon

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/565ECED4.6050001%40p-o.co.uk.
For more options, visit https://groups.google.com/d/optout.


Re: Recursion error after upgrading from 1.8 to 1.9

2015-12-02 Thread Gergely Polonkai
New info: I have removed everything after django.contrib.staticfiles, but
the problem still persists.

2015-12-02 11:57 GMT+01:00 Gergely Polonkai :

> I have upgraded Django from 1.8.5 to 1.9. Running my tests fails with this:
>
> RuntimeError: maximum recursion depth exceeded while calling a Python
> object
>
> My INSTALLED_APPS:
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'form_utils',
> 'django_fsm',
> 'django_fsm_log',
> 'compressor',
> 'rest_framework',
> 'rest_framework.authtoken',
> 'django_js_reverse',
> 'bootstrap3',
> 'timezone_field',
> 'builds',
> 'accounts',
> 'api',
> 'process',
> )
>
> I’m in the process of filtering this, but if anyone has some idea, don’t
> hesitate to share :)
>
> Best,
> Gergely
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUKLxo42T0OaFQ8dY5WTAnsBsicQF%2BXggY1tt7TxFefyZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django 1.9 released

2015-12-02 Thread Dimitris R
You need to upgrade pip. 

See 
https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-with-pip-1-5-6

On Wednesday, 2 December 2015 12:20:49 UTC+2, Mike wrote:
>
> pip install django
>> Downloading/unpacking django
>>   Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
>> Installing collected packages: django
>> Compiling 
>> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py 
>> ...
>>   File 
>> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py", 
>> line 4
>> class {{ camel_case_app_name }}Config(AppConfig):
>>   ^
>> SyntaxError: invalid syntax
>> Compiling 
>> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py 
>> ...
>>   File 
>> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py",
>>  
>> line 1
>> {{ unicode_literals }}from django.db import models
>>  ^
>> SyntaxError: invalid syntax
>> Successfully installed django
>> Cleaning up...
>
>
> Anyone else see this error? This was in an new virtualenv.
>
>
> On Tuesday, December 1, 2015 at 7:10:41 PM UTC-5, Tim Graham wrote:
>>
>> Django 1.9 is now available:
>>
>> https://www.djangoproject.com/weblog/2015/dec/01/django-19-released/ 
>> 
>>
>> With the release of Django 1.9, Django 1.7 has reached end-of-life. 
>> Django 1.7.11 is the final release of the 1.7 series and all users are 
>> encouraged to upgrade to Django 1.8+ as soon as possible so they can 
>> continue to receive security updates. Django 1.8 LTS will receive security 
>> updates until April 2018. Django 1.4 (the previous LTS) reached end of life 
>> on October 1, 2015. See the downloads page [1] for a table of supported 
>> versions and the future release schedule.
>>
>> [1] https://www.djangoproject.com/download/#supported-versions
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a64e46fe-938c-45c5-bcf7-ad65d17df8d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django 1.9 released

2015-12-02 Thread Luke Granger-Brown
On Wed, Dec 2, 2015 at 10:20 AM, Mike  wrote:

> pip install django
>> Downloading/unpacking django
>>   Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
>> Installing collected packages: django
>> Compiling
>> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py
>> ...
>>   File
>> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py",
>> line 4
>> class {{ camel_case_app_name }}Config(AppConfig):
>>   ^
>> SyntaxError: invalid syntax
>> Compiling
>> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py
>> ...
>>   File
>> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py",
>> line 1
>> {{ unicode_literals }}from django.db import models
>>  ^
>> SyntaxError: invalid syntax
>> Successfully installed django
>> Cleaning up...
>
>
> Anyone else see this error? This was in an new virtualenv.
>
It's mentioned in the release notes (specifically at
https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-with-pip-1-5-6
)


>

> On Tuesday, December 1, 2015 at 7:10:41 PM UTC-5, Tim Graham wrote:
>>
>> Django 1.9 is now available:
>>
>> https://www.djangoproject.com/weblog/2015/dec/01/django-19-released/
>> 
>>
>> With the release of Django 1.9, Django 1.7 has reached end-of-life.
>> Django 1.7.11 is the final release of the 1.7 series and all users are
>> encouraged to upgrade to Django 1.8+ as soon as possible so they can
>> continue to receive security updates. Django 1.8 LTS will receive security
>> updates until April 2018. Django 1.4 (the previous LTS) reached end of life
>> on October 1, 2015. See the downloads page [1] for a table of supported
>> versions and the future release schedule.
>>
>> [1] https://www.djangoproject.com/download/#supported-versions
>>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/04e0e7cb-250a-4eae-8745-4832c8f5eb2f%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALE3ZjV-z6wORaLaH4dk1B2FRyHpxC_ttJdaRdoZ9AqHF842gA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django doesn't remove the "old" file after change

2015-12-02 Thread Fellipe Henrique
I have one ImageField in my Model, but when I change the image, django
doesn't remove the old file.

How can I make these happen? when change the file, the old one need to be
deleted.

I use ImageKit, so I try to override *storage * method in ImageFile field,
but django start to save in my disk, not in Amazon S3 (default when I use
ImageKit).

So, any idea how can I fix these issue?

Regards.


T.·.F.·.A.·. S+F
*Fellipe Henrique P. Soares*

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
*Fedora Ambassador: https://fedoraproject.org/wiki/User:Fellipeh
*
*Blog: *http:www.fellipeh.eti.br
*GitHub: https://github.com/fellipeh *
*Twitter: @fh_bash*

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1jwZFPHNAwTkR0Gg87MavUS2Eq9j%3D%2BWjHhF5rweogRATipkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transitioning existing login portal to Django

2015-12-02 Thread 'Tom Evans' via Django users
On Tue, Dec 1, 2015 at 10:15 PM, Evan Palmer  wrote:
> Hello,
>
> Does anyone have experience with transitioning an existing database
> including user login data to Django?
>
> I am about to begin work on a startup's hand-written web portal that
> consists of about 2000 lines of custom Python code (hashing passwords,
> managing user accounts, DB connections, etc.), some Mako templates, and a
> Postgresql database. A hand-written web framework makes me nervous for many
> reasons. I don't have access to the source code or the database yet, but my
> plan is to transition it to Django 1.8. I'd like to use inspectdb to help
> generate the models, but I doubt inspectdb will be smart enough to handle
> usernames and password hashes properly. How can I make sure this data gets
> transferred correctly?
>
> I'm looking for ideas about how to proceed and/or what to expect during the
> transition. Thanks.

inspectdb will do a pretty decent stab of things, although there is
always some rewriting necessary in order to give the model attributes
appropriate names (they don't have to match the table column name,
that is what the db_column attribute is for).
Django does not support composite primary keys; where this will
particularly bite is on M2M "through" or "link" tables; 3NF/BCNF would
have those tables with (foreign_key_to_table_a,
foreign_key_to_table_b) as the primary key, where as django will want
a separate "id" column as a primary key.

For passwords, Django provides a password hashing framework:

https://docs.djangoproject.com/en/1.9/topics/auth/passwords/#how-django-stores-passwords

This allows you to define your own custom password hashing algorithm
to accommodate the existing passwords. Ideally, you will update the
stored passwords to the same format
("$$$"), defining your own custom
name for the algorithm.

Adding your new custom password hasher class to the end of
settings.PASSWORD_HASHERS will then allow users to authenticate, and
then on login or password change - basically, any time the system
verifies a plaintext password - the password hash will be updated to
the preferred hasher (settings.PASSWORD_HASHERS[0]).

If your current hashing algorithm is not secure, eg unsalted md5, then
after a certain amount of time (business decision), you should email
all users who have not got an up-to-date hash that in X weeks you will
reset their passwords and they will have to reset their password.

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1Lbru1PHcOsFQq0KSkOYMFvhnofUj9Bdjkv%3DduJwvTqFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Tim Graham
It will be easier to help if you can provide a sample project that 
reproduces the error.

On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>
> Hi,
>
> Am seeing that test case in suite are failing but passing when ran 
> individually.
> I have gone through most of the thread on the internet but did not find 
> any solution.
>
> Below is the snip of what am trying to do.
>
> class A(TestCase):
>   def test_a():
>create an obj in db
>retrive obj list from db and check the length of the list (should be 1)
>update same obj in db
>delte same obj in db
>
>  def b():
>   create an obj in db and check the length.
>
> When ran in suite test_a fails as the length of the list is 2.
> test_b() runs before test_a and leave the object in the database.
>
> From various threads suggested using 'django.test import TestCase' 
> instead of 'from django.unittest import TestCase' which am already doing.
>
> Is there anything else i need to do here ?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8ad70a1-4abf-406b-8668-a6d860a868bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Bill Freeman
Make test b clean up after itself, by deleting the test object.

On Wed, Dec 2, 2015 at 9:28 AM, Tim Graham  wrote:

> It will be easier to help if you can provide a sample project that
> reproduces the error.
>
> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>>
>> Hi,
>>
>> Am seeing that test case in suite are failing but passing when ran
>> individually.
>> I have gone through most of the thread on the internet but did not find
>> any solution.
>>
>> Below is the snip of what am trying to do.
>>
>> class A(TestCase):
>>   def test_a():
>>create an obj in db
>>retrive obj list from db and check the length of the list (should be 1)
>>update same obj in db
>>delte same obj in db
>>
>>  def b():
>>   create an obj in db and check the length.
>>
>> When ran in suite test_a fails as the length of the list is 2.
>> test_b() runs before test_a and leave the object in the database.
>>
>> From various threads suggested using 'django.test import TestCase'
>> instead of 'from django.unittest import TestCase' which am already doing.
>>
>> Is there anything else i need to do here ?
>>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f8ad70a1-4abf-406b-8668-a6d860a868bb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0sB7cLusW4-nCi%2BHgHSSYdYgRmCstPMFpb8v7ZcMAHp_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem to retrieve user type in custom submit_line.html template

2015-12-02 Thread Alessandro Peretti
Hello folk,

I have a problem with my submit_line.html. I added a button through " input 
type="submit" value="{% trans 'Send Email' %}" name="_send_email" />" to 
send an email. In my admin.py of my app I override the save_model method to 
send an email and save the new istance created inside the database. For 
this everything is good and work. Furthermore, I want to show my new button 
just for the staff users and not for the superusers. but it doesn't work. 
To do this I added {% if request.user.is_superuser%} but it doesn't 
work. It seems that  the variable user is outside the scope. How can I fix 
this?

Thanks in advance, 

Alessandro. :)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f8130ca-c8c4-48fa-90a2-c21fde3e45bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Issue: get user type in custom submit_line.html template

2015-12-02 Thread Alessandro Peretti
Hi folk,

I added a submit button in submit_line.html. I want to show it just for 
staff users and not for superusers.
So I inserted {% if request.user.is_superuser %} but it doesn't work. 
It seems that the django variable user is outside this scope. 
How can I fix it?

Thanks in advance.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/18d106e6-e543-47d1-a33c-6a7954e5dd14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Siddhi Divekar
Hi Tim,

Below is what am trying to achieve.

class OrcaTestCase(TestCase):

def test_customer_create_modify_delete(self):
'''Test customer object create, modify and delete operations in 
 DB.'''
# Create.
CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
  c_date_created=timezone.now(),
  c_date_updated=timezone.now())
customer_list = CustomerDb.objects.all()
   * self.assertEqual(len(customer_list), 1)*

# Modify.
customer = CustomerDb.objects.get(c_name='Pnc')
self.assertNotEqual(customer, None)
setattr(customer, 'c_name', 'Zoo')
customer.save()
customer_list = CustomerDb.objects.all()
self.assertEqual(len(customer_list), 1)
self.assertEqual(str(customer_list[0]), 'Gap')

# Delete.
customer = CustomerDb.objects.get(c_name='foo')
self.assertNotEqual(customer, None)
customer.delete()
customer_list = CustomerDb.objects.all()
self.assertEqual(len(customer_list), 0)

def test_create_customer(self):
'''Handle customer create.'''
customer_list = CustomerDb.objects.all()
self.assertEqual(len(customer_list), 1)

test_create_customer runs first, test_customer_create_modify_delete fails 
at the highlighted line.

On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:
>
> It will be easier to help if you can provide a sample project that 
> reproduces the error.
>
> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>>
>> Hi,
>>
>> Am seeing that test case in suite are failing but passing when ran 
>> individually.
>> I have gone through most of the thread on the internet but did not find 
>> any solution.
>>
>> Below is the snip of what am trying to do.
>>
>> class A(TestCase):
>>   def test_a():
>>create an obj in db
>>retrive obj list from db and check the length of the list (should be 1)
>>update same obj in db
>>delte same obj in db
>>
>>  def b():
>>   create an obj in db and check the length.
>>
>> When ran in suite test_a fails as the length of the list is 2.
>> test_b() runs before test_a and leave the object in the database.
>>
>> From various threads suggested using 'django.test import TestCase' 
>> instead of 'from django.unittest import TestCase' which am already doing.
>>
>> Is there anything else i need to do here ?
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d3a0973b-166c-49da-912d-08db8783d623%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Siddhi Divekar
Hi Ke1g,
That is the last option but
wanted to understand why database was not cleaned after first test.

On Wednesday, December 2, 2015 at 7:56:26 AM UTC-8, ke1g wrote:
>
> Make test b clean up after itself, by deleting the test object.
>
> On Wed, Dec 2, 2015 at 9:28 AM, Tim Graham  > wrote:
>
>> It will be easier to help if you can provide a sample project that 
>> reproduces the error.
>>
>> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>>>
>>> Hi,
>>>
>>> Am seeing that test case in suite are failing but passing when ran 
>>> individually.
>>> I have gone through most of the thread on the internet but did not find 
>>> any solution.
>>>
>>> Below is the snip of what am trying to do.
>>>
>>> class A(TestCase):
>>>   def test_a():
>>>create an obj in db
>>>retrive obj list from db and check the length of the list (should be 
>>> 1)
>>>update same obj in db
>>>delte same obj in db
>>>
>>>  def b():
>>>   create an obj in db and check the length.
>>>
>>> When ran in suite test_a fails as the length of the list is 2.
>>> test_b() runs before test_a and leave the object in the database.
>>>
>>> From various threads suggested using 'django.test import TestCase' 
>>> instead of 'from django.unittest import TestCase' which am already doing.
>>>
>>> Is there anything else i need to do here ?
>>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/f8ad70a1-4abf-406b-8668-a6d860a868bb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd9cfc5e-5c1c-450f-a91a-5cce46a9f6fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Bill Freeman
Did you see some documentation that said that the test framework will clear
the database?

I'm not sure that it's reasonable to ask a test framework to do that, given
the number of possible databases and interface layers, though it is
conceivable that django's variation on test could take care of this for the
ORM.

Still, explicit is better than implicit.

A common way to clean up, by the way, is to start a transaction in setUp()
and do a rollback in tearDown().

On Wed, Dec 2, 2015 at 11:21 AM, Siddhi Divekar 
wrote:

> Hi Ke1g,
> That is the last option but
> wanted to understand why database was not cleaned after first test.
>
> On Wednesday, December 2, 2015 at 7:56:26 AM UTC-8, ke1g wrote:
>>
>> Make test b clean up after itself, by deleting the test object.
>>
>> On Wed, Dec 2, 2015 at 9:28 AM, Tim Graham  wrote:
>>
>>> It will be easier to help if you can provide a sample project that
>>> reproduces the error.
>>>
>>> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:

 Hi,

 Am seeing that test case in suite are failing but passing when ran
 individually.
 I have gone through most of the thread on the internet but did not find
 any solution.

 Below is the snip of what am trying to do.

 class A(TestCase):
   def test_a():
create an obj in db
retrive obj list from db and check the length of the list (should be
 1)
update same obj in db
delte same obj in db

  def b():
   create an obj in db and check the length.

 When ran in suite test_a fails as the length of the list is 2.
 test_b() runs before test_a and leave the object in the database.

 From various threads suggested using 'django.test import TestCase'
 instead of 'from django.unittest import TestCase' which am already
 doing.

 Is there anything else i need to do here ?

>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/f8ad70a1-4abf-406b-8668-a6d860a868bb%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fd9cfc5e-5c1c-450f-a91a-5cce46a9f6fd%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0v_MQMDKBoJ9W3%2B-CX2efsObUyg0t_tBKYjeaGmDx%3D%3DOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


DataError on get_or_create with nullable fields

2015-12-02 Thread mccc
(this is mostly copied/pasted from my comment on an eight-years-old issue 
here )

I cannot get the get_or_create operation to create non-existing object with 
nullable field, getting a `DataError: integer out of range` error.

The query goes like so: 
`Test.objects.get_or_create(**{u'device_preference__isnull': True, 
u'test_type': u'TextTest', u'master_id': 1234, u'testset_id__isnull': 
True})` where `device_preference` is a nullable PositiveIntegerField and 
`testset_id` is a ForeignKey.

Attached traceback shows that the issue happens on creation, I believe.

{{{
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 407, in get_or_create
return self._create_object_from_params(lookup, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 439, in _create_object_from_params
obj = self.create(**params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 348, in create
obj.save(force_insert=True, using=self.db)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 734, in save
force_update=force_update, update_fields=update_fields)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 762, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, 
update_fields)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 846, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, 
raw)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 885, in _do_insert
using=using, raw=raw)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 920, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 974, in execute_sql
cursor.execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/utils.py", 
line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
DataError: integer out of range
}}}

I have not reopened the issue, just because, but I'd welcome any possible 
comment.
Thank you.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/15e8559a-dc36-492e-a49c-bd1d20135238%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread Tim Graham
How does the test fail? Please show the entire test file including imports.

On Wednesday, December 2, 2015 at 11:20:27 AM UTC-5, learn django wrote:
>
> Hi Tim,
>
> Below is what am trying to achieve.
>
> class OrcaTestCase(TestCase):
>
> def test_customer_create_modify_delete(self):
> '''Test customer object create, modify and delete operations in 
>  DB.'''
> # Create.
> CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
>   c_date_created=timezone.now(),
>   c_date_updated=timezone.now())
> customer_list = CustomerDb.objects.all()
>* self.assertEqual(len(customer_list), 1)*
>
> # Modify.
> customer = CustomerDb.objects.get(c_name='Pnc')
> self.assertNotEqual(customer, None)
> setattr(customer, 'c_name', 'Zoo')
> customer.save()
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
> self.assertEqual(str(customer_list[0]), 'Gap')
>
> # Delete.
> customer = CustomerDb.objects.get(c_name='foo')
> self.assertNotEqual(customer, None)
> customer.delete()
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 0)
>
> def test_create_customer(self):
> '''Handle customer create.'''
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
>
> test_create_customer runs first, test_customer_create_modify_delete fails 
> at the highlighted line.
>
> On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:
>>
>> It will be easier to help if you can provide a sample project that 
>> reproduces the error.
>>
>> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>>>
>>> Hi,
>>>
>>> Am seeing that test case in suite are failing but passing when ran 
>>> individually.
>>> I have gone through most of the thread on the internet but did not find 
>>> any solution.
>>>
>>> Below is the snip of what am trying to do.
>>>
>>> class A(TestCase):
>>>   def test_a():
>>>create an obj in db
>>>retrive obj list from db and check the length of the list (should be 
>>> 1)
>>>update same obj in db
>>>delte same obj in db
>>>
>>>  def b():
>>>   create an obj in db and check the length.
>>>
>>> When ran in suite test_a fails as the length of the list is 2.
>>> test_b() runs before test_a and leave the object in the database.
>>>
>>> From various threads suggested using 'django.test import TestCase' 
>>> instead of 'from django.unittest import TestCase' which am already doing.
>>>
>>> Is there anything else i need to do here ?
>>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3567d250-2339-4c3a-806a-c290d271f1b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread 'Tom Evans' via Django users
On Wed, Dec 2, 2015 at 4:20 PM, Siddhi Divekar
 wrote:
> Hi Tim,
>
> Below is what am trying to achieve.
>
> class OrcaTestCase(TestCase):
>
> def test_customer_create_modify_delete(self):
> '''Test customer object create, modify and delete operations in
> DB.'''
> # Create.
> CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
>   c_date_created=timezone.now(),
>   c_date_updated=timezone.now())
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
>
> # Modify.
> customer = CustomerDb.objects.get(c_name='Pnc')
> self.assertNotEqual(customer, None)
> setattr(customer, 'c_name', 'Zoo')
> customer.save()
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
> self.assertEqual(str(customer_list[0]), 'Gap')
>
> # Delete.
> customer = CustomerDb.objects.get(c_name='foo')
> self.assertNotEqual(customer, None)
> customer.delete()
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 0)
>
> def test_create_customer(self):
> '''Handle customer create.'''
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
>
> test_create_customer runs first, test_customer_create_modify_delete fails at
> the highlighted line.
>

You really really do not need to be testing that Django's CRUD
operations work - there is no value in doing so, since Django is well
tested.

Tests should concentrate on the custom business logic that your app
uses, not that when you create an object in the database, an object
exists in the database.

As to your question, what DB backend are you using for tests? Each
django.test.TestCase test is run inside a transaction that is rolled
back[1]; if your backend "supports" transactions by ignoring them
(cough, MySQL/MyISAM), then nothing happens when the transaction is
rolled back.

Cheers

Tom

[1] https://docs.djangoproject.com/en/1.9/topics/testing/overview/#writing-tests

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2B6W%3Dgg2op%2BFc5xKHDCE8QOhiZx-CdCdm6a%3DtWG3YvNEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: AttributeError: type object 'Product' has no attribute '_meta'

2015-12-02 Thread Lucas Vieira May
try this:


from django.db import models

# Create your models here.
class Product(models.Model):
item_name = models.CharField(max_length=100)
item_price = models.IntegerField()
item_image = models.ImageField()


def __unicode__(self):
return self.item_name


class Meta:
# Do not Forget the sign in front of the field
ordering = [-'item_name']

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0817402d-7f7f-4c51-828f-548650d07aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django 1.9 released

2015-12-02 Thread François Schiettecatte
I see the error too, no virtualenv or pip here, this is my install sequence:

tar zxf Django-1.9.tar.gz 
cd Django-1.9
python3 ./setup.py build
sudo python3 ./setup.py install

F.

> On Dec 2, 2015, at 5:31 AM, Luke Granger-Brown  wrote:
> 
> On Wed, Dec 2, 2015 at 10:20 AM, Mike  wrote:
> pip install django
> Downloading/unpacking django
>   Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
> Installing collected packages: django
> Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py ...
>   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py", 
> line 4
> class {{ camel_case_app_name }}Config(AppConfig):
>   ^
> SyntaxError: invalid syntax
> Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py 
> ...
>   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py",
>  line 1
> {{ unicode_literals }}from django.db import models
>  ^
> SyntaxError: invalid syntax
> Successfully installed django
> Cleaning up...
> 
> Anyone else see this error? This was in an new virtualenv.
> It's mentioned in the release notes (specifically at 
> https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-with-pip-1-5-6)
>  
> 
>  
> 
> On Tuesday, December 1, 2015 at 7:10:41 PM UTC-5, Tim Graham wrote:
> Django 1.9 is now available:
> 
> https://www.djangoproject.com/weblog/2015/dec/01/django-19-released/
> 
> With the release of Django 1.9, Django 1.7 has reached end-of-life. Django 
> 1.7.11 is the final release of the 1.7 series and all users are encouraged to 
> upgrade to Django 1.8+ as soon as possible so they can continue to receive 
> security updates. Django 1.8 LTS will receive security updates until April 
> 2018. Django 1.4 (the previous LTS) reached end of life on October 1, 2015. 
> See the downloads page [1] for a table of supported versions and the future 
> release schedule.
> 
> [1] https://www.djangoproject.com/download/#supported-versions
> 
> -- 
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/04e0e7cb-250a-4eae-8745-4832c8f5eb2f%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALE3ZjV-z6wORaLaH4dk1B2FRyHpxC_ttJdaRdoZ9AqHF842gA%40mail.gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/BFEF7F98-695C-4495-967D-14D47D4A4ADA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANNOUNCE] Django 1.9 released

2015-12-02 Thread Tim Graham
I later discovered that it's actually a bug in setuptools 5.5/5.5.1. I'll 
update the documentation.

On Wednesday, December 2, 2015 at 2:05:52 PM UTC-5, François Schiettecatte 
wrote:
>
> I see the error too, no virtualenv or pip here, this is my install 
> sequence: 
>
> tar zxf Django-1.9.tar.gz 
> cd Django-1.9 
> python3 ./setup.py build 
> sudo python3 ./setup.py install 
>
> F. 
>
> > On Dec 2, 2015, at 5:31 AM, Luke Granger-Brown  > wrote: 
> > 
> > On Wed, Dec 2, 2015 at 10:20 AM, Mike > 
> wrote: 
> > pip install django 
> > Downloading/unpacking django 
> >   Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded 
> > Installing collected packages: django 
> > Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py 
> ... 
> >   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/apps.py", 
> line 4 
> > class {{ camel_case_app_name }}Config(AppConfig): 
> >   ^ 
> > SyntaxError: invalid syntax 
> > Compiling 
> /Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py 
> ... 
> >   File 
> "/Users/mike/sieve2/SIEVEENV/build/django/django/conf/app_template/models.py",
>  
> line 1 
> > {{ unicode_literals }}from django.db import models 
> >  ^ 
> > SyntaxError: invalid syntax 
> > Successfully installed django 
> > Cleaning up... 
> > 
> > Anyone else see this error? This was in an new virtualenv. 
> > It's mentioned in the release notes (specifically at 
> https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-with-pip-1-5-6)
>  
>
> > 
> >   
> > 
> > On Tuesday, December 1, 2015 at 7:10:41 PM UTC-5, Tim Graham wrote: 
> > Django 1.9 is now available: 
> > 
> > https://www.djangoproject.com/weblog/2015/dec/01/django-19-released/ 
> > 
> > With the release of Django 1.9, Django 1.7 has reached end-of-life. 
> Django 1.7.11 is the final release of the 1.7 series and all users are 
> encouraged to upgrade to Django 1.8+ as soon as possible so they can 
> continue to receive security updates. Django 1.8 LTS will receive security 
> updates until April 2018. Django 1.4 (the previous LTS) reached end of life 
> on October 1, 2015. See the downloads page [1] for a table of supported 
> versions and the future release schedule. 
> > 
> > [1] https://www.djangoproject.com/download/#supported-versions 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/04e0e7cb-250a-4eae-8745-4832c8f5eb2f%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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CALE3ZjV-z6wORaLaH4dk1B2FRyHpxC_ttJdaRdoZ9AqHF842gA%40mail.gmail.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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/766f0e37-cf8f-40e7-a06b-ade8a9c237c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Resolving circular dependencies when squashing migrations

2015-12-02 Thread Nikolas Stevenson-Molnar
I'm attempting to squash migrations on my Django 1.8 project and am running 
into a mess of circular dependencies. The docs suggest in this case to "break 
out one of the ForeignKeys in the circular dependency loop into a separate 
migration, and move the dependency on the other app with it." [1] 

I was able to successfully do this, but that presents another problem: now I 
have an additional migration which Django attempts to run but fails because 
it's trying to run commands that have already been run and runs into duplicate 
column errors.

I realize I could --fake the necessary migrations, but that means manual 
intervention in every environment this is deployed to. Is there some other way 
I can do this? Or is the only solution to add the extra migration then --fake 
it everywhere?

_Nik

[1] 
https://docs.djangoproject.com/en/1.8/topics/migrations/#squashing-migrations

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2b5edf1-1037-4e44-9bb6-c225858414e2%40getmailbird.com.
For more options, visit https://groups.google.com/d/optout.


Best approach to write unit tests involving rest apis.

2015-12-02 Thread learn django
Hi,

My app uses rest framework.
I am writing test cases which involve standard requests like 
GET/POST/DELETE/PUT.
What is the best approach to write the test cases ?

Should I run the web server from unit test in setUp() (by running 'python 
manage.py runserver') so that http
request response can work. That way I can make sure my urls.py is correctly 
setup.

Or is there a better way to achieve the same ?

For now am calling my rest handlers directly by passing request (of type 
HttpRequest()) to it.
The request object is filled with required info which the backend code 
expects.

Since the handlers are called directly am unable to automate tests to make 
sure
urls are working fine.

Please give pointers as to how this can be done.
Thanks in advance.
  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7145ad6-cc76-4db6-ae1d-0167a5bc4fd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tests not passing in suite but pass individually

2015-12-02 Thread learn django
Below is the test file & logs.
No matter in which order (using --reverse) I run the suite it fails.
The database backend is postgres. Is that an issue ?

File:-
===
import datetime
import pdb

from rest_framework import status
from rest_framework.test import APIClient

from django.http import HttpRequest
from django.contrib.auth.models import User
from django.utils import timezone
from django.test import TestCase

from orca.models import *

import orca.handlers.customer_handler as ch

# Create your tests here.
class OrcaTestCase(TestCase):

def test_customer_create_modify_delete(self):
'''Test customer object create, modify and delete operations in 
 DB.'''
# Create.
CustomerDb.objects.create(c_name='Zoo', c_role='Admin',
  c_date_created=timezone.now(),
  c_date_updated=timezone.now())
customer_list = CustomerDb.objects.all()
self.assertEqual(len(customer_list), 1)

def test_launch(self):
'''Test launch.'''
CustomerDb.objects.create(c_name='Foo', c_role='Admin',
  c_date_created=timezone.now(),
  c_date_updated=timezone.now())
customer_list = CustomerDb.objects.all()
self.assertEqual(len(customer_list), 1)


Logs:-

==
FAIL: test_customer_create_modify_delete (orca.tests.tmp.OrcaTestCase)
Test customer object create, modify and delete operations in  DB.
--
Traceback (most recent call last):
  File "/home/sidhesh/workspace/sztp/orca/tests/tmp.py", line 26, in 
test_customer_create_modify_delete
self.assertEqual(len(customer_list), 1)
AssertionError: 2 != 1

--
Ran 2 tests in 0.014s

FAILED (failures=1)



On Wednesday, December 2, 2015 at 9:14:54 AM UTC-8, Tim Graham wrote:
>
> How does the test fail? Please show the entire test file including imports.
>
> On Wednesday, December 2, 2015 at 11:20:27 AM UTC-5, learn django wrote:
>>
>> Hi Tim,
>>
>> Below is what am trying to achieve.
>>
>> class OrcaTestCase(TestCase):
>>
>> def test_customer_create_modify_delete(self):
>> '''Test customer object create, modify and delete operations in 
>>  DB.'''
>> # Create.
>> CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
>>   c_date_created=timezone.now(),
>>   c_date_updated=timezone.now())
>> customer_list = CustomerDb.objects.all()
>>* self.assertEqual(len(customer_list), 1)*
>>
>> # Modify.
>> customer = CustomerDb.objects.get(c_name='Pnc')
>> self.assertNotEqual(customer, None)
>> setattr(customer, 'c_name', 'Zoo')
>> customer.save()
>> customer_list = CustomerDb.objects.all()
>> self.assertEqual(len(customer_list), 1)
>> self.assertEqual(str(customer_list[0]), 'Gap')
>>
>> # Delete.
>> customer = CustomerDb.objects.get(c_name='foo')
>> self.assertNotEqual(customer, None)
>> customer.delete()
>> customer_list = CustomerDb.objects.all()
>> self.assertEqual(len(customer_list), 0)
>>
>> def test_create_customer(self):
>> '''Handle customer create.'''
>> customer_list = CustomerDb.objects.all()
>> self.assertEqual(len(customer_list), 1)
>>
>> test_create_customer runs first, test_customer_create_modify_delete fails 
>> at the highlighted line.
>>
>> On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:
>>>
>>> It will be easier to help if you can provide a sample project that 
>>> reproduces the error.
>>>
>>> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:

 Hi,

 Am seeing that test case in suite are failing but passing when ran 
 individually.
 I have gone through most of the thread on the internet but did not find 
 any solution.

 Below is the snip of what am trying to do.

 class A(TestCase):
   def test_a():
create an obj in db
retrive obj list from db and check the length of the list (should be 
 1)
update same obj in db
delte same obj in db

  def b():
   create an obj in db and check the length.

 When ran in suite test_a fails as the length of the list is 2.
 test_b() runs before test_a and leave the object in the database.

 From various threads suggested using 'django.test import TestCase' 
 instead of 'from django.unittest import TestCase' which am already 
 doing.

 Is there anything else i need to do here ?

>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receivi

Re: Tests not passing in suite but pass individually

2015-12-02 Thread Tim Graham
It looks correct. I'd like a minimal project I could download to reproduce 
the issue. In putting that together, you might discover the reason for the 
failure.

On Wednesday, December 2, 2015 at 6:29:07 PM UTC-5, learn django wrote:
>
> Below is the test file & logs.
> No matter in which order (using --reverse) I run the suite it fails.
> The database backend is postgres. Is that an issue ?
>
> File:-
> ===
> import datetime
> import pdb
>
> from rest_framework import status
> from rest_framework.test import APIClient
>
> from django.http import HttpRequest
> from django.contrib.auth.models import User
> from django.utils import timezone
> from django.test import TestCase
>
> from orca.models import *
>
> import orca.handlers.customer_handler as ch
>
> # Create your tests here.
> class OrcaTestCase(TestCase):
>
> def test_customer_create_modify_delete(self):
> '''Test customer object create, modify and delete operations in 
>  DB.'''
> # Create.
> CustomerDb.objects.create(c_name='Zoo', c_role='Admin',
>   c_date_created=timezone.now(),
>   c_date_updated=timezone.now())
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
>
> def test_launch(self):
> '''Test launch.'''
> CustomerDb.objects.create(c_name='Foo', c_role='Admin',
>   c_date_created=timezone.now(),
>   c_date_updated=timezone.now())
> customer_list = CustomerDb.objects.all()
> self.assertEqual(len(customer_list), 1)
>
>
> Logs:-
> 
> ==
> FAIL: test_customer_create_modify_delete (orca.tests.tmp.OrcaTestCase)
> Test customer object create, modify and delete operations in  DB.
> --
> Traceback (most recent call last):
>   File "/home/sidhesh/workspace/sztp/orca/tests/tmp.py", line 26, in 
> test_customer_create_modify_delete
> self.assertEqual(len(customer_list), 1)
> AssertionError: 2 != 1
>
> --
> Ran 2 tests in 0.014s
>
> FAILED (failures=1)
>
>
>
> On Wednesday, December 2, 2015 at 9:14:54 AM UTC-8, Tim Graham wrote:
>>
>> How does the test fail? Please show the entire test file including 
>> imports.
>>
>> On Wednesday, December 2, 2015 at 11:20:27 AM UTC-5, learn django wrote:
>>>
>>> Hi Tim,
>>>
>>> Below is what am trying to achieve.
>>>
>>> class OrcaTestCase(TestCase):
>>>
>>> def test_customer_create_modify_delete(self):
>>> '''Test customer object create, modify and delete operations in 
>>>  DB.'''
>>> # Create.
>>> CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
>>>   c_date_created=timezone.now(),
>>>   c_date_updated=timezone.now())
>>> customer_list = CustomerDb.objects.all()
>>>* self.assertEqual(len(customer_list), 1)*
>>>
>>> # Modify.
>>> customer = CustomerDb.objects.get(c_name='Pnc')
>>> self.assertNotEqual(customer, None)
>>> setattr(customer, 'c_name', 'Zoo')
>>> customer.save()
>>> customer_list = CustomerDb.objects.all()
>>> self.assertEqual(len(customer_list), 1)
>>> self.assertEqual(str(customer_list[0]), 'Gap')
>>>
>>> # Delete.
>>> customer = CustomerDb.objects.get(c_name='foo')
>>> self.assertNotEqual(customer, None)
>>> customer.delete()
>>> customer_list = CustomerDb.objects.all()
>>> self.assertEqual(len(customer_list), 0)
>>>
>>> def test_create_customer(self):
>>> '''Handle customer create.'''
>>> customer_list = CustomerDb.objects.all()
>>> self.assertEqual(len(customer_list), 1)
>>>
>>> test_create_customer runs first, test_customer_create_modify_delete 
>>> fails at the highlighted line.
>>>
>>> On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:

 It will be easier to help if you can provide a sample project that 
 reproduces the error.

 On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar 
 wrote:
>
> Hi,
>
> Am seeing that test case in suite are failing but passing when ran 
> individually.
> I have gone through most of the thread on the internet but did not 
> find any solution.
>
> Below is the snip of what am trying to do.
>
> class A(TestCase):
>   def test_a():
>create an obj in db
>retrive obj list from db and check the length of the list (should 
> be 1)
>update same obj in db
>delte same obj in db
>
>  def b():
>   create an obj in db and check the length.
>
> When ran in suite test_a fails as the length of the list is 2.
> test_b() 

Re: Tests not passing in suite but pass individually

2015-12-02 Thread learn django
Will try to send minimal project by end of the day.
Hopefully I can discover the reason during this exercise.

On Wednesday, December 2, 2015 at 3:33:30 PM UTC-8, Tim Graham wrote:
>
> It looks correct. I'd like a minimal project I could download to reproduce 
> the issue. In putting that together, you might discover the reason for the 
> failure.
>
> On Wednesday, December 2, 2015 at 6:29:07 PM UTC-5, learn django wrote:
>>
>> Below is the test file & logs.
>> No matter in which order (using --reverse) I run the suite it fails.
>> The database backend is postgres. Is that an issue ?
>>
>> File:-
>> ===
>> import datetime
>> import pdb
>>
>> from rest_framework import status
>> from rest_framework.test import APIClient
>>
>> from django.http import HttpRequest
>> from django.contrib.auth.models import User
>> from django.utils import timezone
>> from django.test import TestCase
>>
>> from orca.models import *
>>
>> import orca.handlers.customer_handler as ch
>>
>> # Create your tests here.
>> class OrcaTestCase(TestCase):
>>
>> def test_customer_create_modify_delete(self):
>> '''Test customer object create, modify and delete operations in 
>>  DB.'''
>> # Create.
>> CustomerDb.objects.create(c_name='Zoo', c_role='Admin',
>>   c_date_created=timezone.now(),
>>   c_date_updated=timezone.now())
>> customer_list = CustomerDb.objects.all()
>> self.assertEqual(len(customer_list), 1)
>>
>> def test_launch(self):
>> '''Test launch.'''
>> CustomerDb.objects.create(c_name='Foo', c_role='Admin',
>>   c_date_created=timezone.now(),
>>   c_date_updated=timezone.now())
>> customer_list = CustomerDb.objects.all()
>> self.assertEqual(len(customer_list), 1)
>>
>>
>> Logs:-
>> 
>> ==
>> FAIL: test_customer_create_modify_delete (orca.tests.tmp.OrcaTestCase)
>> Test customer object create, modify and delete operations in  DB.
>> --
>> Traceback (most recent call last):
>>   File "/home/sidhesh/workspace/sztp/orca/tests/tmp.py", line 26, in 
>> test_customer_create_modify_delete
>> self.assertEqual(len(customer_list), 1)
>> AssertionError: 2 != 1
>>
>> --
>> Ran 2 tests in 0.014s
>>
>> FAILED (failures=1)
>>
>>
>>
>> On Wednesday, December 2, 2015 at 9:14:54 AM UTC-8, Tim Graham wrote:
>>>
>>> How does the test fail? Please show the entire test file including 
>>> imports.
>>>
>>> On Wednesday, December 2, 2015 at 11:20:27 AM UTC-5, learn django wrote:

 Hi Tim,

 Below is what am trying to achieve.

 class OrcaTestCase(TestCase):

 def test_customer_create_modify_delete(self):
 '''Test customer object create, modify and delete operations in 
  DB.'''
 # Create.
 CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin',
   c_date_created=timezone.now(),
   c_date_updated=timezone.now())
 customer_list = CustomerDb.objects.all()
* self.assertEqual(len(customer_list), 1)*

 # Modify.
 customer = CustomerDb.objects.get(c_name='Pnc')
 self.assertNotEqual(customer, None)
 setattr(customer, 'c_name', 'Zoo')
 customer.save()
 customer_list = CustomerDb.objects.all()
 self.assertEqual(len(customer_list), 1)
 self.assertEqual(str(customer_list[0]), 'Gap')

 # Delete.
 customer = CustomerDb.objects.get(c_name='foo')
 self.assertNotEqual(customer, None)
 customer.delete()
 customer_list = CustomerDb.objects.all()
 self.assertEqual(len(customer_list), 0)

 def test_create_customer(self):
 '''Handle customer create.'''
 customer_list = CustomerDb.objects.all()
 self.assertEqual(len(customer_list), 1)

 test_create_customer runs first, test_customer_create_modify_delete 
 fails at the highlighted line.

 On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:
>
> It will be easier to help if you can provide a sample project that 
> reproduces the error.
>
> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar 
> wrote:
>>
>> Hi,
>>
>> Am seeing that test case in suite are failing but passing when ran 
>> individually.
>> I have gone through most of the thread on the internet but did not 
>> find any solution.
>>
>> Below is the snip of what am trying to do.
>>
>> class A(TestCase):
>>   def test_a():
>>create an

Re: RemoteUserMiddleware stay logged in

2015-12-02 Thread Dan Davis
Thanks,

I can probably just install it and use it.   If I must stay in 1.8 for some 
arcane reason, I can read the code at https://github.com/django/django.

On Monday, November 30, 2015 at 8:29:00 PM UTC-5, Tim Graham wrote:
>
> Does the PersistentRemoteUserMiddleware added in Django 1.9 help?
>
>
> https://docs.djangoproject.com/en/1.9/howto/auth-remote-user/#using-remote-user-on-login-pages-only
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a5ea3adf-1e9e-491d-abdb-67437ce23f75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best approach to write unit tests involving rest apis.

2015-12-02 Thread Xavier Ordoquy
Hi,

> Le 3 déc. 2015 à 00:12, learn django  a écrit :
> 
> My app uses rest framework.
> I am writing test cases which involve standard requests like 
> GET/POST/DELETE/PUT.
> What is the best approach to write the test cases ?

Django REST framework comes with a test client named APIClient.
It will go through the middleware and urls before calling your API entry points 
which seems to be what you’re looking for.
The documentation about it is available at 
http://www.django-rest-framework.org/api-guide/testing/#apiclient

Regards,
Xavier,
Linovia.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C9F5286E-8261-47C3-8F0C-959EBF267E49%40linovia.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: Best approach to write unit tests involving rest apis.

2015-12-02 Thread learn django
 On Wednesday, December 2, 2015 at 10:48:52 PM UTC-8, Xavier Ordoquy wrote:
>
> Hi, 
>
> > Le 3 déc. 2015 à 00:12, learn django  > a écrit : 
> > 
> > My app uses rest framework. 
> > I am writing test cases which involve standard requests like 
> GET/POST/DELETE/PUT. 
> > What is the best approach to write the test cases ? 
>
> Django REST framework comes with a test client named APIClient. 
> It will go through the middleware and urls before calling your API entry 
> points which seems to be what you’re looking for. 
> The documentation about it is available at 
> http://www.django-rest-framework.org/api-guide/testing/#apiclient 
>
> Regards, 
> Xavier, 
> Linovia. 
>
>
Hi Linovia,

Yes, I started with that.
Initially I was getting 403 (auth failure) since my backend handlers have 
@login_required decorator.

To overcome that i created a super user (python manage.py superuser) &
used those credentials as below.

# url = '/orca/api/v2/customer/'
# data = {'c_name':'Pnc', 'c_role':'API-Admin'}
# client = APIClient()
# client.login(username='admin', password='admin')
# response = client.post(url, data, format='json') 

After this I started was getting 302 (redirects).
Have you encountered similar issue before ?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0dab1a9-6b99-462b-911e-f098a4aea79e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.