Commit 1ae71133 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Merge branch '31-factory-boy-tests' into 'dev'

start using factory boy for tests

Closes #31

See merge request !11
parents b0ae5b9e c6933a0c
Pipeline #13701 passed with stages
in 2 minutes and 14 seconds
......@@ -25,6 +25,8 @@ wcwidth = "*"
zipp = "*"
Cycler = "*"
jupyter = "*"
factory-boy = "*"
pytest-factoryboy = "*"
[packages]
certifi = "*"
......
{
"_meta": {
"hash": {
"sha256": "3f969624ad2843dc98988e65ec5cddd38dc5f191e7250153d491f3467d197606"
"sha256": "d669f354e8994bdf3d7ba50fa5966b453792364ae116e1efbf8460a33b1fa4f9"
},
"pipfile-spec": 6,
"requires": {
......@@ -289,35 +289,32 @@
},
"ruamel.yaml": {
"hashes": [
"sha256:4c1dbad22790b5ea8587c2a0cae97ebc7a9d0d88de5d0edb70dea2eab7d8534a",
"sha256:eb4b1ffd095785c50f110118cb6f7bb9cd011ecc013b014436d38b7f8fb7afa9"
"sha256:547aeab5c51c93bc750ed2a320c1559b605bde3aa569216aa75fd91d8a1c4623"
],
"version": "==0.16.0"
"version": "==0.16.1"
},
"ruamel.yaml.clib": {
"hashes": [
"sha256:32c37bdc7ee5fbc5e794b497b98f98ecc12e1f1541cdd3bbd65f8ec32e0270d2",
"sha256:385b70734435d2f66f00823d4e224c1a4b53dfeaf9ded3a655a6a2f9c229b1f6",
"sha256:4040ddea350698138e341395508b8dd7610b2312177cb41c8db2b6260adee348",
"sha256:4dc088e55e0cc3f8c18652e830e3ecff159425f01327de4d94e5ce473fdcd2f8",
"sha256:53768934bc28ce07ca82c02d9db6717ae9bad4cdf9511d3a3e6d1b576235d04e",
"sha256:53fd2ef53be8301707662f4c353731d97a4cb2b372972b7dcd73ef245dbab9e9",
"sha256:5712728e6ba56d3b93f5f99a175760c778420caae714687592548c4f7699782e",
"sha256:66df3233e5cca3528be2a700f2a54e26262dde6d5e22b34953e7f44785857c8c",
"sha256:750a15f07178d91204ce4baffb16697cef4c8f583495d4f0fec52902dad8e7fc",
"sha256:820ec13201ed5c015dc74ea7087b2c5c56b8aeb51af4b7d7c859e0b45c07f035",
"sha256:8dcab8a09c17a030d046749eb97ed9a81e02bb642d7816e8757fc5a3016af89d",
"sha256:9e1acd628f2bf601fd4df69523476ee4640be8ba7d9aff8f04cd66a1ae07f119",
"sha256:b31bc078c9bac3dbb5855e94eb382aeef23076bf3d1a2d02ee8d91c55567cb08",
"sha256:b7a681e2d6dbd147ec9808cb1a736c1ef96bc2c693f54e0fc01fe0d10409bd88",
"sha256:c1333e8911c29c6e209db117345141d5fcb772464d62cac3e117912a965d9619",
"sha256:d583e7b9646418dff5ee0e36875b3cabc3d0fb925dfdeec239697c583388f9b2",
"sha256:da610ff9feeb075641128ce40881d2ac3c8e57e7ea04636169b0c3b5e8f711f7",
"sha256:e9b6ebb62806817b01e9eea9fc7da57c12557e44e94e79f5fa82eca4bc7fad60",
"sha256:f36035f1c0b6a7a20010e98b582d38272514a77f34cd45ec0d2847abaa89ac78"
],
"markers": "platform_python_implementation == 'CPython' and python_version < '3.8'",
"version": "==0.1.0"
"sha256:0bbe19d3e099f8ba384e1846e6b54f245f58aeec8700edbbf9abb87afa54fd82",
"sha256:2f38024592613f3a8772bbc2904be027d9abf463518ba145f2d0c8e6da27009f",
"sha256:44449b3764a3f75815eea8ae5930b98e8326be64a90b0f782747318f861abfe0",
"sha256:5710be9a357801c31c1eaa37b9bc92d38176d785af5b2f0c9751385c5dc9659a",
"sha256:5a089acb6833ed5f412e24cbe3e665683064c1429824d2819137b5ade54435c3",
"sha256:6143386ddd61599ea081c012a69a16e5bdd7b3c6c231bd039534365a48940f30",
"sha256:6726aaf851f5f9e4cbdd3e1e414bc700bdd39220e8bc386415fd41c87b1b53c2",
"sha256:68fbc3b5d94d145a391452f886ae5fca240cb7e3ab6bd66e1a721507cdaac28a",
"sha256:75ebddf99ba9e0b48f32b5bdcf9e5a2b84c017da9e0db7bf11995fa414aa09cd",
"sha256:79948a6712baa686773a43906728e20932c923f7b2a91be7347993be2d745e55",
"sha256:8a2dd8e8b08d369558cade05731172c4b5e2f4c5097762c6b352bd28fd9f9dc4",
"sha256:c747acdb5e8c242ab2280df6f0c239e62838af4bee647031d96b3db2f9cefc04",
"sha256:cadc8eecd27414dca30366b2535cb5e3f3b47b4e2d6be7a0b13e4e52e459ff9f",
"sha256:cee86ecc893a6a8ecaa7c6a9c2d06f75f614176210d78a5f155f8e78d6989509",
"sha256:e59af39e895aff28ee5f55515983cab3466d1a029c91c04db29da1c0f09cf333",
"sha256:eee7ecd2eee648884fae6c51ae50c814acdcc5d6340dc96c970158aebcd25ac6",
"sha256:ef8d4522d231cb9b29f6cdd0edc8faac9d9715c60dc7becbd6eb82c915a98e5b",
"sha256:f504d45230cc9abf2810623b924ae048b224a90adb01f97db4e766cfdda8e6eb"
],
"version": "==0.1.2"
},
"six": {
"hashes": [
......@@ -458,6 +455,21 @@
"index": "pypi",
"version": "==0.3"
},
"factory-boy": {
"hashes": [
"sha256:728df59b372c9588b83153facf26d3d28947fc750e8e3c95cefa9bed0e6394ee",
"sha256:faf48d608a1735f0d0a3c9cbf536d64f9132b547dae7ba452c4d99a79e84a370"
],
"index": "pypi",
"version": "==2.12.0"
},
"faker": {
"hashes": [
"sha256:96ad7902706f2409a2d0c3de5132f69b413555a419bacec99d3f16e657895b47",
"sha256:b3bb64aff9571510de6812df45122b633dbc6227e870edae3ed9430f94698521"
],
"version": "==2.0.0"
},
"flake8": {
"hashes": [
"sha256:19241c1cbc971b9962473e4438a2ca19749a7dd002dd1a946eaba171b4114548",
......@@ -474,12 +486,18 @@
"index": "pypi",
"version": "==0.19"
},
"inflection": {
"hashes": [
"sha256:18ea7fb7a7d152853386523def08736aa8c32636b047ade55f7578c4edeb16ca"
],
"version": "==0.3.1"
},
"ipykernel": {
"hashes": [
"sha256:346189536b88859937b5f4848a6fd85d1ad0729f01724a411de5cae9b618819c",
"sha256:f0e962052718068ad3b1d8bcc703794660858f58803c3798628817f492a8769c"
"sha256:167c3ef08450f5e060b76c749905acb0e0fbef9365899377a4a1eae728864383",
"sha256:b503913e0b4cce7ed2de965457dfb2edd633e8234161a60e23f2fe2161345d12"
],
"version": "==5.1.1"
"version": "==5.1.2"
},
"ipython": {
"hashes": [
......@@ -799,6 +817,13 @@
"index": "pypi",
"version": "==3.5.1"
},
"pytest-factoryboy": {
"hashes": [
"sha256:ffef3fb7ddec1299d3df0d334846259023f3d1da5ab887ad880139a8253a5a1a"
],
"index": "pypi",
"version": "==2.0.3"
},
"python-dateutil": {
"hashes": [
"sha256:7e6584c74aeed623791615e26efd690f29817a27c73085b78e4bad02493df2fb",
......@@ -809,33 +834,33 @@
},
"pyzmq": {
"hashes": [
"sha256:00dd015159eaeb1c0731ad49310e1f5d839c9a35a15e4f3267f5052233fad99b",
"sha256:03913b6beb8e7b417b9910b0ee1fd5d62e9626d218faefbe879d70714ceab1a2",
"sha256:13f17386df81d5e6efb9a4faea341d8de22cdc82e49a326dded26e33f42a3112",
"sha256:16c6281d96885db1e15f7047ddc1a8f48ff4ea35d31ca709f4d2eb39f246d356",
"sha256:17efab4a804e31f58361631256d660214204046f9e2b962738b171b9ad674ea7",
"sha256:2b79919ddeff3d3c96aa6087c21d294c8db1c01f6bfeee73324944683685f419",
"sha256:2f832e4711657bb8d16ea1feba860f676ec5f14fb9fe3b449b5953a60e89edae",
"sha256:31a11d37ac73107363b47e14c94547dbfc6a550029c3fe0530be443199026fc2",
"sha256:33a3e928e6c3138c675e1d6702dd11f6b7050177d7aab3fc322db6e1d2274490",
"sha256:34a38195a6d3a9646cbcdaf8eb245b4d935c7a57f7e1b3af467814bc1a92467e",
"sha256:42900054f1500acef6df7428edf806abbf641bf92eb9ceded24aa863397c3bae",
"sha256:4ccc7f3c63aa9d744dadb62c49eda2d0e7de55649b80c45d7c684d70161a69af",
"sha256:5b220c37c346e6575db8c88a940c1fc234f99ce8e0068c408919bb8896c4b6d2",
"sha256:6074848da5c8b44a1ca40adf75cf65aa92bc80f635e8249aa8f37a69b2b9b6f5",
"sha256:61a4155964bd4a14ef95bf46cb1651bcf8dcbbed8c0108e9c974c1fcbb57788f",
"sha256:62b5774688326600c52f587f7a033ca6b6284bef4c8b1b5fda32480897759eac",
"sha256:65a9ffa4f9f085d696f16fd7541f34b3c357d25fe99c90e3bce2ea59c3b5b4b6",
"sha256:76a077d2c30f8adc5e919a55985a784b96aeca69b53c1ea6fd5723d3ae2e6f53",
"sha256:8e5b4c51557071d6379d6dc1f54f35e9f6a137f5e84e102efb869c8d3c13c8ff",
"sha256:917f73e07cc04f0678a96d93e7bb8b1adcccdde9ccfe202e622814f4d1d1ecfd",
"sha256:91c75d3c4c357f9643e739db9e79ab9681b2f6ae8ec5678d6ef2ea0d01532596",
"sha256:923dd91618b100bb4c92ab9ed7b65825a595b8524a094ce03c7cb2aaae7d353b",
"sha256:9849054e0355e2bc7f4668766a25517ba76095031c9ff5e39ae8949cee5bb024",
"sha256:c9d453933f0e3f44b9759189f2a18aa765f7f1a4345c727c18ebe8ad0d748d26",
"sha256:cb7514936277abce64c2f4c56883e5704d85ed04d98d2d432d1c6764003bb003"
],
"version": "==18.0.2"
"sha256:01636e95a88d60118479041c6aaaaf5419c6485b7b1d37c9c4dd424b7b9f1121",
"sha256:021dba0d1436516092c624359e5da51472b11ba8edffa334218912f7e8b65467",
"sha256:0463bd941b6aead494d4035f7eebd70035293dd6caf8425993e85ad41de13fa3",
"sha256:05fd51edd81eed798fccafdd49c936b6c166ffae7b32482e4d6d6a2e196af4e6",
"sha256:1fadc8fbdf3d22753c36d4172169d184ee6654f8d6539e7af25029643363c490",
"sha256:22efa0596cf245a78a99060fe5682c4cd00c58bb7614271129215c889062db80",
"sha256:260c70b7c018905ec3659d0f04db735ac830fe27236e43b9dc0532cf7c9873ef",
"sha256:2762c45e289732d4450406cedca35a9d4d71e449131ba2f491e0bf473e3d2ff2",
"sha256:2fc6cada8dc53521c1189596f1898d45c5f68603194d3a6453d6db4b27f4e12e",
"sha256:343b9710a61f2b167673bea1974e70b5dccfe64b5ed10626798f08c1f7227e72",
"sha256:41bf96d5f554598a0632c3ec28e3026f1d6591a50f580df38eff0b8067efb9e7",
"sha256:856b2cdf7a1e2cbb84928e1e8db0ea4018709b39804103d3a409e5584f553f57",
"sha256:85b869abc894672de9aecdf032158ea8ad01e2f0c3b09ef60e3687fb79418096",
"sha256:93f44739db69234c013a16990e43db1aa0af3cf5a4b8b377d028ff24515fbeb3",
"sha256:98fa3e75ccb22c0dc99654e3dd9ff693b956861459e8c8e8734dd6247b89eb29",
"sha256:9a22c94d2e93af8bebd4fcf5fa38830f5e3b1ff0d4424e2912b07651eb1bafb4",
"sha256:a7d3f4b4bbb5d7866ae727763268b5c15797cbd7b63ea17f3b0ec1067da8994b",
"sha256:b645a49376547b3816433a7e2d2a99135c8e651e50497e7ecac3bd126e4bea16",
"sha256:cf0765822e78cf9e45451647a346d443f66792aba906bc340f4e0ac7870c169c",
"sha256:dc398e1e047efb18bfab7a8989346c6921a847feae2cad69fedf6ca12fb99e2c",
"sha256:dd5995ae2e80044e33b5077fb4bc2b0c1788ac6feaf15a6b87a00c14b4bdd682",
"sha256:e03fe5e07e70f245dc9013a9d48ae8cc4b10c33a1968039c5a3b64b5d01d083d",
"sha256:ea09a306144dff2795e48439883349819bef2c53c0ee62a3c2fae429451843bb",
"sha256:f4e37f33da282c3c319849877e34f97f0a3acec09622ec61b7333205bdd13b52",
"sha256:fa4bad0d1d173dee3e8ef3c3eb6b2bb6c723fc7a661eeecc1ecb2fa99860dd45"
],
"version": "==18.1.0"
},
"qtconsole": {
"hashes": [
......@@ -873,6 +898,13 @@
],
"version": "==0.4.2"
},
"text-unidecode": {
"hashes": [
"sha256:5a1375bb2ba7968740508ae38d92e1f889a0832913cb1c447d5e2046061a396d",
"sha256:801e38bd550b943563660a91de8d4b6fa5df60a542be9093f7abf819f86050cc"
],
"version": "==1.2"
},
"tornado": {
"hashes": [
"sha256:349884248c36801afa19e342a77cc4458caca694b0eda633f5878e458a44cb2c",
......
from .taxonomy import TaxonomyFactory # noqa
from factory import fuzzy
from factory import DjangoModelFactory, lazy_attribute
from faker import Factory
from metagenedb.apps.catalog import models
faker = Factory.create()
SELECTED_RANK = [i[0] for i in models.Taxonomy.RANK_CHOICES]
class TaxonomyFactory(DjangoModelFactory):
class Meta:
model = models.Taxonomy
rank = fuzzy.FuzzyChoice(SELECTED_RANK)
@lazy_attribute
def tax_id(self):
return faker.pyint()
from unittest import TestCase
import pytest
from rest_framework.exceptions import ValidationError
from rest_framework.test import APITestCase
from metagenedb.apps.catalog.models import Gene
from metagenedb.apps.catalog.factory.taxonomy import TaxonomyFactory
from scripts.populate_db.import_igc_data import parse_gene, upsert_gene, select_taxonomy
......@@ -100,23 +102,67 @@ class TestUpsertGene(APITestCase):
self.assertEqual(Gene.objects.get(gene_id="test_gene01").length, 356)
@pytest.mark.django_db
class TestSelectTaxonomy(TestCase):
def setUp(self):
self.genus_name = 'Genus'
self.phylum_name = 'Phylum'
self.unknown_name = 'unknown'
self.genus = TaxonomyFactory(rank="genus", name=self.genus_name)
self.phylum = TaxonomyFactory(rank="phylum", name=self.phylum_name)
def test_genus_only(self):
pass # @TODO with #31
gene_dict = {
'gene_id': 'gene',
'length': 135,
'taxo_phylum': self.unknown_name,
'taxo_genus': self.genus_name
}
expected_dict = {
'gene_id': 'gene',
'length': 135,
'taxonomy': str(self.genus.tax_id)
}
tested_dict = select_taxonomy(gene_dict)
self.assertDictEqual(tested_dict, expected_dict)
def test_phylum_only(self):
pass # @TODO with #31
gene_dict = {
'gene_id': 'gene',
'length': 135,
'taxo_phylum': self.phylum_name,
'taxo_genus': self.unknown_name
}
expected_dict = {
'gene_id': 'gene',
'length': 135,
'taxonomy': str(self.phylum.tax_id)
}
tested_dict = select_taxonomy(gene_dict)
self.assertDictEqual(tested_dict, expected_dict)
def test_genus_phylum(self):
pass # @TODO with #31
gene_dict = {
'gene_id': 'gene',
'length': 135,
'taxo_phylum': self.phylum_name,
'taxo_genus': self.genus_name
}
expected_dict = {
'gene_id': 'gene',
'length': 135,
'taxonomy': str(self.genus.tax_id)
}
tested_dict = select_taxonomy(gene_dict)
self.assertDictEqual(tested_dict, expected_dict)
def test_both_unknown(self):
gene_dict = {
'gene_id': 'gene',
'length': 135,
'taxo_phylum': 'unknown',
'taxo_genus': 'unknown'
'taxo_phylum': self.unknown_name,
'taxo_genus': self.unknown_name
}
expected_dict = {
'gene_id': 'gene',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment