-
Notifications
You must be signed in to change notification settings - Fork 51
/
themes_test.py
56 lines (47 loc) · 2.1 KB
/
themes_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Tests for Themes."""
import os
import unittest
import zipfile
import mock
from grow.sdk import themes
from grow.testing import testing
TEST_ZIP_FILE = os.path.abspath(
os.path.join(
os.path.dirname(__file__), '..', 'testing', 'testdata', 'themes', 'base-master.zip'))
class ThemesTestCase(unittest.TestCase):
"""Test the Themes."""
def setUp(self):
self.pod = testing.create_pod()
@mock.patch('grow.sdk.themes.GrowTheme.archive',
new_callable=mock.PropertyMock)
def test_extract(self, mock_archive):
"""Test theme unpacking."""
mock_archive.return_value = zipfile.ZipFile(TEST_ZIP_FILE, 'r')
self.assertFalse(self.pod.file_exists('/podspec.yaml'))
theme = themes.GrowTheme('base')
theme.extract(self.pod)
self.assertTrue(self.pod.file_exists('/podspec.yaml'))
@mock.patch('grow.sdk.themes.GrowTheme.archive',
new_callable=mock.PropertyMock)
def test_extract_existing(self, mock_archive):
"""Test theme unpacking."""
mock_archive.return_value = zipfile.ZipFile(TEST_ZIP_FILE, 'r')
self.assertFalse(self.pod.file_exists('/gulpfile.js'))
self.assertFalse(self.pod.file_exists('/podspec.yaml'))
self.pod.write_file('/podspec.yaml', '')
self.assertTrue(self.pod.file_exists('/podspec.yaml'))
theme = themes.GrowTheme('base')
theme.extract(self.pod)
self.assertFalse(self.pod.file_exists('/gulpfile.js'))
@mock.patch('grow.sdk.themes.GrowTheme.archive',
new_callable=mock.PropertyMock)
def test_extract_force(self, mock_archive):
"""Test theme unpacking."""
mock_archive.return_value = zipfile.ZipFile(TEST_ZIP_FILE, 'r')
self.assertFalse(self.pod.file_exists('/gulpfile.js'))
self.assertFalse(self.pod.file_exists('/podspec.yaml'))
self.pod.write_file('/podspec.yaml', '')
self.assertTrue(self.pod.file_exists('/podspec.yaml'))
theme = themes.GrowTheme('base')
theme.extract(self.pod, force=True)
self.assertTrue(self.pod.file_exists('/gulpfile.js'))