Page MenuHomePhabricator

Provide a pytest for database of wikilabels
Closed, ResolvedPublic

Description

Currently, database modules of wikilabels doesn't have any pytest attached to them: https://github.com/wiki-ai/wikilabels/tree/master/wikilabels/database

Your task is to write a pytest.

Event Timeline

Halfak lowered the priority of this task from Normal to Low.
Aklapper renamed this task from pytest for database of wikilabels to Provide a pytest for database of wikilabels.Nov 25 2017, 9:41 PM
Aklapper updated the task description. (Show Details)
Aklapper moved this task from Proposed tasks to Imported in GCI Site on the Google-Code-in-2017 board.

https://travis-ci.org/eisenhaus335/wikilabels/builds/315706960#L1751
i was sure i am already checking the form to create a new item.
The problem i was facing why the log show me that i am creating ID on number 1. Note that on campaign.py.DB.create() the sql code was showing its was using INSERT so i am sure its creating ID and without knowing the ID number so its must generate a new one. Thats the confuse part because its said i am creating duplicate item on unique key and that is "ID"

This definitely needs more work, one thing can be that the database has not been properly set up.

I am found a bug and i am already fix it. I am still wondering what i just do and the true meaning of it. Take a look on this test https://travis-ci.org/eisenhaus335/wikilabels/builds/317939040. My test_campaign_create() and test_campaign_get() is passed. Module that i am using is https://github.com/eisenhaus335/wikilabels/blob/a8b87f69d2b853509995ccc890b61c0df77c10df/wikilabels/tests/test_database.py here.

My problem was the id is not re indexed as you can see on chat history. I am worry this solution is not optimum and eating performance but you can suggest what i can improve

My solution was using cursor.execute("SELECT setval('campaign_id_seq', (SELECT MAX(id) FROM campaign)+1)") to create method on campaign module. I worry again this might result on eat performance and might result new bug

Ladsgroup added a comment.EditedDec 18 2017, 11:23 PM

Even though performance is not the case in here because the module is used ~once a week in prod, that idea seems like a very bad practice that should be avoided, if it was only on test code, it would be okay-ish but I don't recommend doing this in production code.

These are options:

  • Have you tried ignore errors when creating the campaign? It might be created before and we might have a unique index preventing duplicates.
  • If your fix only needs a schema change to add an index, do it, make a patch and I review it :)

i am edit that now. i am just gonna reset the sequence on the module tests so i can test it on my "online testing service"

Ladsgroup closed this task as Resolved.May 2 2018, 2:48 PM