Re: Unit testing for apis

2015-11-24 Thread David Palao
Hi,
I was browsing the EuroPython 2015 videos and found a talk titled "TDD
for APIs". I have not watched it, but you might be interested in it:
https://www.youtube.com/watch?v=Okz6agNgaTA=51=PL8uoeex94UhGGUH0mFb-StlZ1WYGWiJfP
Best

2015-11-24 11:27 GMT+01:00 Kishan Mehta :
> Hi All,
>
> How can I write negative unit test cases for api endpoints
> I am using django.tests.TestCase for unit testing.
>
> Thanks,
> Kishan
>
> --
> 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/d67330b4-e495-4ae3-9898-2d9d980ec6e4%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/CAKUKWz%3D3NreQyh1eCfnwSqy0AcOuESR3mo9gvdbj%3D4L3thJL8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Version

2015-04-21 Thread David Palao
Hello,
Your question is too vague. Also some context would be helpful.
What system you are working on? What Python version? How did you
install django? What are you trying to do? What database you are
interested in?
For example.

Best

2015-04-21 12:47 GMT+02:00 Parikshit Mishra :
> hello  everyone.
>
> I hv installed django but it is version 1.3.1.Please tell me how to update
> it to 1.4 .Also how to install data base pls help me.
>
> --
> 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/03833081-c126-4899-89a2-37da1498d65b%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/CAKUKWzmdYYJs4Yv4TgTa%2BqMuV879ChVsEpyUBB_vcbEYZZ%3Djdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django

2015-04-21 Thread David Palao
Hello,
I suggest you to go to
https://www.djangoproject.com/
and have a look at the docs in there.

Best

2015-04-21 7:23 GMT+02:00 Parikshit Mishra :
> hello I want to learn django from scratch please help me
>
> --
> 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/4dd07109-7b84-49f2-8d02-5c1f03225de3%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/CAKUKWzmE0h1VSQBq9rTk%3DLLtxNfCY48DZ3YDynRNVhvA3tfEcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create models table from exists database?

2015-04-21 Thread David Palao
Hi,
Yes, in principle you can.The keywords are "legacy database":
https://docs.djangoproject.com/en/1.8/howto/legacy-databases/

Best

2015-04-21 9:15 GMT+02:00 Dario Concilio :
> Hi to all!
> I'm new of django, I've a question for you: Can I create a new project using
> an exists database?
>
> I've a domotic system on Ubuntu Server, with a Postgres database that has
> several table. Actually the system uses a table by a python service and PHP
> portal for data management of domotic configuration.
>
> I would change portal admin with a "django" portal, can I create a new
> django project using this database?
> Django framework allows me to generate the system tables and complete models
> (model.py) from existing ones?
>
> PS: I imagine this approach as the technique called "Database First" of
> various ORM.
>
> Thanks to all.
>
> --
> 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/e38f24fd-ebce-40ff-b53b-b94c5234d07a%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/CAKUKWznN00eCQCXXzxwxMe3j%2BaamQ9jAtGTT17_Sg23JkknW0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Putting Limits on Memory and CPU Usage in python ?

2015-04-21 Thread David Palao
Hi,
Have you had a look at "psutil"? It is a python module to manage processes.

Best

2015-04-21 9:20 GMT+02:00 SHINTO PETER :
> Hi
> François Schiettecatte , limit memory and CPU usage for python socket client
> service
>
> On Mon, Apr 20, 2015 at 11:24 PM, François Schiettecatte
>  wrote:
>>
>> Bummer, shows how long it has been since I have used that.
>>
>> Peter, why do you want to limit memory and CPU usage? To prevent someone
>> from killing the machine ?
>>
>> F.
>>
>> > On Apr 20, 2015, at 1:47 PM, Tim Chase 
>> > wrote:
>> >
>> > On 2015-04-20 13:13, François Schiettecatte wrote:
>> >> You don’t say what platform you are running on, but on linux/unix
>> >> you can use ulimit, see http://ss64.com/bash/ulimit.html
>> >
>> > I've wanted this occasionally, but "ulimit -m" doesn't appear to work
>> > on most modern Linux installations.  See
>> >
>> >
>> > http://unix.stackexchange.com/questions/129587/does-ulimit-m-not-work-on-modern-linux
>> >
>> > for more info.
>> >
>> > I'm not sure *why* it was removed, as there have been times I wanted
>> > this functionality (I'm looking at you, Firefox, and your
>> > memory-gorging habits) so it would be awfully helpful to have
>> > around.  I also just tested "ulimit -m" on OpenBSD and it too seems
>> > to let the RSS of the process grow beyond the specified limit.  I've
>> > got a FreeBSD laptop around here that I could test as well if I can
>> > find the power adaptor.
>> >
>> > -tkc
>> >
>> >
>> >
>> > --
>> > 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/20150420124711.0f49d04d%40bigbox.christie.dr.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/LE6J4sRujbQ/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/E8425E9D-C9B9-4474-B6BC-3B719C599D23%40gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> SHINTO PETER
> NIRAPPIL
> 09591040010
>
> --
> 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/CAKggVnC%3DJGo%2BKxfE21%3DGAJY%2BTS%3DhTCJ8Ba1ZAVupLAHFanA1Yw%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/CAKUKWznQC3K0E044R4a1G-%2B067X1a-j9twrT_TBpear%2BS47cOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models not appearing in db. Am I missing something?

