From 6486bc57651f074245ae0bf786f9e92460d73fef Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Wed, 26 Aug 2020 17:31:17 +0300
Subject: Fix failing tests that use python2-htmlgen
* wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py: Fix
tests.
---
.../test_display_mapping_results.py | 91 ++++++++++++----------
1 file changed, 48 insertions(+), 43 deletions(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py b/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py
index 6f791df1..8ae0f09f 100644
--- a/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py
+++ b/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py
@@ -1,6 +1,6 @@
import unittest
-from htmlgen import HTMLgen2 as HT
+import htmlgen as HT
from wqflask.marker_regression.display_mapping_results import (
DisplayMappingResults,
HtmlGenWrapper
@@ -26,9 +26,9 @@ class TestHtmlGenWrapper(unittest.TestCase):
width="10",
height="13",
usemap="#webqtlmap")),
- ("""""")
+ ("""""")
)
def test_create_form(self):
@@ -37,7 +37,7 @@ class TestHtmlGenWrapper(unittest.TestCase):
cgi="/testing/",
enctype='multipart/form-data',
name="formName",
- submit=HT.Input(type='hidden')
+ submit=HtmlGenWrapper.create_input_tag(type_='hidden', name='Default_Name')
)
test_image = HtmlGenWrapper.create_image_tag(
src="test.png",
@@ -49,10 +49,10 @@ class TestHtmlGenWrapper(unittest.TestCase):
)
self.assertEqual(
str(test_form).replace("\n", ""),
- ("""
"""))
+ (""""""))
hddn = {
'FormID': 'showDatabase',
'ProbeSetID': '_',
@@ -62,21 +62,26 @@ class TestHtmlGenWrapper(unittest.TestCase):
'incparentsf1': 'ON'
}
for key in hddn.keys():
- test_form.append(HT.Input(name=key, value=hddn[key],
- type='hidden'))
+ test_form.append(
+ HtmlGenWrapper.create_input_tag(
+ name=key,
+ value=hddn[key],
+ type_='hidden'))
test_form.append(test_image)
+
self.assertEqual(str(test_form).replace("\n", ""), (
- """"""))
+ """"""))
def test_create_paragraph(self):
"""Test HT.Paragraph method"""
@@ -89,48 +94,48 @@ class TestHtmlGenWrapper(unittest.TestCase):
)
self.assertEqual(
str(test_p_element),
- """"""
+ """"""
)
- test_p_element.append(HT.BR())
+ test_p_element.append(HtmlGenWrapper.create_br_tag())
test_p_element.append(par_text)
self.assertEqual(
str(test_p_element),
- """
{}
""".format(par_text)
+ """
{}
""".format(par_text)
)
def test_create_br_tag(self):
"""Test HT.BR() method"""
self.assertEqual(str(HtmlGenWrapper.create_br_tag()),
- "
")
+ "
")
def test_create_input_tag(self):
"""Test HT.Input method"""
self.assertEqual(
str(HtmlGenWrapper.create_input_tag(
- type="hidden",
+ type_="hidden",
name="name",
value="key",
Class="trait trait_")).replace("\n", ""),
- (""""""))
+ (""""""))
def test_create_map_tag(self):
"""Test HT.Map method"""
self.assertEqual(str(HtmlGenWrapper.create_map_tag(
name="WebqTLImageMap")).replace("\n", ""),
- """""")
- gifmap = HtmlGenWrapper.create_map_tag(areas=[])
- gifmap.areas.append(HT.Area(shape="rect",
- coords='1 2 3', href='#area1'))
- gifmap.areas.append(HT.Area(shape="rect",
- coords='1 2 3', href='#area2'))
+ """""")
+ gifmap = HtmlGenWrapper.create_map_tag(name="test")
+ gifmap.append(HtmlGenWrapper.create_area_tag(shape="rect",
+ coords='1 2 3', href='#area1'))
+ gifmap.append(HtmlGenWrapper.create_area_tag(shape="rect",
+ coords='1 2 3', href='#area2'))
self.assertEqual(
str(gifmap).replace("\n", ""),
- (""""""))
+ (""""""))
def test_create_area_tag(self):
"""Test HT.Area method"""
@@ -140,12 +145,12 @@ class TestHtmlGenWrapper(unittest.TestCase):
coords="1 2",
href="http://test.com",
title="Some Title")).replace("\n", ""),
- (""""""))
+ (""""""))
def test_create_link_tag(self):
"""Test HT.HREF method"""
self.assertEqual(
str(HtmlGenWrapper.create_link_tag(
"www.test.com", "test", target="_blank")).replace("\n", ""),
- """test""")
+ """test""")
--
cgit v1.2.3
From 869da13b92e70fa0769cd1a49e15b03e2c9d0550 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Thu, 27 Aug 2020 01:31:33 +0300
Subject: Fix failing tests
---
wqflask/tests/base/test_data_set.py | 71 +++++++++++++++++++++++-------
wqflask/tests/base/test_general_object.py | 9 ++--
wqflask/tests/wqflask/api/test_gen_menu.py | 6 +++
3 files changed, 66 insertions(+), 20 deletions(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/base/test_data_set.py b/wqflask/tests/base/test_data_set.py
index 94780a5d..e6000e56 100644
--- a/wqflask/tests/base/test_data_set.py
+++ b/wqflask/tests/base/test_data_set.py
@@ -4,7 +4,7 @@ import unittest
import mock
from wqflask import app
-from data import gen_menu_json
+from .data import gen_menu_json
from base.data_set import DatasetType
@@ -59,9 +59,14 @@ class TestDataSetTypes(unittest.TestCase):
self.assertEqual(data_set("BXDGeno"), "Geno")
self.assertEqual(data_set("BXDPublish"), "Publish")
self.assertEqual(data_set("HLC_0311"), "ProbeSet")
+
redis_mock.set.assert_called_once_with(
"dataset_structure",
- '{"BXDGeno": "Geno", "BXDPublish": "Publish", "HLCPublish": "Publish", "HLC_0311": "ProbeSet", "HC_M2_0606_P": "ProbeSet"}')
+ ('{"HLC_0311": "ProbeSet", '
+ '"HLCPublish": "Publish", '
+ '"BXDGeno": "Geno", '
+ '"HC_M2_0606_P": "ProbeSet", '
+ '"BXDPublish": "Publish"}'))
@mock.patch('base.data_set.g')
def test_set_dataset_key_mrna(self, db_mock):
@@ -74,8 +79,17 @@ class TestDataSetTypes(unittest.TestCase):
self.assertEqual(data_set("Test"), "ProbeSet")
redis_mock.set.assert_called_once_with(
"dataset_structure",
- '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "ProbeSet", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}')
- expected_db_call = """"""
+ ('{"AD-cases-controls-MyersGeno": "Geno", '
+ '"AD-cases-controls-MyersPublish": "Publish", '
+ '"AKXDGeno": "Geno", '
+ '"AXBXAGeno": "Geno", '
+ '"AXBXAPublish": "Publish", '
+ '"Aging-Brain-UCIPublish": "Publish", '
+ '"All Phenotypes": "Publish", '
+ '"B139_K_1206_M": "ProbeSet", '
+ '"B139_K_1206_R": "ProbeSet", '
+ '"Test": "ProbeSet"}'))
+
db_mock.db.execute.assert_called_with(
("SELECT ProbeSetFreeze.Id FROM ProbeSetFreeze " +
"WHERE ProbeSetFreeze.Name = \"Test\" ")
@@ -92,13 +106,21 @@ class TestDataSetTypes(unittest.TestCase):
self.assertEqual(data_set("Test"), "Publish")
redis_mock.set.assert_called_once_with(
"dataset_structure",
- '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Publish", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}')
- expected_db_call = """"""
+ ('{"AD-cases-controls-MyersGeno": "Geno", '
+ '"AD-cases-controls-MyersPublish": "Publish", '
+ '"AKXDGeno": "Geno", '
+ '"AXBXAGeno": "Geno", '
+ '"AXBXAPublish": "Publish", '
+ '"Aging-Brain-UCIPublish": "Publish", '
+ '"All Phenotypes": "Publish", '
+ '"B139_K_1206_M": "ProbeSet", '
+ '"B139_K_1206_R": "ProbeSet", '
+ '"Test": "Publish"}'))
db_mock.db.execute.assert_called_with(
- ("SELECT InfoFiles.GN_AccesionId " +
- "FROM InfoFiles, PublishFreeze, InbredSet " +
+ ("SELECT InfoFiles.GN_AccesionId "
+ "FROM InfoFiles, PublishFreeze, InbredSet "
"WHERE InbredSet.Name = 'Test' AND "
- "PublishFreeze.InbredSetId = InbredSet.Id AND " +
+ "PublishFreeze.InbredSetId = InbredSet.Id AND "
"InfoFiles.InfoPageName = PublishFreeze.Name")
)
@@ -111,10 +133,20 @@ class TestDataSetTypes(unittest.TestCase):
data_set = DatasetType(redis_mock)
data_set.set_dataset_key("other_pheno", "Test")
self.assertEqual(data_set("Test"), "Publish")
+
redis_mock.set.assert_called_once_with(
"dataset_structure",
- '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Publish", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}')
- expected_db_call = """"""
+ ('{"AD-cases-controls-MyersGeno": "Geno", '
+ '"AD-cases-controls-MyersPublish": "Publish", '
+ '"AKXDGeno": "Geno", '
+ '"AXBXAGeno": "Geno", '
+ '"AXBXAPublish": "Publish", '
+ '"Aging-Brain-UCIPublish": "Publish", '
+ '"All Phenotypes": "Publish", '
+ '"B139_K_1206_M": "ProbeSet", '
+ '"B139_K_1206_R": "ProbeSet", '
+ '"Test": "Publish"}'))
+
db_mock.db.execute.assert_called_with(
("SELECT PublishFreeze.Name " +
"FROM PublishFreeze, InbredSet " +
@@ -133,8 +165,17 @@ class TestDataSetTypes(unittest.TestCase):
self.assertEqual(data_set("Test"), "Geno")
redis_mock.set.assert_called_once_with(
"dataset_structure",
- '{"Aging-Brain-UCIPublish": "Publish", "AKXDGeno": "Geno", "B139_K_1206_M": "ProbeSet", "AD-cases-controls-MyersGeno": "Geno", "AD-cases-controls-MyersPublish": "Publish", "All Phenotypes": "Publish", "Test": "Geno", "AXBXAPublish": "Publish", "B139_K_1206_R": "ProbeSet", "AXBXAGeno": "Geno"}')
- expected_db_call = """"""
+ ('{"AD-cases-controls-MyersGeno": "Geno", '
+ '"AD-cases-controls-MyersPublish": "Publish", '
+ '"AKXDGeno": "Geno", '
+ '"AXBXAGeno": "Geno", '
+ '"AXBXAPublish": "Publish", '
+ '"Aging-Brain-UCIPublish": "Publish", '
+ '"All Phenotypes": "Publish", '
+ '"B139_K_1206_M": "ProbeSet", '
+ '"B139_K_1206_R": "ProbeSet", '
+ '"Test": "Geno"}'))
+
db_mock.db.execute.assert_called_with(
- ("SELECT GenoFreeze.Id FROM GenoFreeze WHERE GenoFreeze.Name = \"Test\" ")
- )
+ ("SELECT GenoFreeze.Id FROM "
+ "GenoFreeze WHERE GenoFreeze.Name = \"Test\" "))
diff --git a/wqflask/tests/base/test_general_object.py b/wqflask/tests/base/test_general_object.py
index c7701021..00fd3c72 100644
--- a/wqflask/tests/base/test_general_object.py
+++ b/wqflask/tests/base/test_general_object.py
@@ -17,9 +17,9 @@ class TestGeneralObjectTests(unittest.TestCase):
def test_object_dict(self):
"""Test whether the base class is printed properly"""
test_obj = GeneralObject("a", name="test", value=1)
- self.assertEqual(str(test_obj), "value = 1\nname = test\n")
+ self.assertEqual(str(test_obj), "name = test\nvalue = 1\n")
self.assertEqual(
- repr(test_obj), "value = 1\nname = test\ncontents = ['a']\n")
+ repr(test_obj), "contents = ['a']\nname = test\nvalue = 1\n")
self.assertEqual(len(test_obj), 2)
self.assertEqual(test_obj["value"], 1)
test_obj["test"] = 1
@@ -36,6 +36,5 @@ class TestGeneralObjectTests(unittest.TestCase):
test_obj1 = GeneralObject("a", name="test", value=1)
test_obj2 = GeneralObject("b", name="test2", value=2)
test_obj3 = GeneralObject("a", name="test", x=1, y=2)
- self.assertTrue(test_obj1 == test_obj2 )
- self.assertFalse(test_obj1 == test_obj3 )
-
+ self.assertTrue(test_obj1 == test_obj2)
+ self.assertFalse(test_obj1 == test_obj3)
diff --git a/wqflask/tests/wqflask/api/test_gen_menu.py b/wqflask/tests/wqflask/api/test_gen_menu.py
index 239484aa..bf41054d 100644
--- a/wqflask/tests/wqflask/api/test_gen_menu.py
+++ b/wqflask/tests/wqflask/api/test_gen_menu.py
@@ -2,6 +2,7 @@
import unittest
import mock
+from wqflask import app
from wqflask.api.gen_menu import gen_dropdown_json
from wqflask.api.gen_menu import get_species
from wqflask.api.gen_menu import get_groups
@@ -17,6 +18,8 @@ class TestGenMenu(unittest.TestCase):
"""Tests for the gen_menu module"""
def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
self.test_group = {
'mouse': [
['H_T1',
@@ -67,6 +70,9 @@ class TestGenMenu(unittest.TestCase):
}
}
+ def tearDown(self):
+ self.app_context.pop()
+
@mock.patch('wqflask.api.gen_menu.g')
def test_get_species(self, db_mock):
"""Test that assertion is raised when dataset and dataset_name
--
cgit v1.2.3
From 16faa26e52b1f0191595e16550d553907d2f9d67 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Thu, 17 Sep 2020 17:21:30 +0300
Subject: Fix errors in tests
* wqflask/tests/utility/test_authentication_tools.py
test_check_resource_availability_non_default_mask): Mock flask's
global 'g' variable properly.
* wqflask/tests/base/test_trait.py: Ditto.
* wqflask/tests/utility/test_authentication_tools.py: Ditto.
---
wqflask/tests/base/test_trait.py | 9 +++------
wqflask/tests/utility/test_authentication_tools.py | 8 ++------
2 files changed, 5 insertions(+), 12 deletions(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py
index 53b0d440..d333458a 100644
--- a/wqflask/tests/base/test_trait.py
+++ b/wqflask/tests/base/test_trait.py
@@ -38,9 +38,8 @@ class TestRetrieveTraitInfo(unittest.TestCase):
dataset={})
@mock.patch('base.trait.requests.get')
- @mock.patch('base.trait.g')
+ @mock.patch('base.trait.g', mock.Mock())
def test_retrieve_trait_info_with_empty_trait_info(self,
- g_mock,
requests_mock):
"""Empty trait info"""
requests_mock.return_value = TestNilResponse()
@@ -49,9 +48,8 @@ class TestRetrieveTraitInfo(unittest.TestCase):
dataset=mock.MagicMock())
@mock.patch('base.trait.requests.get')
- @mock.patch('base.trait.g')
+ @mock.patch('base.trait.g', mock.Mock())
def test_retrieve_trait_info_with_non_empty_trait_info(self,
- g_mock,
requests_mock):
"""Test that attributes are set"""
mock_dataset = mock.MagicMock()
@@ -66,9 +64,8 @@ class TestRetrieveTraitInfo(unittest.TestCase):
self.assertEqual(test_trait.d, 4)
@mock.patch('base.trait.requests.get')
- @mock.patch('base.trait.g')
+ @mock.patch('base.trait.g', mock.Mock())
def test_retrieve_trait_info_utf8_parsing(self,
- g_mock,
requests_mock):
"""Test that utf-8 strings are parsed correctly"""
utf_8_string = "test_string"
diff --git a/wqflask/tests/utility/test_authentication_tools.py b/wqflask/tests/utility/test_authentication_tools.py
index 99c74245..ef94eabc 100644
--- a/wqflask/tests/utility/test_authentication_tools.py
+++ b/wqflask/tests/utility/test_authentication_tools.py
@@ -38,17 +38,15 @@ class TestCheckResourceAvailability(unittest.TestCase):
"""Test methods related to checking the resource availability"""
@mock.patch('utility.authentication_tools.add_new_resource')
@mock.patch('utility.authentication_tools.Redis')
- @mock.patch('utility.authentication_tools.g')
+ @mock.patch('utility.authentication_tools.g', mock.Mock())
@mock.patch('utility.authentication_tools.get_resource_id')
def test_check_resource_availability_default_mask(
self,
resource_id_mock,
- g_mock,
redis_mock,
add_new_resource_mock):
"""Test the resource availability with default mask"""
resource_id_mock.return_value = 1
- g_mock.return_value = mock.Mock()
redis_mock.smembers.return_value = []
test_dataset = mock.MagicMock()
type(test_dataset).type = mock.PropertyMock(return_value="Test")
@@ -58,18 +56,16 @@ class TestCheckResourceAvailability(unittest.TestCase):
@mock.patch('utility.authentication_tools.requests.get')
@mock.patch('utility.authentication_tools.add_new_resource')
@mock.patch('utility.authentication_tools.Redis')
- @mock.patch('utility.authentication_tools.g')
+ @mock.patch('utility.authentication_tools.g', TestUserSession())
@mock.patch('utility.authentication_tools.get_resource_id')
def test_check_resource_availability_non_default_mask(
self,
resource_id_mock,
- g_mock,
redis_mock,
add_new_resource_mock,
requests_mock):
"""Test the resource availability with default mask"""
resource_id_mock.return_value = 1
- g_mock.return_value = mock.Mock()
redis_mock.smembers.return_value = []
add_new_resource_mock.return_value = {"default_mask": 2}
requests_mock.return_value = TestResponse()
--
cgit v1.2.3
From f67b0c92af93e3153fe9375e98a139386a4f2fb0 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Sat, 26 Sep 2020 01:21:10 +0300
Subject: Fix failing tests
* wqflask/tests/base/test_trait.py: Remove decode function call which
is no longer supported in python3.
---
wqflask/tests/base/test_trait.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py
index 9c3154f3..d333458a 100644
--- a/wqflask/tests/base/test_trait.py
+++ b/wqflask/tests/base/test_trait.py
@@ -93,6 +93,6 @@ class TestRetrieveTraitInfo(unittest.TestCase):
test_trait = retrieve_trait_info(trait=mock_trait,
dataset=mock_dataset)
self.assertEqual(test_trait.abbreviation,
- "ファイルを画面毎に見て行くには、次のコマンドを使います。".decode('utf-8'))
+ "ファイルを画面毎に見て行くには、次のコマンドを使います。")
self.assertEqual(test_trait.authors,
- "Jane Doe かいと".decode('utf-8'))
+ "Jane Doe かいと")
--
cgit v1.2.3
From bbcecf8e7d8389b8466fe51dde6538387fdce6b5 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Sat, 26 Sep 2020 01:33:52 +0300
Subject: Fix failing tests by replacing mock with unittest.mock
* wqflask/tests/base/test_data_set.py (imports): Run:
`find . -type f -name "*py" -print0 | xargs -0 sed -i \
"s|import mock|from unittest import mock|g"`
* wqflask/tests/base/test_trait.py(imports): Ditto.
* wqflask/tests/utility/test_authentication_tools.py(imports): Ditto.
* wqflask/tests/utility/test_hmac.py(imports). Ditto.
* wqflask/tests/wqflask/api/test_gen_menu.py: Ditto
---
wqflask/tests/base/test_data_set.py | 2 +-
wqflask/tests/base/test_trait.py | 2 +-
wqflask/tests/utility/test_authentication_tools.py | 2 +-
wqflask/tests/utility/test_hmac.py | 2 +-
wqflask/tests/wqflask/api/test_gen_menu.py | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/base/test_data_set.py b/wqflask/tests/base/test_data_set.py
index b1de4932..96563a16 100644
--- a/wqflask/tests/base/test_data_set.py
+++ b/wqflask/tests/base/test_data_set.py
@@ -1,7 +1,7 @@
"""Tests for wqflask/base/data_set.py"""
import unittest
-import mock
+from unittest import mock
from wqflask import app
from .data import gen_menu_json
diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py
index d333458a..bf4e88e0 100644
--- a/wqflask/tests/base/test_trait.py
+++ b/wqflask/tests/base/test_trait.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests wqflask/base/trait.py"""
import unittest
-import mock
+from unittest import mock
from base.trait import GeneralTrait
from base.trait import retrieve_trait_info
diff --git a/wqflask/tests/utility/test_authentication_tools.py b/wqflask/tests/utility/test_authentication_tools.py
index ef94eabc..5c391be5 100644
--- a/wqflask/tests/utility/test_authentication_tools.py
+++ b/wqflask/tests/utility/test_authentication_tools.py
@@ -1,6 +1,6 @@
"""Tests for authentication tools"""
import unittest
-import mock
+from unittest import mock
from utility.authentication_tools import check_resource_availability
from utility.authentication_tools import add_new_resource
diff --git a/wqflask/tests/utility/test_hmac.py b/wqflask/tests/utility/test_hmac.py
index 16b50771..7c61c0a6 100644
--- a/wqflask/tests/utility/test_hmac.py
+++ b/wqflask/tests/utility/test_hmac.py
@@ -2,7 +2,7 @@
"""Test hmac utility functions"""
import unittest
-import mock
+from unittest import mock
from utility.hmac import data_hmac
from utility.hmac import url_for_hmac
diff --git a/wqflask/tests/wqflask/api/test_gen_menu.py b/wqflask/tests/wqflask/api/test_gen_menu.py
index bf41054d..84898bd1 100644
--- a/wqflask/tests/wqflask/api/test_gen_menu.py
+++ b/wqflask/tests/wqflask/api/test_gen_menu.py
@@ -1,6 +1,6 @@
"""Test cases for wqflask.api.gen_menu"""
import unittest
-import mock
+from unittest import mock
from wqflask import app
from wqflask.api.gen_menu import gen_dropdown_json
--
cgit v1.2.3
From 21ec6863d7f8380d66c39f1ed3b8d9cc0dc86e49 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Mon, 28 Sep 2020 18:34:53 +0300
Subject: Fix failing test
* wqflask/tests/base/test_trait.py: Add app_context to test class,
otherwise an error related to working outside the app_context is
generated. Adding the app_context is required when mocking "Flask.g".
---
wqflask/tests/base/test_trait.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py
index 60ebaee0..826ccefd 100644
--- a/wqflask/tests/base/test_trait.py
+++ b/wqflask/tests/base/test_trait.py
@@ -3,6 +3,7 @@
import unittest
from unittest import mock
+from wqflask import app
from base.trait import GeneralTrait
from base.trait import retrieve_trait_info
@@ -31,6 +32,14 @@ class MockTrait(GeneralTrait):
class TestRetrieveTraitInfo(unittest.TestCase):
"""Tests for 'retrieve_trait_info'"""
+
+ def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
def test_retrieve_trait_info_with_empty_dataset(self):
"""Test that an exception is raised when dataset is empty"""
with self.assertRaises(AssertionError):
@@ -104,7 +113,7 @@ class TestRetrieveTraitInfo(unittest.TestCase):
resource_id_mock,
g_mock,
requests_mock):
- """Test """
+ """Test retrieve trait info when lrs has a value"""
resource_id_mock.return_value = 1
g_mock.db.execute.return_value.fetchone = mock.Mock()
g_mock.db.execute.return_value.fetchone.side_effect = [
--
cgit v1.2.3
From ce728fa92e02725202bca486e8336b2e1158f4ef Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Tue, 29 Sep 2020 15:57:01 +0300
Subject: Add test for process_traits from collections.py
* wqflask/tests/wqflask/test_collect.py: Add it.
---
wqflask/tests/wqflask/test_collect.py | 73 +++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 wqflask/tests/wqflask/test_collect.py
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/wqflask/test_collect.py b/wqflask/tests/wqflask/test_collect.py
new file mode 100644
index 00000000..06609b4c
--- /dev/null
+++ b/wqflask/tests/wqflask/test_collect.py
@@ -0,0 +1,73 @@
+"""Test cases for some methods in collect.py"""
+
+import unittest
+import mock
+
+from flask import Flask
+from wqflask.collect import process_traits
+
+app = Flask(__name__)
+
+
+class MockSession:
+ """Helper class for mocking wqflask.collect.g.user_session.logged_in"""
+ def __init__(self, is_logged_in=False):
+ self.is_logged_in = is_logged_in
+
+ @property
+ def logged_in(self):
+ return self.is_logged_in
+
+
+class MockFlaskG:
+ """Helper class for mocking wqflask.collect.g.user_session"""
+ def __init__(self, is_logged_in=False):
+ self.is_logged_in = is_logged_in
+
+ @property
+ def user_session(self):
+ if self.is_logged_in:
+ return MockSession(is_logged_in=True)
+ return MockSession()
+
+
+class TestCollect(unittest.TestCase):
+
+ def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
+ @mock.patch("wqflask.collect.g", MockFlaskG())
+ def test_process_traits_with_bytestring(self):
+ """
+ Test that the correct traits are returned when the user is logged
+ out and bytes are used.
+ """
+ self.assertEqual(process_traits(
+ b'1452452_at:HC_M2_0606_P:163d04f7db7c9e110de6,'
+ b'1452447_at:HC_M2_0606_P:eeece8fceb67072debea,'
+ b'1451401_a_at:HC_M2_0606_P:a043d23b3b3906d8318e,'
+ b'1429252_at:HC_M2_0606_P:6fa378b349bc9180e8f5'),
+ set(['1429252_at:HC_M2_0606_P',
+ '1451401_a_at:HC_M2_0606_P',
+ '1452447_at:HC_M2_0606_P',
+ '1452452_at:HC_M2_0606_P']))
+
+ @mock.patch("wqflask.collect.g", MockFlaskG())
+ def test_process_traits_with_normal_string(self):
+ """
+ Test that the correct traits are returned when the user is logged
+ out and a normal string is used.
+ """
+ self.assertEqual(process_traits(
+ '1452452_at:HC_M2_0606_P:163d04f7db7c9e110de6,'
+ '1452447_at:HC_M2_0606_P:eeece8fceb67072debea,'
+ '1451401_a_at:HC_M2_0606_P:a043d23b3b3906d8318e,'
+ '1429252_at:HC_M2_0606_P:6fa378b349bc9180e8f5'),
+ set(['1429252_at:HC_M2_0606_P',
+ '1451401_a_at:HC_M2_0606_P',
+ '1452447_at:HC_M2_0606_P',
+ '1452452_at:HC_M2_0606_P']))
--
cgit v1.2.3
From 475b6e333e6356103592b0983d5efb8e84eb73e7 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Wed, 30 Sep 2020 02:09:27 +0300
Subject: Fix import in tests
---
wqflask/tests/wqflask/test_collect.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/wqflask/test_collect.py b/wqflask/tests/wqflask/test_collect.py
index 06609b4c..9a36132d 100644
--- a/wqflask/tests/wqflask/test_collect.py
+++ b/wqflask/tests/wqflask/test_collect.py
@@ -1,7 +1,7 @@
"""Test cases for some methods in collect.py"""
import unittest
-import mock
+from unittest import mock
from flask import Flask
from wqflask.collect import process_traits
--
cgit v1.2.3
From b2b7bacdbc8dc28dd062ebdb94698fca88f9b0cb Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Tue, 20 Oct 2020 22:19:56 +0300
Subject: Add pbkdf2 tests
* wqflask/tests/wqflask/test_pbkdf2.py: New tests.
---
wqflask/tests/wqflask/test_pbkdf2.py | 61 ++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 wqflask/tests/wqflask/test_pbkdf2.py
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/wqflask/test_pbkdf2.py b/wqflask/tests/wqflask/test_pbkdf2.py
new file mode 100644
index 00000000..a33fbd4f
--- /dev/null
+++ b/wqflask/tests/wqflask/test_pbkdf2.py
@@ -0,0 +1,61 @@
+"""Test cases pbkdf2"""
+
+import unittest
+from wqflask.pbkdf2 import pbkdf2_hex
+
+
+class TestPbkdf2(unittest.TestCase):
+ def test_pbkdf2_hex(self):
+ """
+ Test pbkdf2_hex function
+ """
+
+ for password, salt, iterations, keylen, expected_value in [
+ ('password', 'salt', 1, 20,
+ '0c60c80f961f0e71f3a9b524af6012062fe037a6'),
+ ('password', 'salt', 2, 20,
+ 'ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957'),
+ ('password', 'salt', 4096, 20,
+ '4b007901b765489abead49d926f721d065a429c1'),
+ ('passwordPASSWORDpassword',
+ 'saltSALTsaltSALTsaltSALTsaltSALTsalt',
+ 4096, 25,
+ '3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038'),
+ ('pass\x00word', 'sa\x00lt', 4096, 16,
+ '56fa6aa75548099dcc37d7f03425e0c3'),
+ ('password', 'ATHENA.MIT.EDUraeburn', 1, 16,
+ 'cdedb5281bb2f801565a1122b2563515'),
+ ('password', 'ATHENA.MIT.EDUraeburn', 1, 32,
+ ('cdedb5281bb2f80'
+ '1565a1122b256351'
+ '50ad1f7a04bb9f3a33'
+ '3ecc0e2e1f70837')),
+ ('password', 'ATHENA.MIT.EDUraeburn', 2, 16,
+ '01dbee7f4a9e243e988b62c73cda935d'),
+ ('password', 'ATHENA.MIT.EDUraeburn', 2, 32,
+ ('01dbee7f4a9e243e9'
+ '88b62c73cda935da05'
+ '378b93244ec8f48a99'
+ 'e61ad799d86')),
+ ('password', 'ATHENA.MIT.EDUraeburn', 1200, 32,
+ ('5c08eb61fdf71e'
+ '4e4ec3cf6ba1f55'
+ '12ba7e52ddbc5e51'
+ '42f708a31e2e62b1e13')),
+ ('X' * 64, 'pass phrase equals block size', 1200, 32,
+ ('139c30c0966bc32ba'
+ '55fdbf212530ac9c5'
+ 'ec59f1a452f5cc9ad'
+ '940fea0598ed1')),
+ ('X' * 65, 'pass phrase exceeds block size', 1200, 32,
+ ('9ccad6d468770cd'
+ '51b10e6a68721be6'
+ '11a8b4d282601db3'
+ 'b36be9246915ec82a'))
+ ]:
+ self.assertEqual(
+ pbkdf2_hex(data=password,
+ salt=salt,
+ iterations=iterations,
+ keylen=keylen),
+ expected_value)
--
cgit v1.2.3
From 5d06524c8465064248cc3605c69dd32687ea7565 Mon Sep 17 00:00:00 2001
From: BonfaceKilz
Date: Tue, 20 Oct 2020 22:55:19 +0300
Subject: Add tests for encoding password
* wqflask/tests/wqflask/test_user_login.py: New tests.
---
wqflask/tests/wqflask/test_user_login.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 wqflask/tests/wqflask/test_user_login.py
(limited to 'wqflask/tests')
diff --git a/wqflask/tests/wqflask/test_user_login.py b/wqflask/tests/wqflask/test_user_login.py
new file mode 100644
index 00000000..61cd9ab9
--- /dev/null
+++ b/wqflask/tests/wqflask/test_user_login.py
@@ -0,0 +1,21 @@
+"""Test cases for some methods in login.py"""
+
+import unittest
+from wqflask.user_login import encode_password
+
+
+class TestUserLogin(unittest.TestCase):
+ def test_encode_password(self):
+ """
+ Test encode password
+ """
+ pass_gen_fields = {
+ "salt": "salt",
+ "hashfunc": "sha1",
+ "iterations": 4096,
+ "keylength": 20,
+ }
+ self.assertEqual(
+ encode_password(pass_gen_fields,
+ "password").get("password"),
+ '4b007901b765489abead49d926f721d065a429c1')
--
cgit v1.2.3