2014-12-15 Thread David Palao
Hello,
>From your post I understand you did not write unittests for your models?
I would recommend to write some sensible tests for them and start
tracing your problem from the failures you should get.
Best,

David

2014-12-15 8:15 GMT+01:00 Shazwi Suwandi :
> I've added 'core' to settings.py file under INSTALLED_APPS too.
>
>
> On Monday, 15 December 2014 15:10:12 UTC+8, Shazwi Suwandi wrote:
>>
>> from django.db import models
>> from django.contrib.auth.models import User
>>
>> # CORE APPLICATION
>> # Create your models here.
>> class Member(models.Model):
>> user = models.OneToOneField(User)
>> description = models.CharField(max_length=250)
>> date_of_birth = models.DateField()
>> location = models.CharField(max_length=100)
>> gender = models.CharField(max_length=15)
>>
>> class NewTable(models.Model):
>> test = models.CharField(max_length=25)
>>
>> I've created some models and I used makemigrations and migrate. I went to
>> my db and checked that only the default tables are there (auth_group ...
>> django_session). I know that my connection settings are right and that I see
>> new rows being added to the auth_user table when I create users in django
>> admin page.
>>
>> Is there something that I must have missed out?
>
> --
> 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/7af04f16-09a8-458d-8857-c71694394101%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/CAKUKWzmd-7Qqf58E5QpBTc6SkMBTXQcZ0QL7WsPbHt%2Ba0rameA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to test an application that's using a legacy database

2014-11-12 Thread David Palao
2014-11-12 0:25 GMT+01:00 Carl Meyer :
> Hi David,
>
> On 11/11/2014 08:37 AM, dpalao.pyt...@gmail.com wrote:
>> Dear Carl,
>>
>> Thank you for the answer.
>>
>> On Tuesday, November 11, 2014 3:13:18 PM UTC+1, Carl Meyer wrote:
>>
>> Hi David,
>>
>> On 11/11/2014 07:01 AM, dpalao...@gmail.com  wrote:
>> > I see your point. You might be right, but it is not clear to me
>> how to
>> > do it and if it would work: I have already tried to subclass
>> > DiscoverRunner to modify its behaviour with little success.
>>
>> If there are specific aspects of "how to do it" that are confusing to
>> you, I could try to clarify. Or if you try it and have specific
>> problems.
>>
>>
>> Well, I never worked with sql directly. And as I said in my post when I
>> tried to subclass  DiscoverRunner I got the impression that it is not
>> straightforward (at least for my limited experience with Django).
>>
>> > Another problem that I see: it is not an homogenous approach. I mean,
>> > the models are created from the production database. Now I create an
>> > independent database for testing. Of course, you will tell me that I
>> > have to follow the TDD approach to the end: for the code that creates
>> > the testing database too! And I would agree. But it is clearly a
>> bit too
>> > complicated.
>>
>> I'm afraid I am quite confused by this paragraph.
>>
>> I don't know what you mean by "not an homogenous approach".
>>
>> And I don't know what you mean by "the models are created from the
>> production database."
>>
>> And I don't know what you mean by "an independent database for
>> testing."
>> Django already creates a new database for each test run. I'm not
>> suggesting creating any additional database beyond that, just running
>> some SQL to create your legacy (un-managed) tables in the testing
>> database.
>>
>> The code that creates the testing database will be exercised at the
>> start of every test run, and if it's not working your tests will fail
>> because the legacy tables are not created. Personally, I'd consider
>> that
>> adequate; I wouldn't write any additional tests for that code.
>>
>>
>>  I created the models by running "inspectdb". I see that as a (logical)
>> link between the models and the tables. Perhaps not the standard link,
>> but they are related. That is what I meant by "the models are created
>> from the production database".
>
> I see, that makes sense.
>
>> Now your suggestion is to create some tables from scratch. By hand. This
>> is what I mean by "not an homogeneous approach", because I don't see a
>> logical link between the models and the testing database. The testing
>> database is created by me. (Or by Django, then I take control to create
>> the tables, then I return control to Django -- if this is what you suggest).
>
> Sorry, I didn't fully explain this part of my suggestion. I would not
> create the SQL for those tables "by hand" - I would do it via a dump of
> the SQL schema from the actual production tables.
>
>> But actually I think your solution makes a lot of sense. At the
>> beginning I wanted Django to create the testing database along with the
>> tables automatically. And you probably are right and the SQL code to
>> create the tables is absolutely trivial, but for me it is not.
>> So I tried also something slightly different. As the database already
>> exists, I think it would make sense if I also the testing database
>> exists prior to testing.
>> What I just did was:
>> I created the testing database simply with a command like
>>
>> mysqldump -u user --password='xxx' -h localhost -d production_db | mysql
>> -h localhost -u user --passwor='xxx' -Dtest_db
>
> So this is close to my suggestion. But rather than creating the entire
> DB (including managed models too), I would send the dump to a SQL file
> instead:
>
> mysqldump -u user --password='xxx' -h localhost -d production_db >
> schema.sql
>
> And then edit schema.sql to remove any tables for normal managed models,
> leaving only the table definitions for the unmanaged (legacy) tables.
> (You might also add `--no-data`, depending whether you want your legacy
> tables to also be prepopulated with data for your tests).
>
> Then you can allow Django to create its test database normally, and run
> migrations to create tables for your managed models; you just have to
> additionally run `schema.sql` to add in the un-managed tables.
>
> (It's possible that your approach of pre-creating the entire test DB
> could just work, with no need to subclass DiscoverRunner at all, by
> using the --keepdb option to manage.py test; but that option only exists
> in the Django development version, so you probably don't have it.)
>
>> Again, I must subclassing DiscoverRunner to have a chance to succeed
>> (need to by-pass db creation), and actually Django complains if I don't
>> do that.
>> So, I subclassed 

Re: running unit tests with legacy database: Error 1050, Table already exists

2014-11-06 Thread David Palao
Hi Collin,
Thanks a lot for the answer. I think you are right, and that was what
I was doing. Still, apparently the models could not be created
properly, or whatever.

However I think I managed to convert this problem to a different one
(not sure if I should start a new thread).
What I did was: remove the __pycache__ dirs, remake the migrations,
and remove some models that were created by inspectdb (django
related).

Now, the original problem has gone, BUT something (related, I think)
happens. With _meta.managed=False in my models I get
...
django.db.utils.ProgrammingError: Table 'test_job_mon.job_info' doesn't exist

The test I'm running is very simple:

class HomePageTest(TestCase):
def setUp(self):
from django.db.models.loading import get_models
self.unmanaged_models = [m for m in get_models() if not m._meta.managed]
for m in self.unmanaged_models:
m._meta.managed = True

def tearDown(self):
for m in self.unmanaged_models:
m._meta.managed = False

def test_there_are_no_job_items_in_empty_db(self):
njobs = JobInfo.objects.count()
self.assertEqual(njobs, 0)



The relevant model:

class JobInfo(models.Model):
job_db_inx = models.IntegerField(primary_key=True)
id_job = models.IntegerField()
id_user = models.IntegerField()
id_group = models.IntegerField()
account = models.TextField(blank=True)
cpus_req = models.IntegerField()
cpus_alloc = models.IntegerField()
nodelist = models.TextField()
nodes_alloc = models.IntegerField()
partition = models.TextField()
time_start = models.IntegerField()
time_end = models.IntegerField()
was_updated = models.IntegerField()
jobmondatacleared =
models.IntegerField(db_column='jobMonDataCleared')  # Field name made
lowercase.
endupcount = models.IntegerField(db_column='endUpCount')  # Field
name made lowercase.
approved = models.IntegerField()

class Meta:
managed = False
db_table = 'job_info'


Now, if I comment the line "managed = False" and run makemigrations,
the test passes.

But I have checked that "managed" is switched to True during the tests.

Any ideas?

Thanks in advance,

David

2014-11-05 18:45 GMT+01:00 Collin Anderson :
> Hi David,
>
> Interesting. Shouldn't the test database be a separate, fresh, empty
> database (not a legacy database)?
>
> Thanks,
> Collin
>
> --
> 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/b79d8ab2-38ef-489d-9563-c2474c58defb%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/CAKUKWzm_8fM0fXW2DcAQsvYffXeN3indxtqtQHzsQ6U5_K7RWA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.